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

Unified Diff: LayoutTests/http/tests/serviceworker/install-phase-event-waituntil.html

Issue 352423005: Add ServiceWorker InstallPhaseEvent.waitUntil() layout test. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add FIXME Created 6 years, 6 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/install-phase-event-waituntil.html
diff --git a/LayoutTests/http/tests/serviceworker/install-phase-event-waituntil.html b/LayoutTests/http/tests/serviceworker/install-phase-event-waituntil.html
new file mode 100644
index 0000000000000000000000000000000000000000..a7cfc252446e1fd48f1e14ee9c208e13da50358f
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/install-phase-event-waituntil.html
@@ -0,0 +1,116 @@
+<!DOCTYPE html>
+<title>InstallPhaseEvent: waitUntil</title>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.js"></script>
+<script>
+function runTest(test, scope, onRegister) {
+ var script = 'resources/install-phase-event-waituntil.js';
+ test.step(function() {
+ service_worker_unregister_and_register(
+ test, script, scope
+ ).then(
+ test.step_func(onRegister)
+ );
+ });
+}
+
+function syncWorker(test, worker, obj) {
+ var channel = new MessageChannel();
+ channel.port1.onmessage = test.step_func(function(e) {
+ var message = e.data;
+ assert_equals(message, 'SYNC', 'Should receive sync message from worker.');
+ obj.synced = true;
+ channel.port1.postMessage('ACK');
+ });
+ worker.postMessage({port: channel.port2}, [channel.port2]);
+}
+
+async_test(function(t) {
+ // Passing scope as the test switch for worker script.
+ var scope = 'install-fulfilled';
+ var onRegister = function(worker) {
+ var obj = {};
+ worker.onstatechange = t.step_func(function() {
+ if (worker.state == 'installing') {
+ syncWorker(t, worker, obj);
+ } else if (worker.state == 'installed') {
+ assert_true(obj.synced,
+ 'state should be "installed" after the waitUntil promise for "oninstall" is fulfilled.');
+ service_worker_unregister_and_done(t, scope);
+ }
+ });
+ };
+ runTest(t, scope, onRegister);
+}, 'Test install event waitUntil fulfilled');
+
+async_test(function(t) {
+ var scope = 'activate-fulfilled';
+ var onRegister = function(worker) {
+ var obj = {};
+ worker.onstatechange = t.step_func(function() {
+ if (worker.state == 'activating') {
+ syncWorker(t, worker, obj);
+ } else if (worker.state == 'activated') {
+ assert_true(obj.synced,
+ 'state should be "activated" after the waitUntil promise for "onactivate" is fulfilled.');
+ service_worker_unregister_and_done(t, scope);
+ }
+ });
+ };
+ runTest(t, scope, onRegister);
+}, 'Test activate event waitUntil fulfilled');
+
+async_test(function(t) {
+ var scope = 'install-rejected';
+ var onRegister = function(worker) {
+ worker.onstatechange = t.step_func(function() {
+ console.log(worker.state);
+ if (worker.state == 'redundant')
+ service_worker_unregister_and_done(t, scope);
+ });
+ };
+ runTest(t, scope, onRegister);
+}, 'Test install event waitUntil rejected');
+
+async_test(function(t) {
+ var scope = 'activate-rejected';
+ var onRegister = function(worker) {
+ worker.onstatechange = t.step_func(function() {
+ if (worker.state == 'redundant')
+ service_worker_unregister_and_done(t, scope);
+ });
+ };
+ runTest(t, scope, onRegister);
+}, 'Test activate event waitUntil rejected.');
+
+async_test(function(t) {
+ var scope = 'activate-multiple-fulfilled';
+ var onRegister = function(worker) {
+ var obj1 = {};
+ var obj2 = {};
+ worker.onstatechange = t.step_func(function() {
+ if (worker.state == 'activating') {
+ syncWorker(t, worker, obj1);
+ syncWorker(t, worker, obj2);
+ } else if (worker.state == 'activated') {
+ assert_true(obj1.synced && obj2.synced,
+ 'state should be "activated" after all waitUnitl promises for "onactivate" are fulfilled.');
+ service_worker_unregister_and_done(t, scope);
+ }
+ });
+ };
+ runTest(t, scope, onRegister);
+}, 'Test InstallPhaseEvent multiple waitUntil fulfilled.');
+
+async_test(function(t) {
+ var scope = 'activate-reject-precedence';
+ var onRegister = function(worker) {
+ worker.onstatechange = t.step_func(function() {
+ if (worker.state == 'redundant')
+ service_worker_unregister_and_done(t, scope);
+ });
+ };
+ runTest(t, scope, onRegister);
+}, 'Test InstallPhaseEvent waitUntil reject precedence.');
+</script>

Powered by Google App Engine
This is Rietveld 408576698