Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / multiple-register.html
blobea1095f28e227c7cf0df1bd7c1652abef3ceda26
1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/test-helpers.js"></script>
5 <script>
6 var worker_url = 'resources/empty-worker.js';
8 async_test(function(t) {
9 var scope = 'resources/scope/subsequent-register-from-same-window';
10 var registration;
12 service_worker_unregister_and_register(t, worker_url, scope)
13 .then(function(r) {
14 registration = r;
15 return wait_for_state(t, r.installing, 'activated');
17 .then(function() {
18 return navigator.serviceWorker.register(worker_url, { scope: scope });
20 .then(function(new_registration) {
21 assert_registration_equals(new_registration, registration);
22 assert_not_equals(
23 new_registration, registration,
24 'register should resolve to a new registration object');
25 assert_equals(new_registration.active, registration.active,
26 'register should resolve to the same worker');
27 assert_equals(new_registration.active.state, 'activated',
28 'the worker should be in state "activated"');
29 return registration.unregister();
31 .then(function() { t.done(); })
32 .catch(unreached_rejection(t));
33 }, 'Subsequent registrations resolve to a different registration object ' +
34 'but they refer to the same registration and workers');
36 async_test(function(t) {
37 var scope = 'resources/scope/subsequent-register-from-different-iframe';
38 var frame;
39 var registration;
41 service_worker_unregister_and_register(t, worker_url, scope)
42 .then(function(r) {
43 registration = r;
44 return wait_for_state(t, r.installing, 'activated');
46 .then(function() { return with_iframe('out-of-scope'); })
47 .then(function(f) {
48 frame = f;
49 return frame.contentWindow.navigator.serviceWorker.register(
50 worker_url, { scope: scope });
52 .then(function(new_registration) {
53 assert_not_equals(
54 registration, new_registration,
55 'register should resolve to a different registration');
56 assert_equals(
57 registration.scope, new_registration.scope,
58 'registrations should have the same scope');
60 assert_equals(
61 registration.installing, null,
62 'installing worker should be null');
63 assert_equals(
64 new_registration.installing, null,
65 'installing worker should be null');
66 assert_equals(
67 registration.waiting, null,
68 'waiting worker should be null')
69 assert_equals(
70 new_registration.waiting, null,
71 'waiting worker should be null')
73 assert_not_equals(
74 registration.active, new_registration.active,
75 'registration should have a different active worker');
76 assert_equals(
77 registration.active.scriptURL,
78 new_registration.active.scriptURL,
79 'active workers should have the same script URL');
80 assert_equals(
81 registration.active.state,
82 new_registration.active.state,
83 'active workers should be in the same state');
85 frame.remove();
86 return registration.unregister();
88 .then(function() { t.done(); })
89 .catch(unreached_rejection(t));
90 }, 'Subsequent registrations from a different iframe resolve to the ' +
91 'different registration object but they refer to the same ' +
92 'registration and workers');
94 async_test(function(t) {
95 var scope = 'resources/scope/concurrent-register';
96 var number_of_registrations = 10;
98 service_worker_unregister(t, scope)
99 .then(function() {
100 var promises = [];
101 for (var i = 0; i < number_of_registrations; ++i) {
102 promises.push(navigator.serviceWorker.register(worker_url,
103 { scope: scope }));
105 return Promise.all(promises);
107 .then(function(registrations) {
108 for (var i = 1; i < number_of_registrations; ++i) {
109 assert_registration_equals(registrations[i], registrations[0]);
110 assert_not_equals(
111 registrations[i], registrations[0],
112 'register should resolve to a new registration object');
114 registrations.forEach(function(registration) {
116 return registrations[0].unregister();
118 .then(function() { t.done(); })
119 .catch(unreached_rejection(t));
120 }, 'Concurrent registrations resolve to a different registration object ' +
121 'but they refer to the same registration and workers');
123 </script>