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

Unified Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/chromium/use-counter.html

Issue 2684933011: M57: Add UseCounter for ServiceWorkerNavigationPreload. (Closed)
Patch Set: 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/http/tests/serviceworker/navigation-preload/chromium/use-counter.html
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/chromium/use-counter.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/chromium/use-counter.html
new file mode 100644
index 0000000000000000000000000000000000000000..6b52114164cfb6c784ad7ef45dfa21257d875ea2
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/chromium/use-counter.html
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<!-- This test requires internals because it tests Chromium's
+ internal UseCounter. -->
+<title>Navigation Preload use counter</title>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="../../resources/test-helpers.js"></script>
+<script>
+function is_navigation_preload_counted(frame) {
+ // From UseCounter.h
+ const ServiceWorkerNavigationPreload = 1803;
+
+ return frame.contentWindow.internals.isUseCounted(
+ frame.contentDocument, ServiceWorkerNavigationPreload);
+}
+
+promise_test(t => {
+ var script = 'resources/worker.js?no-preload';
+ var scope = 'resources/dummy?no-preload-passthrough';
+ return service_worker_unregister_and_register(t, script, scope)
+ .then(registration => {
+ add_completion_callback(_ => registration.unregister());
+ var worker = registration.installing;
+ return wait_for_state(t, worker, 'activated');
+ })
+ .then(() => {
+ return with_iframe(scope);
+ })
+ .then(frame => {
+ assert_false(is_navigation_preload_counted(frame));
+ });
+ }, 'Navigation Preload is not counted if not enabled.');
+
+promise_test(t => {
+ var script = 'resources/worker.js';
+ var scope = 'resources/dummy?respondWith';
+ return service_worker_unregister_and_register(t, script, scope)
+ .then(registration => {
+ add_completion_callback(_ => registration.unregister());
+ var worker = registration.installing;
+ return wait_for_state(t, worker, 'activated');
+ })
+ .then(() => with_iframe(scope))
+ .then(frame => {
+ assert_true(is_navigation_preload_counted(frame));
+ });
+ }, 'Navigation Preload is use counted.');
+
+promise_test(t => {
+ var script = 'resources/worker.js';
+ var scope = 'resources/dummy?passthrough';
+ return service_worker_unregister_and_register(t, script, scope)
+ .then(registration => {
+ add_completion_callback(_ => registration.unregister());
+ var worker = registration.installing;
+ return wait_for_state(t, worker, 'activated');
+ })
+ .then(() => with_iframe(scope))
+ .then(frame => {
+ assert_true(is_navigation_preload_counted(frame));
+ });
+ }, 'Navigation Preload is use counted even if preloadResponse is not used.');
+</script>

Powered by Google App Engine
This is Rietveld 408576698