2 <script src=
"../resources/testharness.js"></script>
3 <script src=
"../resources/testharnessreport.js"></script>
4 <script src=
"resources/test-helpers.js"></script>
6 var worker_url
= 'resources/simple-intercept-worker.js';
8 async_test(function(t
) {
10 'resources/unregister-controller-page.html?load-before-unregister';
15 service_worker_unregister_and_register(t
, worker_url
, scope
)
18 return wait_for_state(t
, r
.installing
, 'activated');
21 return with_iframe(scope
);
23 .then(function(frame
) {
24 frame_window
= frame
.contentWindow
;
25 controller
= frame_window
.navigator
.serviceWorker
.controller
;
26 assert_true(controller
instanceof frame_window
.ServiceWorker
,
27 'document should load with a controller');
28 return registration
.unregister();
31 assert_equals(frame_window
.navigator
.serviceWorker
.controller
,
33 'unregistration should not modify controller');
34 return frame_window
.fetch_url('simple.txt');
36 .then(function(response
) {
37 assert_equals(response
, 'intercepted by service worker',
38 'controller should intercept requests');
41 .catch(unreached_rejection(t
));
42 }, 'Unregister does not affect existing controller');
44 async_test(function(t
) {
46 'resources/unregister-controller-page.html?load-after-unregister';
49 service_worker_unregister_and_register(t
, worker_url
, scope
)
52 return wait_for_state(t
, r
.installing
, 'activated');
55 return registration
.unregister();
58 return with_iframe(scope
);
60 .then(function(frame
) {
61 var frame_window
= frame
.contentWindow
;
62 assert_equals(frame_window
.navigator
.serviceWorker
.controller
, null,
63 'document should not have a controller');
64 return frame_window
.fetch_url('simple.txt');
66 .then(function(response
) {
67 assert_equals(response
, 'a simple text file\n',
68 'requests should not be intercepted');
71 .catch(unreached_rejection(t
));
72 }, 'Unregister prevents control of subsequent navigations');
74 async_test(function(t
) {
76 'resources/scope/no-new-controllee-even-if-registration-is-still-used';
79 service_worker_unregister_and_register(t
, worker_url
, scope
)
82 return wait_for_state(t
, r
.installing
, 'activated');
85 return with_iframe(scope
);
87 .then(function(frame
) {
88 return registration
.unregister();
91 return with_iframe(scope
);
93 .then(function(frame
) {
94 assert_equals(frame
.contentWindow
.navigator
.serviceWorker
.controller
,
96 'document should not have a controller');
99 .catch(unreached_rejection(t
));
100 }, 'Unregister prevents new controllee even if registration is still in use');