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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/client-navigate.https.html

Issue 2415873002: Import w3c tests for the service workers (Closed)
Patch Set: Rebase Created 4 years, 2 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
(Empty)
1 <!doctype html>
2 <meta charset=utf-8>
3 <title>Service Worker: WindowClient.navigate</title>
4 <script src=/resources/testharness.js></script>
5 <script src=/resources/testharnessreport.js></script>
6 <script src="resources/get-host-info.sub.js"></script>
7 <script src="resources/test-helpers.sub.js"></script>
8 <script>
9 function wait_for_message(msg) {
10 return new Promise(function(resolve, reject) {
11 var get_message_data = function get_message_data(e) {
12 window.removeEventListener("message", get_message_data);
13 resolve(e.data);
14 }
15 window.addEventListener("message", get_message_data, false);
16 });
17 }
18
19 function run_test(controller, clientId, test) {
20 return new Promise(function(resolve, reject) {
21 var channel = new MessageChannel();
22 channel.port1.onmessage = function(e) {
23 resolve(e.data);
24 };
25 var message = {
26 port: channel.port2,
27 test: test,
28 clientId: clientId,
29 };
30 controller.postMessage(
31 message, [channel.port2]);
32 });
33 }
34
35 promise_test(function(t) {
36 var worker = "resources/client-navigate-worker.js";
37 var scope = "resources/client-navigate-frame.html";
38 var controller, frame, clientId;
39
40 return service_worker_unregister_and_register(t, worker, scope)
41 .then(reg => wait_for_state(t, reg.installing, "activated"))
42 .then(___ => with_iframe(scope))
43 .then(f => {
44 frame = f;
45 controller = frame.contentWindow.navigator.serviceWorker.controller;
46 fetch_tests_from_worker(controller);
47 return wait_for_message()
48 })
49 .then(({id}) => clientId = id)
50 .then(___ => run_test(controller, clientId, "test_client_navigate_success" ))
51 .then(({result, url}) => {
52 assert_equals(result, "test_client_navigate_success");
53 assert_equals(
54 url, new URL("resources/client-navigated-frame.html",
55 location).toString());
56 assert_equals(
57 frame.contentWindow.location.href,
58 new URL("resources/client-navigated-frame.html",
59 location).toString());
60 })
61 .catch(unreached_rejection(t))
62 .then(___ => service_worker_unregister(t, scope));
63 }, "Frame location should update on successful navigation");
64
65 promise_test(function(t) {
66 var worker = "resources/client-navigate-worker.js";
67 var scope = "resources/client-navigate-frame.html";
68 var controller, frame, clientId;
69
70 return service_worker_unregister_and_register(t, worker, scope)
71 .then(reg => wait_for_state(t, reg.installing, "activated"))
72 .then(___ => with_iframe(scope))
73 .then(f => {
74 frame = f;
75 controller = frame.contentWindow.navigator.serviceWorker.controller;
76 fetch_tests_from_worker(controller);
77 return wait_for_message()
78 })
79 .then(({id}) => clientId = id)
80 .then(___ => run_test(controller, clientId, "test_client_navigate_redirect "))
81 .then(({result, url}) => {
82 assert_equals(result, "test_client_navigate_redirect");
83 assert_equals(url, "");
84 assert_throws(null, function() { return frame.contentWindow.location.hre f });
85 })
86 .catch(unreached_rejection(t))
87 .then(___ => service_worker_unregister(t, scope));
88 }, "Frame location should not be accessible after redirect");
89
90 promise_test(function(t) {
91 var worker = "resources/client-navigate-worker.js";
92 var scope = "resources/client-navigate-frame.html";
93 var controller, frame, clientId;
94
95 return service_worker_unregister_and_register(t, worker, scope)
96 .then(reg => wait_for_state(t, reg.installing, "activated"))
97 .then(___ => with_iframe(scope))
98 .then(f => {
99 frame = f;
100 controller = frame.contentWindow.navigator.serviceWorker.controller;
101 fetch_tests_from_worker(controller);
102 return wait_for_message()
103 })
104 .then(({id}) => clientId = id)
105 .then(___ => run_test(controller, clientId, "test_client_navigate_failure" ))
106 .then(({result, url}) => {
107 assert_equals(result, "test_client_navigate_failure");
108 assert_equals(
109 frame.contentWindow.location.href,
110 new URL("resources/client-navigate-frame.html",
111 location).toString());
112 frame.contentWindow.document.body.style = "background-color: green"
113 })
114 .catch(unreached_rejection(t))
115 .then(___ => service_worker_unregister(t, scope));
116 }, "Frame location should not update on failed navigation");
117 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698