Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Unified Diff: LayoutTests/http/tests/serviceworker/registration-end-to-end.html

Issue 238993003: ServiceWorker: "minimal" end-to-end sample as a W3C test (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Sync with github Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/serviceworker/registration-end-to-end.html
diff --git a/LayoutTests/http/tests/serviceworker/registration-end-to-end.html b/LayoutTests/http/tests/serviceworker/registration-end-to-end.html
new file mode 100644
index 0000000000000000000000000000000000000000..b7ca6ea780b3426628f3183ead003c6b0ad133f5
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/registration-end-to-end.html
@@ -0,0 +1,91 @@
+<!DOCTYPE html>
+<title>Service Worker: registration end-to-end</title>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="resources/support.js"></script>
+<script>
+var t = async_test('Registration: end-to-end');
+t.step(function() {
+
+ var serviceWorkerStates = [];
+ var lastServiceWorkerState = '';
+ var receivedMessageFromPort = '';
+ var currentChangeCount = 0;
+
+ assert_true(navigator.serviceWorker instanceof ServiceWorkerContainer);
+ assert_equals(typeof navigator.serviceWorker.register, 'function');
+ assert_equals(typeof navigator.serviceWorker.unregister, 'function');
+
+ navigator.serviceWorker.oncurrentchange = function() {
jsbell 2014/04/16 17:43:38 I reintroduced this as it seems like a valid asser
+ ++currentChangeCount;
+ };
+
+ // This always tests fresh registration, so unregister it first.
+
+ // unregister is non-idempotent, and rejects if not found.
+ // https://github.com/slightlyoff/ServiceWorker/issues/233
+ navigator.serviceWorker.unregister('/in-scope/*').then(
+ t.step_func(doRegister), t.step_func(doRegister));
jsbell 2014/04/16 17:43:38 Having unregister() reject if there was no match s
kinuko 2014/04/17 11:32:54 It's the behavior currently spec'ed, not the test'
+
+ function doRegister() {
+ navigator.serviceWorker.register(
+ 'resources/end-to-end-worker.js',
+ {scope: '/in-scope/*'}
+ ).then(
+ t.step_func(onRegister)
jsbell 2014/04/16 17:43:38 On github, the registration.html calls onRegister
kinuko 2014/04/17 11:32:54 It was a bug, it's fixed now (by dominicc's pull r
+ ).catch(
+ fail(t, 'Registration failed')
+ );
+ }
+
+ function onRegister(sw) {
+ serviceWorkerStates.push(sw.state);
+ lastServiceWorkerState = sw.state;
+
+ sendMessagePort(sw, 'registering doc').onmessage = t.step_func(function (e) {
+ receivedMessageFromPort = e.data;
+ if (lastServiceWorkerState === 'active')
+ onTestFinished();
jsbell 2014/04/16 17:43:38 Having two exit paths makes me sad. The test shoul
kinuko 2014/04/17 11:32:54 Yup agreed, btw feel free to fix these flaws here
+ });
+
+ sw.onstatechange = t.step_func(function() {
+ serviceWorkerStates.push(sw.state);
+
+ switch (sw.state) {
+ case 'installing':
+ // FIXME: Not currently seen.
+ assert_equals(lastServiceWorkerState, 'parsed');
jsbell 2014/04/16 17:43:38 This case currently never matches, but it's in git
kinuko 2014/04/17 11:32:54 I wasn't very sure which is expected behavior, whe
+ break;
+ case 'installed':
+ assert_equals(lastServiceWorkerState, 'installing');
+ break;
+ case 'activating':
+ assert_equals(lastServiceWorkerState, 'installed');
+ break;
+ case 'active':
+ assert_equals(lastServiceWorkerState, 'activating');
+ break;
+ default:
+ fail(t, 'Unexpected state: ' + sw.state);
+ }
+
+ lastServiceWorkerState = sw.state;
+ if (sw.state === 'active' && receivedMessageFromPort)
+ onTestFinished();
falken 2014/04/22 14:03:08 FYI, I think the flaky timeouts are caused by acti
+ });
+ }
+
+ function onTestFinished() {
+ assert_array_equals(serviceWorkerStates,
+ ['installing', 'installed', 'activating', 'active'],
+ 'Service worker should pass through four states');
+
+ assert_equals(currentChangeCount, 0,
+ 'Should not see current changes since document is out of scope');
+
+ assert_equals(receivedMessageFromPort, 'Ack for: registering doc');
+
+ t.done();
+ }
+});
+</script>

Powered by Google App Engine
This is Rietveld 408576698