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

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

Issue 2586863002: Worker: Enable UseCounter for SharedWorkerGlobalScope (Closed)
Patch Set: address review comments 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
(Empty)
1 <!DOCTYPE html>
2 <title>Shared Worker: UseCounter</title>
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <body>
6 </body>
7 <script>
8
9 var FetchFeature = 675; // From UseCounter.h
10
11 function isUseCounted(frame, feature) {
12 return frame.contentWindow.internals.isUseCounted(
Rick Byers 2017/01/26 03:02:37 Note that this test is pretty limited - doesn't ve
nhiroki 2017/01/27 16:58:16 Thank you for the guide! Using the command line f
13 frame.contentDocument, feature);
14 }
15
16 function with_iframe(url) {
17 return new Promise(resolve => {
18 var frame = document.createElement('iframe');
19 frame.src = url;
20 frame.onload = () => resolve(frame);
21 document.body.appendChild(frame);
22 });
23 }
24
25 promise_test(t => {
26 const kFrameUrl = 'resources/shared-worker-usecounter-frame.html';
27
28 var frame1;
29 var frame2;
30 var frame3;
31 var worker;
32
33 return with_iframe(kFrameUrl)
34 .then(frame => {
35 frame1 = frame;
36 assert_false(isUseCounted(frame1, FetchFeature));
37 return with_iframe(kFrameUrl);
38 })
39 .then(frame => {
40 frame2 = frame;
41 assert_false(isUseCounted(frame2, FetchFeature));
42 frame1.contentWindow.connectToWorker();
43 frame2.contentWindow.connectToWorker();
44
45 worker = new SharedWorker('resources/shared-worker-usecounter.js');
46 return new Promise(resolve => worker.port.onmessage = resolve);
47 })
48 .then(e => {
49 assert_equals(e.data, 'connected');
50 var promise =
51 new Promise(resolve => worker.port.onmessage = resolve);
52 worker.port.postMessage('request');
53 return promise;
54 })
55 .then(e => {
56 assert_equals(e.data, 'fetched');
57
58 // API use on the SharedWorkerGlobalScope is recorded in UseCounters on
59 // connected documents.
60 assert_true(isUseCounted(frame1, FetchFeature));
61 assert_true(isUseCounted(frame2, FetchFeature));
62
63 return with_iframe(kFrameUrl);
64 })
65 .then((frame) => {
66 frame3 = frame;
67
68 // A new frame hasn't connected to the worker, so the API use should not
69 // be counted yet.
70 //assert_false(isUseCounted(frame3, FetchFeature));
Rick Byers 2017/01/26 03:02:37 Instead of using frames (which share a UseCounter)
nhiroki 2017/01/27 16:58:16 Good idea. Done. It looks like window.open() work
71 assert_true(isUseCounted(frame3, FetchFeature));
72
73 return frame3.contentWindow.connectToWorker();
74 })
75 .then(() => {
76 assert_true(isUseCounted(frame3, FetchFeature));
77 });
78
79 }, 'UseCounter on SharedWorkerGlobalScope');
80
81 </script>
82 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698