Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: third_party/WebKit/LayoutTests/fast/workers/shared-worker-usecounter.html

Issue 2586863002: Worker: Enable UseCounter for SharedWorkerGlobalScope (Closed)
Patch Set: simplify Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/fast/workers/shared-worker-usecounter.html
diff --git a/third_party/WebKit/LayoutTests/fast/workers/shared-worker-usecounter.html b/third_party/WebKit/LayoutTests/fast/workers/shared-worker-usecounter.html
new file mode 100644
index 0000000000000000000000000000000000000000..ef5fecba9666e235672aec7354df4955e58b19c9
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/workers/shared-worker-usecounter.html
@@ -0,0 +1,107 @@
+<!DOCTYPE html>
+<title>Shared Worker: UseCounter</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+</body>
+<script>
+
+const kFeature = 675; // From UseCounter.h
+const kDeprecatedFeature = 538; // From Deprecation.h
+
+function isUseCounted(win, feature) {
+ return win.internals.isUseCounted(win.document, feature);
+}
+
+function openWindow(url) {
+ return new Promise(resolve => {
+ let win = window.open(url, '_blank');
+ add_completion_callback(() => win.close());
+ window.onmessage = e => {
+ assert_equals(e.data, 'LOADED');
+ resolve(win);
+ };
+ });
+}
+
+promise_test(t => {
+ const kWindowUrl = 'resources/shared-worker-usecounter-window.html';
+
+ let win1;
+ let win2;
+ let win3;
+ let worker;
+
+ return openWindow(kWindowUrl)
+ .then(win => {
+ win1 = win;
+ win1.connectToWorker();
+ return openWindow(kWindowUrl);
+ })
+ .then(win => {
+ win2 = win;
+ win2.connectToWorker();
+
+ // Connect to a shared worker from the main document to get a
+ // communication channel to the worker.
+ worker = new SharedWorker('resources/shared-worker-usecounter.js');
+ return new Promise(resolve => worker.port.onmessage = resolve);
+ })
+ .then(e => {
+ assert_equals(e.data, 'CONNECTED');
+
+ assert_false(isUseCounted(win1, kFeature));
+ assert_false(isUseCounted(win2, kFeature));
+
+ // Request to count a feature.
+ let promise =
+ new Promise(resolve => worker.port.onmessage = resolve);
+ worker.port.postMessage({type: 'COUNT_FEATURE', feature: kFeature});
+ return promise;
+ })
+ .then(e => {
+ assert_equals(e.data, 'COUNTED');
+
+ // API use on the SharedWorkerGlobalScope is recorded in UseCounters on
+ // all connected documents.
+ assert_true(isUseCounted(win1, kFeature));
+ assert_true(isUseCounted(win2, kFeature));
+
+ assert_false(isUseCounted(win1, kDeprecatedFeature));
+ assert_false(isUseCounted(win2, kDeprecatedFeature));
+
+ // Request to count a deprecated feature.
+ let promise =
+ new Promise(resolve => worker.port.onmessage = resolve);
+ worker.port.postMessage(
+ {type: 'COUNT_DEPRECATION', feature: kDeprecatedFeature});
+ return promise;
+ })
+ .then(e => {
+ assert_equals(e.data, 'COUNTED');
+
+ // Deprecated API use on the SharedWorkerGlobalScope is recorded in
+ // UseCounters on all connected documents.
+ assert_true(isUseCounted(win1, kDeprecatedFeature));
+ assert_true(isUseCounted(win2, kDeprecatedFeature));
+
+ return openWindow(kWindowUrl);
+ })
+ .then(win => {
+ win3 = win;
+ // A new document hasn't connected to the worker, so the API use should
+ // not be counted yet.
+ assert_false(isUseCounted(win3, kFeature));
+ assert_false(isUseCounted(win3, kDeprecatedFeature));
+ return win3.connectToWorker();
+ })
+ .then(() => {
+ // A counter of the newly connected document should be synced with
+ // others.
+ assert_true(isUseCounted(win3, kFeature));
+ assert_true(isUseCounted(win3, kDeprecatedFeature));
+ });
+}, 'UseCounter on SharedWorkerGlobalScope');
+
+</script>
+</html>

Powered by Google App Engine
This is Rietveld 408576698