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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/windowclient-navigate.html

Issue 1604893002: ServiceWorker: Rewrite windowclient-navigate.html test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 4 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/windowclient-navigate-worker.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>Service Worker: WindowClient.navigate() tests</title> 2 <title>Service Worker: WindowClient.navigate() tests</title>
3 <script src="../resources/testharness.js"></script> 3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script> 4 <script src="../resources/testharnessreport.js"></script>
5 <script src="../resources/get-host-info.js"></script> 5 <script src="../resources/get-host-info.js"></script>
6 <script src="resources/test-helpers.js"></script> 6 <script src="resources/test-helpers.js"></script>
7 <body>
7 <script> 8 <script>
8 9
9 var scope = 'resources/blank.html?windowclient-navigate'; 10 const SCOPE = 'resources/blank.html';
10 var script_url = 'resources/windowclient-navigate-worker.js'; 11 const SCRIPT_URL = 'resources/windowclient-navigate-worker.js';
11 var client_frame; 12 const CROSS_ORIGIN_URL = get_host_info()['HTTP_REMOTE_ORIGIN'] +
12 var worker; 13 '/serviceworker/resources/blank.html';
13 var test;
14 14
15 var current_index = 0; 15 navigate_test({
16 var test_list = [ 16 description: 'normal test',
17 { url : 'blank.html' }, 17 dest_url: 'blank.html?navigate',
18 { url : '' }, 18 expected: normalizeURL(SCOPE) + '?navigate',
19 { url : 'blank.html', init : 'uncontrolled/blank.html' }, 19 });
20 { url : get_host_info()['HTTP_REMOTE_ORIGIN'] +
21 '/serviceworker/resources/blank.html' },
22 { url : 'http://[example].com' },
23 { url : 'view-source://example.com' },
24 { url : 'file:///' },
25 { url : 'about:blank' },
26 { url : 'about:crash' }
27 ];
28 20
29 var expected = [ 21 navigate_test({
30 location.origin + '/serviceworker/resources/blank.html', 22 description: 'blank url test',
31 location.origin + '/serviceworker/' + script_url, 23 dest_url: '',
32 'TypeError', 24 expected: normalizeURL(SCRIPT_URL)
33 null, 25 });
34 'TypeError',
35 'TypeError',
36 'TypeError',
37 'TypeError',
38 'TypeError'
39 ];
40 26
41 var actual = []; 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 });
42 33
43 async_test(function(t) { 34 navigate_test({
44 test = t; 35 description: 'in scope but not controlled test on active worker',
45 return service_worker_unregister_and_register(test, script_url, scope) 36 dest_url: 'blank.html?navigate',
46 .then(function(registration) { 37 expected: 'TypeError',
47 worker = registration.installing; 38 should_be_reload: false,
48 return wait_for_state(test, worker, 'activated'); 39 });
49 })
50 .then(function() {
51 var channel = new MessageChannel();
52 channel.port1.onmessage = test.step_func(function(e) {
53 on_message(e, channel.port1);
54 });
55 worker.postMessage({ port : channel.port2 }, [channel.port2]);
56 })
57 .catch(unreached_rejection(t));
58 }, 'WindowClient.navigate() test');
59 40
60 function on_message(e, port) { 41 navigate_test({
61 var message = e.data; 42 description: 'out scope test',
43 src_url: 'out_scope/blank.html',
44 dest_url: 'blank.html?navigate',
45 expected: 'TypeError',
46 });
62 47
63 message == 'ready' || actual.push(message); 48 navigate_test({
64 if (expected.length == actual.length) { 49 description: 'cross orgin url test',
65 assert_array_equals(actual, expected); 50 dest_url: CROSS_ORIGIN_URL,
66 service_worker_unregister_and_done(test, scope); 51 expected: null
67 } else { 52 });
68 client_frame && client_frame.remove(); 53
69 var init_url = test_list[current_index].init || scope; 54 navigate_test({
70 with_iframe(init_url).then(function(f) { 55 description: 'invalid url(http://[example.com]) test',
71 client_frame = f; 56 dest_url: 'http://[example].com',
72 port.postMessage(test_list[current_index++].url); 57 expected: 'TypeError'
73 }); 58 });
74 } 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);
75 } 137 }
76 138
77 </script> 139 </script>
140 </body>
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/windowclient-navigate-worker.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698