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

Unified Diff: LayoutTests/http/tests/serviceworker/resources/navigation-redirect-other-origin.html

Issue 1286153003: Add LayoutTests for the behavior of navigation redirect with Service Worker. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: incorporated falken's comment Created 5 years, 4 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: LayoutTests/http/tests/serviceworker/resources/navigation-redirect-other-origin.html
diff --git a/LayoutTests/http/tests/serviceworker/resources/navigation-redirect-other-origin.html b/LayoutTests/http/tests/serviceworker/resources/navigation-redirect-other-origin.html
new file mode 100644
index 0000000000000000000000000000000000000000..ff10b9a122eea6c21db3a03544c633c0e7660f3a
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/resources/navigation-redirect-other-origin.html
@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<script src="../../resources/get-host-info.js"></script>
+<script src="test-helpers.js?pipe=sub"></script>
+<script>
+var host_info = get_host_info();
+var SCOPE = 'navigation-redirect-scope1.php';
+var SCRIPT = 'navigation-redirect-worker.js';
+
+var registration;
+var worker;
+var wait_for_worker_promise = navigator.serviceWorker.getRegistration(SCOPE)
+ .then(function(reg) {
+ if (reg)
+ return reg.unregister();
+ })
+ .then(function() {
+ return navigator.serviceWorker.register(SCRIPT, {scope: SCOPE});
+ })
+ .then(function(reg) {
+ registration = reg;
+ worker = reg.installing;
+ return new Promise(function(resolve) {
+ worker.addEventListener('statechange', function() {
+ if (worker.state == 'activated')
+ resolve();
+ });
+ });
+ });
+
+function send_result(message_id, result) {
+ window.parent.postMessage(
+ {id: message_id, result: result},
+ host_info['HTTP_ORIGIN']);
+}
+
+function get_intercepted_urls(worker) {
+ return new Promise(function(resolve) {
+ var channel = new MessageChannel();
+ channel.port1.onmessage = function(msg) { resolve(msg.data.urls); };
+ worker.postMessage({port: channel.port2}, [channel.port2]);
+ });
+}
+
+window.addEventListener('message', on_message, false);
+
+function on_message(e) {
+ if (e.origin != host_info['HTTP_ORIGIN']) {
+ console.error('invalid origin: ' + e.origin);
+ return;
+ }
+ if (e.data.message == 'wait_for_worker') {
+ wait_for_worker_promise.then(function() { send_result(e.data.id, 'ok'); });
+ } else if (e.data.message == 'get_intercepted_urls') {
+ get_intercepted_urls(worker)
+ .then(function(urls) {
+ send_result(e.data.id, urls);
+ });
+ } else if (e.data.message == 'unregister') {
+ registration.unregister()
+ .then(function() {
+ send_result(e.data.id, 'ok');
+ });
+ }
+}
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698