blob: 302f702c65f1a8781b97598983200fd816d42ad2 [file] [log] [blame]
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(t => {
assert_true("userAgentData" in navigator);
assert_true("NavigatorUAData" in window);
assert_equals(typeof self.NavigatorUAData, "function")
}, "navigator.userAgentData is exposed.");
promise_test(async t => {
let didMicrotaskRun = false;
const uaData = navigator.userAgentData;
for (brandVersionPair of uaData.brands) {
assert_equals(typeof brandVersionPair.brand, "string", "brand should be a string");
assert_equals(typeof brandVersionPair.version, "string", "version should be a string");
}
assert_equals(typeof uaData.mobile, "boolean", "mobile should be a boolean");
const highEntropyData = await uaData.getHighEntropyValues(["platform", "platformVersion", "architecture", "model", "uaFullVersion"]);
assert_equals(typeof highEntropyData["platform"], "string", "Platform brand should be a string");
assert_equals(typeof highEntropyData["platformVersion"], "string", "Platform version should be a string");
assert_equals(typeof highEntropyData["architecture"], "string", "Architecture should be a string");
assert_equals(typeof highEntropyData["model"], "string", "Model should be a string");
assert_equals(typeof highEntropyData["uaFullVersion"], "string", "UAFullVersion should be a string");
const highEntropyData2 = await uaData.getHighEntropyValues([]);
assert_false("platform" in highEntropyData2, "Platform brand should be an empty string");
assert_false("platformVersion" in highEntropyData2, "Platform version should be an empty string");
assert_false("architecture" in highEntropyData2, "Architecture should be an empty string");
assert_false("model" in highEntropyData2, "Model should be an empty string");
assert_false("uaFullVersion" in highEntropyData2, "UAFullVersion should be an empty string");
let finalPromise = uaData.getHighEntropyValues([]).then(() => {
assert_true(didMicrotaskRun, "getHighEntropyValues queued on a task");
});
await Promise.resolve().then(function() {
didMicrotaskRun = true;
});
return finalPromise;
}, "navigator.userAgentData returns a UserAgentMetadata object.");
</script>