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

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: 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
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',
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',
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 wait_state: 'activating',
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://[eaxmple.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 };
88
89 for (key in override_parameters)
90 parameters[key] = override_parameters[key];
91
92 promise_test(function(test) {
93 var service_worker;
94 var client_frame;
95 var script_url = SCRIPT_URL;
96 if (parameters.wait_state != 'activated')
97 script_url += '?' + parameters.wait_state;
98
99 return service_worker_unregister_and_register(
100 test, script_url, parameters.scope)
101 .then(function(registration) {
102 service_worker = registration.installing;
103 return wait_for_state(test, service_worker, parameters.wait_state);
104 })
105 .then(function(state) {
106 return with_iframe(parameters.src_url);
107 })
108 .then(function(frame) {
109 client_frame = frame;
110 return new Promise(function(resolve) {
111 var channel = new MessageChannel();
112 channel.port1.onmessage = test.step_func(resolve);
113 service_worker.postMessage({
114 port: channel.port2,
115 url: parameters.dest_url
116 }, [channel.port2]);
117 });
118 })
119 .then(function(response) {
120 client_frame && client_frame.remove()
121 assert_equals(response.data, parameters.expected);
122 return service_worker_unregister_and_done(test, parameters.scope);
123 })
124 }, parameters.description);
75 } 125 }
76 126
77 </script> 127 </script>
128 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698