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

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, 11 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 SCRIPT_URL_ON_INSTALL = 'resources/navigate-on-install-worker.js';
12 var worker; 13 const URL_PREFIX = location.origin + '/serviceworker/';
13 var test; 14 const FULL_SCOPE_URL = URL_PREFIX + SCOPE;
15 const FULL_SCRIPT_URL = URL_PREFIX + SCRIPT_URL;
16 const CROSS_ORIGIN_URL = get_host_info()['HTTP_REMOTE_ORIGIN'] +
17 '/serviceworker/resources/blank.html';
14 18
15 var current_index = 0; 19 navigate_test({
16 var test_list = [ 20 description: 'normal test',
17 { url : 'blank.html' }, 21 dest_url: 'blank.html?navigate',
18 { url : '' }, 22 expected: FULL_SCOPE_URL + '?navigate',
nhiroki 2016/01/25 09:50:31 normalizeURL() defined in http/tests/serviceworker
zino 2016/01/29 05:36:38 Done.
19 { url : 'blank.html', init : 'uncontrolled/blank.html' }, 23 });
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 24
29 var expected = [ 25 navigate_test({
30 location.origin + '/serviceworker/resources/blank.html', 26 description: 'blank url test',
31 location.origin + '/serviceworker/' + script_url, 27 dest_url: '',
32 'TypeError', 28 expected: FULL_SCRIPT_URL
33 null, 29 });
34 'TypeError',
35 'TypeError',
36 'TypeError',
37 'TypeError',
38 'TypeError'
39 ];
40 30
41 var actual = []; 31 navigate_test({
32 description: 'in scope but not controlled test',
33 dest_url: 'blank.html?navigate',
34 expected: 'TypeError',
35 wait_state: 'installing',
36 script_url: 'resources/navigate-on-install-worker.js'
nhiroki 2016/01/25 09:50:31 SCRIPT_URL_ON_INSTALL
zino 2016/01/29 05:36:38 Done.
37 });
42 38
43 async_test(function(t) { 39 navigate_test({
44 test = t; 40 description: 'out scope test',
45 return service_worker_unregister_and_register(test, script_url, scope) 41 src_url: 'out_scope/blank.html',
46 .then(function(registration) { 42 dest_url: 'blank.html?navigate',
47 worker = registration.installing; 43 expected: 'TypeError',
48 return wait_for_state(test, worker, 'activated'); 44 });
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 45
60 function on_message(e, port) { 46 navigate_test({
61 var message = e.data; 47 description : 'cross orgin url test',
nhiroki 2016/01/25 09:50:31 There is a whitespace before ':'.
zino 2016/01/29 05:36:38 Done.
48 dest_url: CROSS_ORIGIN_URL,
49 expected: null
50 });
62 51
63 message == 'ready' || actual.push(message); 52 navigate_test({
64 if (expected.length == actual.length) { 53 description: 'invalid url(http://[eaxmple.com]) test',
65 assert_array_equals(actual, expected); 54 dest_url: 'http://[example].com',
66 service_worker_unregister_and_done(test, scope); 55 expected: 'TypeError'
67 } else { 56 });
68 client_frame && client_frame.remove(); 57
69 var init_url = test_list[current_index].init || scope; 58 navigate_test({
70 with_iframe(init_url).then(function(f) { 59 description: 'invalid url(view-source://example.com) test',
71 client_frame = f; 60 dest_url: 'view-source://example.com',
72 port.postMessage(test_list[current_index++].url); 61 expected: 'TypeError'
73 }); 62 });
74 } 63
64 navigate_test({
65 description: 'invalid url(file:///) test',
66 dest_url: 'file:///',
67 expected: 'TypeError'
68 });
69
70 navigate_test({
71 description: 'invalid url(about:blank) test',
72 dest_url: 'about:blank',
73 expected: 'TypeError'
74 });
75
76 function navigate_test(override_parameters) {
77 // default parameters
78 var parameters = {
79 description : null,
80 src_url : SCOPE,
81 dest_url : null,
82 expected : null,
83 wait_state : 'activated',
84 scope : SCOPE,
85 script_url : SCRIPT_URL
nhiroki 2016/01/25 09:50:31 ditto(whitespaces)
zino 2016/01/29 05:36:38 Done.
86 };
87
88 for (key in override_parameters)
89 parameters[key] = override_parameters[key];
90
91 promise_test(function(test) {
92 var service_worker;
93 var client_frame;
94 return service_worker_unregister_and_register(
95 test, parameters.script_url, parameters.scope)
96 .then(function(registration) {
97 service_worker = registration.installing;
98 return wait_for_state(test, service_worker, parameters.wait_state);
99 })
100 .then(function(state) {
101 return with_iframe(parameters.src_url);
102 })
103 .then(function(frame) {
104 client_frame = frame;
105 return new Promise(function(resolve) {
106 var channel = new MessageChannel();
107 channel.port1.onmessage = test.step_func(resolve);
108 service_worker.postMessage({
109 port: channel.port2,
110 url: parameters.dest_url
111 }, [channel.port2]);
112 });
113 })
114 .then(function(response) {
115 client_frame && client_frame.remove()
116 assert_equals(response.data, parameters.expected);
117 return service_worker_unregister_and_done(test, parameters.scope);
118 })
119 .catch(unreached_rejection(test));
nhiroki 2016/01/25 09:50:31 Can you remove this 'cache' because 'promise_test'
zino 2016/01/29 05:36:38 Done.
120 }, parameters.description);
75 } 121 }
76 122
77 </script> 123 </script>
124 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698