| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <title>Service Worker: WindowClient.navigate() tests</title> | |
| 3 <script src="../resources/testharness.js"></script> | |
| 4 <script src="../resources/testharnessreport.js"></script> | |
| 5 <script src="../resources/get-host-info.js"></script> | |
| 6 <script src="resources/test-helpers.js"></script> | |
| 7 <body> | |
| 8 <script> | |
| 9 | |
| 10 const SCOPE = 'resources/blank.html'; | |
| 11 const SCRIPT_URL = 'resources/windowclient-navigate-worker.js'; | |
| 12 const CROSS_ORIGIN_URL = get_host_info()['HTTP_REMOTE_ORIGIN'] + | |
| 13 '/serviceworker/resources/blank.html'; | |
| 14 | |
| 15 navigate_test({ | |
| 16 description: 'normal test', | |
| 17 dest_url: 'blank.html?navigate', | |
| 18 expected: normalizeURL(SCOPE) + '?navigate', | |
| 19 }); | |
| 20 | |
| 21 navigate_test({ | |
| 22 description: 'blank url test', | |
| 23 dest_url: '', | |
| 24 expected: normalizeURL(SCRIPT_URL) | |
| 25 }); | |
| 26 | |
| 27 navigate_test({ | |
| 28 description: 'in scope but not controlled test on installing worker', | |
| 29 dest_url: 'blank.html?navigate', | |
| 30 expected: 'TypeError', | |
| 31 wait_state: 'installing', | |
| 32 }); | |
| 33 | |
| 34 navigate_test({ | |
| 35 description: 'in scope but not controlled test on active worker', | |
| 36 dest_url: 'blank.html?navigate', | |
| 37 expected: 'TypeError', | |
| 38 should_be_reload: false, | |
| 39 }); | |
| 40 | |
| 41 navigate_test({ | |
| 42 description: 'out scope test', | |
| 43 src_url: 'out_scope/blank.html', | |
| 44 dest_url: 'blank.html?navigate', | |
| 45 expected: 'TypeError', | |
| 46 }); | |
| 47 | |
| 48 navigate_test({ | |
| 49 description: 'cross orgin url test', | |
| 50 dest_url: CROSS_ORIGIN_URL, | |
| 51 expected: null | |
| 52 }); | |
| 53 | |
| 54 navigate_test({ | |
| 55 description: 'invalid url(http://[example.com]) test', | |
| 56 dest_url: 'http://[example].com', | |
| 57 expected: 'TypeError' | |
| 58 }); | |
| 59 | |
| 60 navigate_test({ | |
| 61 description: 'invalid url(view-source://example.com) test', | |
| 62 dest_url: 'view-source://example.com', | |
| 63 expected: 'TypeError' | |
| 64 }); | |
| 65 | |
| 66 navigate_test({ | |
| 67 description: 'invalid url(file:///) test', | |
| 68 dest_url: 'file:///', | |
| 69 expected: 'TypeError' | |
| 70 }); | |
| 71 | |
| 72 navigate_test({ | |
| 73 description: 'invalid url(about:blank) test', | |
| 74 dest_url: 'about:blank', | |
| 75 expected: 'TypeError' | |
| 76 }); | |
| 77 | |
| 78 function navigate_test(override_parameters) { | |
| 79 // default parameters | |
| 80 var parameters = { | |
| 81 description: null, | |
| 82 src_url: SCOPE, | |
| 83 dest_url: null, | |
| 84 expected: null, | |
| 85 wait_state: 'activated', | |
| 86 scope: SCOPE, | |
| 87 should_be_reload: true | |
| 88 }; | |
| 89 | |
| 90 for (key in override_parameters) | |
| 91 parameters[key] = override_parameters[key]; | |
| 92 | |
| 93 promise_test(function(test) { | |
| 94 var service_worker; | |
| 95 var client_frame; | |
| 96 var script_url = SCRIPT_URL; | |
| 97 | |
| 98 // For in-scope-but-not-controlled test on installing worker, | |
| 99 // if the wait_state is "installing", then append the query to script_url. | |
| 100 if (parameters.wait_state == 'installing') | |
| 101 script_url += '?' + parameters.wait_state; | |
| 102 | |
| 103 return with_iframe(parameters.src_url) | |
| 104 .then(function(frame) { | |
| 105 client_frame = frame; | |
| 106 return service_worker_unregister_and_register( | |
| 107 test, script_url, parameters.scope); | |
| 108 }) | |
| 109 .then(function(registration) { | |
| 110 service_worker = registration.installing; | |
| 111 return wait_for_state(test, service_worker, parameters.wait_state); | |
| 112 }) | |
| 113 .then(function(state) { | |
| 114 if (parameters.should_be_reload) { | |
| 115 client_frame.remove(); | |
| 116 return with_iframe(parameters.src_url); | |
| 117 } | |
| 118 return client_frame; | |
| 119 }) | |
| 120 .then(function(frame) { | |
| 121 client_frame = frame; | |
| 122 return new Promise(function(resolve) { | |
| 123 var channel = new MessageChannel(); | |
| 124 channel.port1.onmessage = test.step_func(resolve); | |
| 125 service_worker.postMessage({ | |
| 126 port: channel.port2, | |
| 127 url: parameters.dest_url | |
| 128 }, [channel.port2]); | |
| 129 }); | |
| 130 }) | |
| 131 .then(function(response) { | |
| 132 client_frame && client_frame.remove() | |
| 133 assert_equals(response.data, parameters.expected); | |
| 134 return service_worker_unregister_and_done(test, parameters.scope); | |
| 135 }) | |
| 136 }, parameters.description); | |
| 137 } | |
| 138 | |
| 139 </script> | |
| 140 </body> | |
| OLD | NEW |