Skip to content

Commit

Permalink
[UA-CH] Add userAgentData worker support
Browse files Browse the repository at this point in the history
This implements PR #80 [1] and exposes userAgentData in workers.

[1] WICG/ua-client-hints#80

Change-Id: I1de6067ab6c00855d7bf820e9646eb4e5a8c5fdb
  • Loading branch information
Yoav Weiss authored and chromium-wpt-export-bot committed Mar 13, 2020
1 parent 4c698c2 commit 53467ca
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webrtc/dictionary-helper.js"></script>
<script>
test(t => {
assert_true("userAgentData" in navigator);
Expand Down
18 changes: 18 additions & 0 deletions workers/WorkerNavigator_userAgentData.http.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title> WorkerNavigator.userAgentData </title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>

promise_test(async () => {
const e = await new Promise((resolve, reject) => {
const worker = new Worker("./support/WorkerNavigator.js");
worker.onmessage = resolve;
});

assert_equals(e.data.uaList, undefined);
assert_equals(e.data.mobile, undefined);
assert_equals(e.data.getHighEntropyValues, undefined);
}, "Test userAgentData in workers");
</script>
29 changes: 29 additions & 0 deletions workers/WorkerNavigator_userAgentData.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<title> WorkerNavigator.userAgentData </title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>

promise_test(async () => {
const e = await new Promise((resolve, reject) => {
const worker = new Worker("./support/WorkerNavigator.js");
worker.onmessage = resolve;
});

assert_equals(e.data.uaList.length, navigator.userAgentData.uaList.length);
for (let i = 0; i < e.data.uaList.length; ++i) {
const workerUA = e.data.uaList[i];
const windowUA = navigator.userAgentData.uaList[i];
assert_equals(workerUA.brand, windowUA.brand);
assert_equals(workerUA.version, windowUA.version);
}
assert_equals(e.data.mobile, navigator.userAgentData.mobile);
const highEntropyValues = await navigator.userAgentData.getHighEntropyValues(["platform", "platformVersion", "architecture", "model", "uaFullVersion"]);
assert_equals(e.data.model, highEntropyValues.model);
assert_equals(e.data.platform, highEntropyValues.platform);
assert_equals(e.data.platformVersion, highEntropyValues.platformVersion);
assert_equals(e.data.architecture, highEntropyValues.architecture);
assert_equals(e.data.uaFullVersion, highEntropyValues.uaFullVersion);
}, "Test userAgentData in workers");
</script>
26 changes: 19 additions & 7 deletions workers/support/WorkerNavigator.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
var obj = new Object();
obj.appName = navigator.appName;
obj.appVersion = navigator.appVersion;
obj.platform = navigator.platform;
obj.userAgent = navigator.userAgent;
obj.onLine = navigator.onLine;
(async () => {
var obj = new Object();
obj.appName = navigator.appName;
obj.appVersion = navigator.appVersion;
obj.platform = navigator.platform;
obj.userAgent = navigator.userAgent;
obj.onLine = navigator.onLine;
if (navigator.userAgentData) {
obj.uaList = navigator.userAgentData.uaList;
obj.mobile = navigator.userAgentData.mobile;
const highEntropyValues = await navigator.userAgentData.getHighEntropyValues(["platform", "platformVersion", "architecture", "model", "uaFullVersion"]);

postMessage(obj);
obj.platform = highEntropyValues.platform;
obj.platformVersion = highEntropyValues.platformVersion;
obj.architecture = highEntropyValues.architecture;
obj.model = highEntropyValues.model;
obj.uaFullVersion = highEntropyValues.uaFullVersion;
}
postMessage(obj);
})();

0 comments on commit 53467ca

Please sign in to comment.