2 <title>Service Worker: claim client not using registration
</title>
3 <script src=
"../resources/testharness.js"></script>
4 <script src=
"../resources/testharness-helpers.js"></script>
5 <script src=
"../resources/testharnessreport.js"></script>
6 <script src=
"resources/test-helpers.js"></script>
10 promise_test(function(t
) {
11 var init_scope
= 'resources/blank.html?not-using-init';
12 var claim_scope
= 'resources/blank.html?not-using';
13 var init_worker_url
= 'resources/empty.js';
14 var claim_worker_url
= 'resources/claim-worker.js';
15 var claim_worker
, claim_registration
, frame1
, frame2
;
16 return service_worker_unregister_and_register(
17 t
, init_worker_url
, init_scope
)
18 .then(function(registration
) {
19 return wait_for_state(t
, registration
.installing
, 'activated');
23 [with_iframe(init_scope
), with_iframe(claim_scope
)]);
25 .then(function(frames
) {
29 frame1
.contentWindow
.navigator
.serviceWorker
.controller
.scriptURL
,
30 normalizeURL(init_worker_url
),
31 'Frame1 controller should not be null');
33 frame2
.contentWindow
.navigator
.serviceWorker
.controller
, null,
34 'Frame2 controller should be null');
35 return navigator
.serviceWorker
.register(claim_worker_url
,
36 {scope
: claim_scope
});
38 .then(function(registration
) {
39 claim_worker
= registration
.installing
;
40 claim_registration
= registration
;
41 return wait_for_state(t
, registration
.installing
, 'activated');
44 var saw_controllerchanged
= new Promise(function(resolve
) {
45 frame2
.contentWindow
.navigator
.serviceWorker
.oncontrollerchange
=
46 function() { resolve(); }
48 var channel
= new MessageChannel();
49 var saw_message
= new Promise(function(resolve
) {
50 channel
.port1
.onmessage
= t
.step_func(function(e
) {
51 assert_equals(e
.data
, 'PASS',
52 'Worker call to claim() should fulfill.');
56 claim_worker
.postMessage({port
: channel
.port2
}, [channel
.port2
]);
57 return Promise
.all([saw_controllerchanged
, saw_message
]);
61 frame1
.contentWindow
.navigator
.serviceWorker
.controller
.scriptURL
,
62 normalizeURL(init_worker_url
),
63 'Frame1 should not be influenced');
65 frame2
.contentWindow
.navigator
.serviceWorker
.controller
.scriptURL
,
66 normalizeURL(claim_worker_url
),
67 'Frame2 should be controlled by the new registration');
70 return claim_registration
.unregister();
73 return service_worker_unregister_and_done(t
, init_scope
);
75 }, 'Test claim client which is not using registration');
77 promise_test(function(t
) {
78 var scope
= 'resources/blank.html?longer-matched';
79 var claim_scope
= 'resources/blank.html?longer';
80 var claim_worker_url
= 'resources/claim-worker.js';
81 var installing_worker_url
= 'resources/empty-worker.js';
82 var frame
, claim_worker
;
83 return with_iframe(scope
)
86 return navigator
.serviceWorker
.register(
87 claim_worker_url
, {scope
: claim_scope
});
89 .then(function(registration
) {
90 claim_worker
= registration
.installing
;
91 return wait_for_state(t
, registration
.installing
, 'activated');
94 return navigator
.serviceWorker
.register(
95 installing_worker_url
, {scope
: scope
});
98 var channel
= new MessageChannel();
99 var saw_message
= new Promise(function(resolve
) {
100 channel
.port1
.onmessage
= t
.step_func(function(e
) {
101 assert_equals(e
.data
, 'PASS',
102 'Worker call to claim() should fulfill.');
106 claim_worker
.postMessage({port
: channel
.port2
}, [channel
.port2
]);
111 frame
.contentWindow
.navigator
.serviceWorker
.controller
, null,
112 'Frame should not be claimed when a longer-matched ' +
113 'registration exists');
115 return service_worker_unregister(t
, claim_scope
);
118 return service_worker_unregister_and_done(t
, scope
);
120 }, 'Test claim client when there\'s a longer-matched registration not ' +
121 'already used by the page');