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

Side by Side 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: Created 6 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>InstallPhaseEvent: waitUntil</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="resources/test-helpers.js"></script>
6 <script>
7 function runTest(test, scope, onRegister) {
8 var worker_script = 'resources/install-phase-event-waituntil.js';
falken 2014/06/30 04:35:31 Unfortunately Service Worker layout tests don't ha
xiang 2014/06/30 06:37:11 I will follow the Blink-style, thanks for the info
9 test.step(function() {
10 service_worker_unregister_and_register(
11 test, worker_script, scope
12 ).then(
13 test.step_func(onRegister)
14 );
15 });
16 }
17
18 function syncWorker(test, worker, obj) {
19 var channel = new MessageChannel();
20 channel.port1.onmessage = test.step_func(function(e) {
21 var message = e.data;
22 assert_equals(message, 'SYNC', 'Should receive sync message from worker. ');
23 obj.synced = true;
24 channel.port1.postMessage('ACK');
25 });
26 worker.postMessage({port: channel.port2}, [channel.port2]);
falken 2014/06/30 04:35:31 I might be missing something. The async tests run
xiang 2014/06/30 06:37:11 Yes, they're parallel. I think the passing "worker
27 }
28
29 (function() {
30 var t = async_test('Test install event waitUntil fulfilled.');
31 // Passing scope as the test switch for worker script.
32 var scope = 'install-fulfilled';
33 var onRegister = function(worker) {
34 var obj = {};
35 worker.onstatechange = t.step_func(function() {
36 if (worker.state == 'installing') {
37 syncWorker(t, worker, obj);
38 } else if (worker.state == 'installed') {
39 assert_true(obj.synced, '"installed" state should changed after sync.');
falken 2014/06/30 04:35:31 This description is a bit unclear: "state should c
xiang 2014/06/30 06:37:11 will change that.
40 service_worker_unregister_and_done(t, scope);
41 }
42 });
43 };
44 runTest(t, scope, onRegister);
45 }());
46
47 (function() {
48 var t = async_test('Test activate event waitUntil fulfilled.');
49 var scope = 'activate-fulfilled';
50 var onRegister = function(worker) {
51 var obj = {};
52 worker.onstatechange = t.step_func(function() {
53 if (worker.state == 'activating') {
54 syncWorker(t, worker, obj);
55 } else if (worker.state == 'activated') {
56 assert_true(obj.synced, '"activated" state should changed after sync.');
57 service_worker_unregister_and_done(t, scope);
58 }
59 });
60 };
61 runTest(t, scope, onRegister);
62 }());
63
64 (function() {
65 var t = async_test('Test install event waitUntil rejected.');
66 var scope = 'install-rejected';
67 var onRegister = function(worker) {
68 worker.onstatechange = t.step_func(function() {
69 if (worker.state == 'redundant')
70 service_worker_unregister_and_done(t, scope);
71 });
72 };
73 runTest(t, scope, onRegister);
74 }());
75
76 (function() {
77 var t = async_test('Test activate event waitUntil rejected.');
78 var scope = 'activate-rejected';
79 var onRegister = function(worker) {
80 worker.onstatechange = t.step_func(function() {
81 if (worker.state == 'redundant')
82 service_worker_unregister_and_done(t, scope);
83 });
84 };
85 runTest(t, scope, onRegister);
86 }());
87
88 (function() {
89 var t = async_test('Test InstallPhaseEvent multiple waitUntil fulfilled.');
90 var scope = 'activate-multiple-fulfilled';
91 var onRegister = function(worker) {
92 var obj1 = {};
93 var obj2 = {};
94 worker.onstatechange = t.step_func(function() {
95 if (worker.state == 'activating') {
96 syncWorker(t, worker, obj1);
97 syncWorker(t, worker, obj2);
98 } else if (worker.state == 'activated') {
99 assert_true(obj1.synced && obj2.synced, '"activated" state shoul d changed after sync.');
100 service_worker_unregister_and_done(t, scope);
101 }
102 });
103 };
104 runTest(t, scope, onRegister);
105 }());
106
107 (function() {
108 var t = async_test('Test InstallPhaseEvent waitUntil reject precedence.');
109 var scope = 'activate-reject-precedence';
110 var onRegister = function(worker) {
111 worker.onstatechange = t.step_func(function() {
112 if (worker.state == 'redundant')
113 service_worker_unregister_and_done(t, scope);
114 });
115 };
116 runTest(t, scope, onRegister);
117 }());
118 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698