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

Side by Side Diff: LayoutTests/http/tests/serviceworker/getregistrations.html

Issue 1168393002: Service Worker: Add ServiceWorkerContainer.getRegistrations() method. (Blink layout tests) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove iframe at the end of the test. Created 5 years, 6 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 <title>Service Worker: getRegistrations()</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="resources/test-helpers.js"></script>
6 <script src="../resources/get-host-info.js"></script>
7 <script src="../fetch/resources/fetch-test-helpers.js"></script>
8 <script>
9 sequential_promise_test(function(t) {
10 return navigator.serviceWorker.getRegistrations()
11 .then(function(value) {
12 assert_array_equals(
13 value,
14 [],
15 'getRegistrations should resolve with an empty array.');
16 });
17 }, 'getRegistrations');
18
19 sequential_promise_test(function(t) {
20 var scope = 'resources/scope/getregistrations/normal';
21 var script = 'resources/empty-worker.js';
22 var registrations = [];
23 return service_worker_unregister_and_register(t, script, scope)
24 .then(function(r) {
25 registrations.push(r);
26 return navigator.serviceWorker.getRegistrations();
27 })
28 .then(function(value) {
29 assert_array_equals(
30 value,
31 registrations,
32 'getRegistrations should resolve with array of registrations.');
33 return service_worker_unregister(t, scope);
34 });
35 }, 'Register then getRegistrations');
36
37 sequential_promise_test(function(t) {
38 var scope1 = 'resources/scope/getregistrations/scope1';
39 var scope2 = 'resources/scope/getregistrations/scope2';
40 var script = 'resources/empty-worker.js';
41 var registrations = [];
42 return service_worker_unregister_and_register(t, script, scope1)
43 .then(function(r) {
44 registrations.push(r);
45 return service_worker_unregister_and_register(t, script, scope2);
46 })
47 .then(function(r) {
48 registrations.push(r);
49 return navigator.serviceWorker.getRegistrations();
50 })
51 .then(function(value) {
52 assert_array_equals(
53 value,
54 registrations,
55 'getRegistrations should resolve with array of registrations.');
56 return service_worker_unregister(t, scope1);
57 })
58 .then(function() {
59 return service_worker_unregister(t, scope2);
60 });
61 }, 'Register multiple times then getRegistrations');
62
63 sequential_promise_test(function(t) {
64 var scope = 'resources/scope/getregistrations/register-unregister';
65 var script = 'resources/empty-worker.js';
66 return service_worker_unregister_and_register(t, script, scope)
67 .then(function(registration) {
68 return registration.unregister();
69 })
70 .then(function() {
71 return navigator.serviceWorker.getRegistrations();
72 })
73 .then(function(value) {
74 assert_array_equals(
75 value,
76 [],
77 'getRegistrations should resolve with an empty array.');
78 });
79 }, 'Register then Unregister then getRegistrations');
80
81 sequential_promise_test(function(t) {
82 // Top-level window's origin is http://127.0.0.1:8000
83 // Set frame's origin to http://localhost:8000
84 var host_info = get_host_info();
85 var frame_url = host_info['HTTP_REMOTE_ORIGIN'] +
86 '/serviceworker/resources/frame-for-getregistrations.html';
87 var scope = 'resources/scope-for-getregistrations';
88 var script = 'resources/empty-worker.js';
89 var frame;
90 var registrations = [];
91
92 return with_iframe(frame_url)
93 .then(function(f) {
94 // frame registered its registration scoped
95 // http://localhost:8000/serviceworker/resources/scope-for-getregistra tions
96 frame = f;
97 // Top-level window registers its registration scoped
98 // http://127.0.0.1:8000/serviceworker/resources/scope-for-getregistra tions
99 return service_worker_unregister_and_register(t, script, scope);
100 })
101 .then(function(r) {
102 registrations.push(r);
103 return navigator.serviceWorker.getRegistrations();
104 })
105 .then(function(value) {
106 assert_array_equals(
107 value,
108 registrations,
109 'getRegistrations should only return same origin registrations.');
110
111 var channel = new MessageChannel();
112 var resolve;
113 var p = new Promise(function(r) { resolve = r; });
114
115 channel.port1.onmessage = function(e) {
116 if (e.data == 'unregistered')
117 resolve();
118 };
119 frame.contentWindow.postMessage('unregister', '*', [channel.port2]);
120 return p;
121 })
122 .then(function() {
123 frame.remove();
124 return service_worker_unregister(t, scope);
125 });
126 }, 'getRegistrations promise resolves only with same origin registrations.');
127
128 sequential_promise_test_done();
129 done();
130 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698