Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/navigation-preload-origin-trial-methods.html |
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/navigation-preload-origin-trial-methods.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/navigation-preload-origin-trial-methods.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fc14d0585a342a5a0d438e7354209b8d334a061d |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium/navigation-preload-origin-trial-methods.html |
@@ -0,0 +1,79 @@ |
+<!DOCTYPE html> |
+<meta charset="utf-8"> |
+<!-- Generate these token with the commands: |
+generate_token.py http://127.0.0.1:8000 ServiceWorkerNavigationPreload -expire-timestamp=2000000000 |
+--> |
+<meta http-equiv="origin-trial" content="AsAA4dg2Rm+GSgnpyxxnpVk1Bk8CcE+qVBTDpPbIFNscyNRJOdqw1l0vkC4dtsGm1tmP4ZDAKwycQDzsc9xr7gMAAABmeyJvcmlnaW4iOiAiaHR0cDovLzEyNy4wLjAuMTo4MDAwIiwgImZlYXR1cmUiOiAiU2VydmljZVdvcmtlck5hdmlnYXRpb25QcmVsb2FkIiwgImV4cGlyeSI6IDIwMDAwMDAwMDB9" /> |
+<title>Navigation Preload origin trial</title> |
+<script src="../../resources/testharness.js"></script> |
+<script src="../../resources/testharnessreport.js"></script> |
+<script src="../resources/test-helpers.js"></script> |
+<script src="./resources/get_interface_names.js"></script> |
+<script> |
+function check_methods(t, script, scope) { |
+ var registration; |
+ var worker; |
+ var message; |
+ var log = ''; |
+ return service_worker_unregister_and_register(t, script, scope) |
+ .then(reg => { |
+ registration = reg; |
+ worker = registration.installing; |
+ return wait_for_state(t, worker, 'activated'); |
+ }) |
+ .then(_ => registration.navigationPreload.disable()) |
+ .then( |
+ result => { log += 'disable() resolved with: ' + result + '\n';}, |
+ error => { log += 'disable() rejected with: ' + error + '\n';}) |
+ .then(_ => registration.navigationPreload.enable()) |
+ .then( |
+ result => { log += 'enable() resolved with: ' + result + '\n';}, |
+ error => { log += 'enable() rejected with: ' + error + '\n';}) |
+ .then(_ => registration.navigationPreload.getState()) |
+ .then( |
+ result => { |
+ log += 'getState() resolved with: ' + JSON.stringify(result) + '\n'; |
+ }, |
+ error => { log += 'getState() rejected with: ' + error + '\n';}) |
+ .then(_ => registration.navigationPreload.setHeaderValue('hello')) |
+ .then( |
+ result => { log += 'setHeaderValue() resolved with: ' + result + '\n';}, |
+ error => { log += 'setHeaderValue() rejected with: ' + error + '\n';}) |
+ .then(_ => with_iframe(scope)) |
+ .then(function() { |
+ var channel = new MessageChannel(); |
+ var saw_message = new Promise(function(resolve) { |
+ channel.port1.onmessage = function(e) { resolve(e.data); } |
+ }); |
+ worker.postMessage({port: channel.port2}, [channel.port2]); |
+ return saw_message; |
falken
2017/01/13 03:43:41
rm messagechannel
horo
2017/01/13 08:41:33
Done.
|
+ }) |
+ .then(function(message) { |
+ log += 'log from SW\n' + message; |
+ return service_worker_unregister(t, scope); |
falken
2017/01/13 03:43:42
nit: could just call registration.unregister() but
horo
2017/01/13 08:41:33
Done.
|
+ }) |
+ .then(function() { |
+ return log; |
+ }); |
+} |
+ |
+promise_test(t => { |
+ var script = 'resources/navigation-preload-origin-trial-methods-worker.php'; |
+ var scope = |
+ 'resources/navigation-preload-origin-trial-methods-scope.php?default'; |
+ return check_methods(t, script, scope).then(log => { |
+ console.log('--normal SW--\n' + log); |
+ }); |
+ }, 'Calling Navigation preload related methods for normal SW.'); |
+ |
+promise_test(t => { |
+ var script = |
+ 'resources/navigation-preload-origin-trial-methods-worker.php?' + |
+ 'origintrial=true'; |
+ var scope = |
+ 'resources/navigation-preload-origin-trial-methods-scope.php?enabled'; |
+ return check_methods(t, script, scope).then(log => { |
+ console.log('--Origin-Trial enabled SW--\n' + log); |
+ }); |
+ }, 'Calling Navigation preload related methods for Origin-Trial enabled SW.'); |
+</script> |