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