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

Unified 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, 11 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..1cef4d3d570b59f9fb0a4a1b756822e0bbc72cac
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/workers/shared-worker-usecounter.html
@@ -0,0 +1,82 @@
+<!DOCTYPE html>
+<title>Shared Worker: UseCounter</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<body>
+</body>
+<script>
+
+var FetchFeature = 675; // From UseCounter.h
+
+function isUseCounted(frame, feature) {
+ 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
+ frame.contentDocument, feature);
+}
+
+function with_iframe(url) {
+ return new Promise(resolve => {
+ var frame = document.createElement('iframe');
+ frame.src = url;
+ frame.onload = () => resolve(frame);
+ document.body.appendChild(frame);
+ });
+}
+
+promise_test(t => {
+ const kFrameUrl = 'resources/shared-worker-usecounter-frame.html';
+
+ var frame1;
+ var frame2;
+ var frame3;
+ var worker;
+
+ return with_iframe(kFrameUrl)
+ .then(frame => {
+ frame1 = frame;
+ assert_false(isUseCounted(frame1, FetchFeature));
+ return with_iframe(kFrameUrl);
+ })
+ .then(frame => {
+ frame2 = frame;
+ assert_false(isUseCounted(frame2, FetchFeature));
+ frame1.contentWindow.connectToWorker();
+ frame2.contentWindow.connectToWorker();
+
+ worker = new SharedWorker('resources/shared-worker-usecounter.js');
+ return new Promise(resolve => worker.port.onmessage = resolve);
+ })
+ .then(e => {
+ assert_equals(e.data, 'connected');
+ var promise =
+ new Promise(resolve => worker.port.onmessage = resolve);
+ worker.port.postMessage('request');
+ return promise;
+ })
+ .then(e => {
+ assert_equals(e.data, 'fetched');
+
+ // API use on the SharedWorkerGlobalScope is recorded in UseCounters on
+ // connected documents.
+ assert_true(isUseCounted(frame1, FetchFeature));
+ assert_true(isUseCounted(frame2, FetchFeature));
+
+ return with_iframe(kFrameUrl);
+ })
+ .then((frame) => {
+ frame3 = frame;
+
+ // A new frame hasn't connected to the worker, so the API use should not
+ // be counted yet.
+ //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
+ assert_true(isUseCounted(frame3, FetchFeature));
+
+ return frame3.contentWindow.connectToWorker();
+ })
+ .then(() => {
+ assert_true(isUseCounted(frame3, FetchFeature));
+ });
+
+}, 'UseCounter on SharedWorkerGlobalScope');
+
+</script>
+</html>

Powered by Google App Engine
This is Rietveld 408576698