Commit 7b0f9402 authored by horo@chromium.org's avatar horo@chromium.org

Revert of Revert of Service Worker: Add tests for same-scope new script...

Revert of Revert of Service Worker: Add tests for same-scope new script registration (patchset #1 id:1 of https://codereview.chromium.org/512703002/)

Reason for revert:
This crash will be fixed by https://codereview.chromium.org/556003006.

Original issue's description:
> Revert of Service Worker: Add tests for same-scope new script registration (patchset #6 of https://codereview.chromium.org/480943002/)
> 
> Reason for revert:
> This is crashing on Mac.
> 
> Original issue's description:
> > Service Worker: Add tests for same-scope, new script registration
> > 
> > Tests for Chromium patch:
> > https://codereview.chromium.org/506043002/
> > 
> > BUG=398355
> > 
> > Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=180948
> 
> TBR=michaeln@chromium.org,nhiroki@chromium.org,falken@chromium.org
> NOTREECHECKS=true
> NOTRY=true
> BUG=398355
> 
> Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=180956

TBR=michaeln@chromium.org,nhiroki@chromium.org,falken@chromium.org,mlamouri@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=398355

Review URL: https://codereview.chromium.org/547743003

git-svn-id: svn://svn.chromium.org/blink/trunk@181878 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent a23c0523
...@@ -1269,7 +1269,6 @@ crbug.com/401380 inspector/elements/styles/styles-should-not-force-sync-style-re ...@@ -1269,7 +1269,6 @@ crbug.com/401380 inspector/elements/styles/styles-should-not-force-sync-style-re
crbug.com/401381 [ XP ] http/tests/serviceworker/fetch-event.html [ Pass Failure ] crbug.com/401381 [ XP ] http/tests/serviceworker/fetch-event.html [ Pass Failure ]
crbug.com/405847 [ XP ] http/tests/serviceworker/install-phase-event-waituntil.html [ Pass Failure ] crbug.com/405847 [ XP ] http/tests/serviceworker/install-phase-event-waituntil.html [ Pass Failure ]
crbug.com/409755 http/tests/serviceworker/request.html [ Crash Pass ] crbug.com/409755 http/tests/serviceworker/request.html [ Crash Pass ]
crbug.com/398355 http/tests/serviceworker/unregister-then-register-new-script.html [ Skip ]
crbug.com/397321 compositing/repaint/should-not-repaint-composited-opacity.html [ Crash Pass ] crbug.com/397321 compositing/repaint/should-not-repaint-composited-opacity.html [ Crash Pass ]
crbug.com/397321 svg/custom/pattern-3-step-cycle.html [ Crash Pass ] crbug.com/397321 svg/custom/pattern-3-step-cycle.html [ Crash Pass ]
......
...@@ -66,18 +66,28 @@ function normalizeURL(url) { ...@@ -66,18 +66,28 @@ function normalizeURL(url) {
} }
function wait_for_update(test, registration) { function wait_for_update(test, registration) {
return new Promise(test.step_func(function(resolve) { if (!registration || registration.unregister == undefined) {
registration.addEventListener('updatefound', test.step_func(function() { return Promise.reject(new Error(
resolve(registration.installing); 'wait_for_update must be passed a ServiceWorkerRegistration'));
})); }
return new Promise(test.step_func(function(resolve) {
registration.addEventListener('updatefound', test.step_func(function() {
resolve(registration.installing);
}));
})); }));
} }
function wait_for_state(test, worker, state) { function wait_for_state(test, worker, state) {
return new Promise(test.step_func(function(resolve) { if (!worker || worker.state == undefined) {
worker.addEventListener('statechange', test.step_func(function() { return Promise.reject(new Error(
if (worker.state === state) 'wait_for_state must be passed a ServiceWorker'));
resolve(state); }
return new Promise(test.step_func(function(resolve) {
worker.addEventListener('statechange', test.step_func(function() {
if (worker.state === state)
resolve(state);
})); }));
})); }));
} }
......
...@@ -6,10 +6,11 @@ ...@@ -6,10 +6,11 @@
var worker_url = 'resources/empty-worker.js'; var worker_url = 'resources/empty-worker.js';
async_test(function(t) { async_test(function(t) {
var scope = 'scope/new-worker'; var scope = 'scope/register-waits-for-unregistered-registration-to-clear';
var new_worker_url = worker_url + '?new'; var new_worker_url = worker_url + '?new';
var iframe; var iframe;
var registration; var registration;
var unloaded = false;
service_worker_unregister_and_register(t, worker_url, scope) service_worker_unregister_and_register(t, worker_url, scope)
.then(function(r) { .then(function(r) {
...@@ -27,14 +28,76 @@ async_test(function(t) { ...@@ -27,14 +28,76 @@ async_test(function(t) {
return registration.unregister(); return registration.unregister();
}) })
.then(function() { .then(function() {
// FIXME: Register should not resolve until controllees are unloaded. setTimeout(function() {
unloaded = true;
unload_iframe(iframe);
}, 10);
return navigator.serviceWorker.register(new_worker_url, return navigator.serviceWorker.register(new_worker_url,
{ scope: scope }); { scope: scope });
}) })
.then(function(new_registration) { .then(function(new_registration) {
return wait_for_update(t, new_registration); assert_true(unloaded,
'register should not resolve until iframe unloaded');
assert_equals(registration.installing, null,
'registration.installing');
assert_equals(registration.waiting, null, 'registration.waiting');
assert_equals(registration.active, null, 'registration.active');
return new_registration.unregister();
})
.then(function() {
t.done();
})
.catch(unreached_rejection(t));
}, 'Registering a new script URL does not resolve until unregistered ' +
'registration is cleared');
async_test(function(t) {
var scope = 'scope/unregister-then-register-new-script-that-exists';
var new_worker_url = worker_url + '?new';
var iframe;
var registration;
service_worker_unregister_and_register(t, worker_url, scope)
.then(function(r) {
registration = r;
return wait_for_update(t, registration);
})
.then(function(worker) {
return wait_for_state(t, worker, 'activated');
})
.then(function() {
return with_iframe(scope);
})
.then(function(frame) {
iframe = frame;
return registration.unregister();
})
.then(function() {
var promise = navigator.serviceWorker.register(new_worker_url,
{ scope: scope });
unload_iframe(iframe);
return promise;
})
.then(function(new_registration) {
assert_not_equals(registration, new_registration,
'register() should resolve to a new registration');
assert_equals(registration.installing, null,
'old registration.installing');
assert_equals(registration.waiting, null,
'old registration.waiting');
assert_equals(registration.active, null,
'old registration.active');
registration = new_registration;
return wait_for_update(t, registration);
}) })
.then(function(worker) { .then(function(worker) {
assert_equals(registration.installing.scriptURL,
normalizeURL(new_worker_url),
'new registration.installing');
assert_equals(registration.waiting, null,
'new registration.waiting');
assert_equals(registration.active, null,
'new registration.active');
return wait_for_state(t, worker, 'activated'); return wait_for_state(t, worker, 'activated');
}) })
.then(function() { .then(function() {
...@@ -44,14 +107,18 @@ async_test(function(t) { ...@@ -44,14 +107,18 @@ async_test(function(t) {
assert_equals( assert_equals(
frame.contentWindow.navigator.serviceWorker.controller.scriptURL, frame.contentWindow.navigator.serviceWorker.controller.scriptURL,
normalizeURL(new_worker_url), normalizeURL(new_worker_url),
'document controller is the new worker'); 'the new worker should control a new document');
service_worker_unregister_and_done(t, scope); unload_iframe(frame);
return registration.unregister();
})
.then(function() {
t.done();
}) })
.catch(unreached_rejection(t)); .catch(unreached_rejection(t));
}, 'Unregister then register a new script URL'); }, 'Registering a new script URL while an unregistered registration is in use');
async_test(function(t) { async_test(function(t) {
var scope = 'scope/non-existent-worker'; var scope = 'scope/unregister-then-register-new-script-that-404s';
var iframe; var iframe;
var registration; var registration;
...@@ -71,32 +138,31 @@ async_test(function(t) { ...@@ -71,32 +138,31 @@ async_test(function(t) {
return registration.unregister(); return registration.unregister();
}) })
.then(function() { .then(function() {
// FIXME: Register should not resolve until controllees are unloaded. var promise = navigator.serviceWorker.register('this-will-404',
return navigator.serviceWorker.register('this-will-404', { scope: scope });
{ scope: scope }); unload_iframe(iframe);
return promise;
}) })
.then( .then(
function() { function() {
assert_unreached('register should reject the promise'); assert_unreached('register should reject the promise');
}, },
function() { function() {
return unload_iframe(iframe);
})
.then(function() {
return with_iframe(scope); return with_iframe(scope);
}) })
.then(function(frame) { .then(function(frame) {
assert_equals(frame.contentWindow.navigator.serviceWorker.controller, assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
null, null,
'document should not load with a controller'); 'document should not load with a controller');
service_worker_unregister_and_done(t, scope); unload_iframe(frame);
t.done();
}) })
.catch(unreached_rejection(t)); .catch(unreached_rejection(t));
}, 'Registering a new script URL that 404s does not resurrect an ' + }, 'Registering a new script URL that 404s does not resurrect an ' +
'unregistered registration'); 'unregistered registration');
async_test(function(t) { async_test(function(t) {
var scope = 'scope/reject-install-worker'; var scope = 'scope/unregister-then-register-reject-install-worker';
var iframe; var iframe;
var registration; var registration;
...@@ -116,19 +182,18 @@ async_test(function(t) { ...@@ -116,19 +182,18 @@ async_test(function(t) {
return registration.unregister(); return registration.unregister();
}) })
.then(function() { .then(function() {
// FIXME: Register should not resolve until controllees are unloaded. var promise = navigator.serviceWorker.register(
return navigator.serviceWorker.register(
'resources/reject-install-worker.js', { scope: scope }); 'resources/reject-install-worker.js', { scope: scope });
unload_iframe(iframe);
return promise;
}) })
.then(function(new_registration) { .then(function(r) {
return wait_for_update(t, new_registration); registration = r;
return wait_for_update(t, registration);
}) })
.then(function(worker) { .then(function(worker) {
return wait_for_state(t, worker, 'redundant'); return wait_for_state(t, worker, 'redundant');
}) })
.then(function(worker) {
return unload_iframe(iframe);
})
.then(function() { .then(function() {
return with_iframe(scope); return with_iframe(scope);
}) })
...@@ -136,7 +201,11 @@ async_test(function(t) { ...@@ -136,7 +201,11 @@ async_test(function(t) {
assert_equals(frame.contentWindow.navigator.serviceWorker.controller, assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
null, null,
'document should not load with a controller'); 'document should not load with a controller');
service_worker_unregister_and_done(t, scope); unload_iframe(frame);
return registration.unregister();
})
.then(function() {
t.done();
}) })
.catch(unreached_rejection(t)); .catch(unreached_rejection(t));
}, 'Registering a new script URL that fails to install does not resurrect ' + }, 'Registering a new script URL that fails to install does not resurrect ' +
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment