OLD | NEW |
(Empty) | |
| 1 importScripts("worker-testharness.js"); |
| 2 importScripts("test-helpers.sub.js"); |
| 3 importScripts("get-host-info.sub.js") |
| 4 importScripts("testharness-helpers.js") |
| 5 |
| 6 self.onfetch = function(e) { |
| 7 if (e.request.url.indexOf("client-navigate-frame.html") >= 0) { |
| 8 if (e.clientId === null) { |
| 9 e.respondWith(fetch(e.request)); |
| 10 } else { |
| 11 e.respondWith(Response.error()); |
| 12 } |
| 13 return; |
| 14 } |
| 15 e.respondWith(new Response(e.clientId)); |
| 16 }; |
| 17 |
| 18 function pass(test, url) { |
| 19 return { result: test, |
| 20 url: url }; |
| 21 } |
| 22 |
| 23 function fail(test, reason) { |
| 24 return { result: "FAILED " + test + " " + reason } |
| 25 } |
| 26 |
| 27 self.onmessage = function(e) { |
| 28 var port = e.data.port; |
| 29 var test = e.data.test; |
| 30 var clientId = e.data.clientId; |
| 31 var clientUrl = ""; |
| 32 if (test === "test_client_navigate_success") { |
| 33 promise_test(function(t) { |
| 34 this.add_cleanup(() => port.postMessage(pass(test, clientUrl))); |
| 35 return self.clients.get(clientId) |
| 36 .then(client => client.navigate("client-navigated-frame.html")) |
| 37 .then(client => { |
| 38 clientUrl = client.url; |
| 39 assert_true(client instanceof WindowClient); |
| 40 }) |
| 41 .catch(unreached_rejection(t)); |
| 42 }, "Return value should be instance of WindowClient"); |
| 43 } else if (test === "test_client_navigate_failure") { |
| 44 promise_test(function(t) { |
| 45 return self.clients.get(clientId) |
| 46 .then(client => assert_promise_rejects(client.navigate("http://
example.com"))) |
| 47 .catch(unreached_rejection(t)); |
| 48 }, "Navigating to different origin should reject"); |
| 49 |
| 50 promise_test(function(t) { |
| 51 this.add_cleanup(function() { port.postMessage(pass(test, "")); }); |
| 52 return self.clients.get(clientId) |
| 53 .then(client => promise_rejects(t, new TypeError(), client.navi
gate("about:blank"))) |
| 54 .catch(unreached_rejection(t)); |
| 55 }, "Navigating to about:blank should reject with TypeError") |
| 56 } else if (test === "test_client_navigate_redirect") { |
| 57 var host_info = get_host_info(); |
| 58 var url = new URL(host_info['HTTPS_REMOTE_ORIGIN']).toString() + |
| 59 new URL("client-navigated-frame.html", location).pathname.substrin
g(1); |
| 60 promise_test(function(t) { |
| 61 this.add_cleanup(() => port.postMessage(pass(test, clientUrl))); |
| 62 return self.clients.get(clientId) |
| 63 .then(client => client.navigate("redirect.py?Redirect=" + url)) |
| 64 .then(client => { |
| 65 clientUrl = (client && client.url) || "" |
| 66 assert_true(client === null); |
| 67 }) |
| 68 .catch(unreached_rejection(t)); |
| 69 }, "Redirecting to another origin should resolve with null"); |
| 70 } |
| 71 }; |
OLD | NEW |