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

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

Issue 2680423006: UseCounter: Introduce UseCounter::Observer for layout tests (Closed)
Patch Set: instance method 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 unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>Shared Worker: UseCounter</title> 2 <title>Shared Worker: UseCounter</title>
3 <script src="../../resources/testharness.js"></script> 3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script> 4 <script src="../../resources/testharnessreport.js"></script>
5 <body> 5 <body>
6 </body> 6 </body>
7 <script> 7 <script>
8 8
9 const kFeature = 675; // From UseCounter.h 9 const kFeature = 675; // From UseCounter.h
10 const kDeprecatedFeature = 538; // From Deprecation.h 10 const kDeprecatedFeature = 538; // From Deprecation.h
11 11
12 function isUseCounted(win, feature) { 12 function isUseCounted(win, feature) {
13 return win.internals.isUseCounted(win.document, feature); 13 return win.internals.isUseCounted(win.document, feature);
14 } 14 }
15 15
16 function observeUseCounter(win, feature) {
17 return win.internals.observeUseCounter(win.document, feature);
18 }
19
16 function openWindow(url) { 20 function openWindow(url) {
17 return new Promise(resolve => { 21 return new Promise(resolve => {
18 let win = window.open(url, '_blank'); 22 let win = window.open(url, '_blank');
19 add_completion_callback(() => win.close()); 23 add_completion_callback(() => win.close());
20 window.onmessage = e => { 24 window.onmessage = e => {
21 assert_equals(e.data, 'LOADED'); 25 assert_equals(e.data, 'LOADED');
22 resolve(win); 26 resolve(win);
23 }; 27 };
24 }); 28 });
25 } 29 }
(...skipping 21 matching lines...) Expand all
47 worker = new SharedWorker('resources/shared-worker-usecounter.js'); 51 worker = new SharedWorker('resources/shared-worker-usecounter.js');
48 return new Promise(resolve => worker.port.onmessage = resolve); 52 return new Promise(resolve => worker.port.onmessage = resolve);
49 }) 53 })
50 .then(e => { 54 .then(e => {
51 assert_equals(e.data, 'CONNECTED'); 55 assert_equals(e.data, 'CONNECTED');
52 56
53 assert_false(isUseCounted(win1, kFeature)); 57 assert_false(isUseCounted(win1, kFeature));
54 assert_false(isUseCounted(win2, kFeature)); 58 assert_false(isUseCounted(win2, kFeature));
55 59
56 // Request to count a feature. 60 // Request to count a feature.
57 let promise =
58 new Promise(resolve => worker.port.onmessage = resolve);
59 worker.port.postMessage({type: 'COUNT_FEATURE', feature: kFeature}); 61 worker.port.postMessage({type: 'COUNT_FEATURE', feature: kFeature});
60 return promise; 62 return Promise.all([
63 observeUseCounter(win1, kFeature),
64 observeUseCounter(win2, kFeature)
65 ]);
61 }) 66 })
62 .then(e => { 67 .then(() => {
63 assert_equals(e.data, 'COUNTED');
64
65 // API use on the SharedWorkerGlobalScope is recorded in UseCounters on 68 // API use on the SharedWorkerGlobalScope is recorded in UseCounters on
66 // all connected documents. 69 // all connected documents.
67 assert_true(isUseCounted(win1, kFeature)); 70 assert_true(isUseCounted(win1, kFeature));
68 assert_true(isUseCounted(win2, kFeature)); 71 assert_true(isUseCounted(win2, kFeature));
69 72
70 assert_false(isUseCounted(win1, kDeprecatedFeature)); 73 assert_false(isUseCounted(win1, kDeprecatedFeature));
71 assert_false(isUseCounted(win2, kDeprecatedFeature)); 74 assert_false(isUseCounted(win2, kDeprecatedFeature));
72 75
73 // Request to count a deprecated feature. 76 // Request to count a deprecated feature.
74 let promise =
75 new Promise(resolve => worker.port.onmessage = resolve);
76 worker.port.postMessage( 77 worker.port.postMessage(
77 {type: 'COUNT_DEPRECATION', feature: kDeprecatedFeature}); 78 {type: 'COUNT_DEPRECATION', feature: kDeprecatedFeature});
78 return promise; 79 return Promise.all([
80 observeUseCounter(win1, kDeprecatedFeature),
81 observeUseCounter(win2, kDeprecatedFeature)
82 ]);
79 }) 83 })
80 .then(e => { 84 .then(() => {
81 assert_equals(e.data, 'COUNTED');
82
83 // Deprecated API use on the SharedWorkerGlobalScope is recorded in 85 // Deprecated API use on the SharedWorkerGlobalScope is recorded in
84 // UseCounters on all connected documents. 86 // UseCounters on all connected documents.
85 assert_true(isUseCounted(win1, kDeprecatedFeature)); 87 assert_true(isUseCounted(win1, kDeprecatedFeature));
86 assert_true(isUseCounted(win2, kDeprecatedFeature)); 88 assert_true(isUseCounted(win2, kDeprecatedFeature));
87 89
88 return openWindow(kWindowUrl); 90 return openWindow(kWindowUrl);
89 }) 91 })
90 .then(win => { 92 .then(win => {
91 win3 = win; 93 win3 = win;
92 // A new document hasn't connected to the worker, so the API use should 94 // A new document hasn't connected to the worker, so the API use should
93 // not be counted yet. 95 // not be counted yet.
94 assert_false(isUseCounted(win3, kFeature)); 96 assert_false(isUseCounted(win3, kFeature));
95 assert_false(isUseCounted(win3, kDeprecatedFeature)); 97 assert_false(isUseCounted(win3, kDeprecatedFeature));
96 return win3.connectToWorker(); 98 win3.connectToWorker();
99 return Promise.all([
100 observeUseCounter(win3, kFeature),
101 observeUseCounter(win3, kDeprecatedFeature)
102 ]);
97 }) 103 })
98 .then(() => { 104 .then(() => {
99 // A counter of the newly connected document should be synced with 105 // A counter of the newly connected document should be synced with
100 // others. 106 // others.
101 assert_true(isUseCounted(win3, kFeature)); 107 assert_true(isUseCounted(win3, kFeature));
102 assert_true(isUseCounted(win3, kDeprecatedFeature)); 108 assert_true(isUseCounted(win3, kDeprecatedFeature));
103 }); 109 });
104 }, 'UseCounter on SharedWorkerGlobalScope'); 110 }, 'UseCounter on SharedWorkerGlobalScope');
105 111
106 </script> 112 </script>
107 </html> 113 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698