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

Side by Side Diff: content/test/data/service_worker/sync.js

Issue 214383005: Browser side of ServiceWorker requestSyncEvents() function (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More nits 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var code = 404; 5 var code = 404;
jsbell 2014/04/03 21:47:34 The test would be clearer if the global state was
jkarlin 2014/04/04 11:59:09 Done.
6 var fetchCount = 0;
7
8 // onfetch is a state machine:
9 // 1st call returns 404 and calls requestSyncEvents()
10 // .. expect sync call here ..
11 // 2nd call returns 200 because sync ran and calls requestSyncEvents(false)
12 // .. sync doesn't fire ..
13 // 3rd call returns 404 and calls requestSyncEvents(true)
14 // .. expect sync call here ..
15 // 4th call returns 200 because sync ran
6 16
7 this.onfetch = function(event) { 17 this.onfetch = function(event) {
18 if (fetchCount == 0) {
jsbell 2014/04/03 21:47:34 Since the sync event won't fire until after the ev
jkarlin 2014/04/04 11:59:09 Done. Great suggestions, thanks.
19 requestSyncEvents();
20 } else if (fetchCount == 1) {
21 requestSyncEvents(false);
22 } else if (fetchCount == 2) {
23 requestSyncEvents(true);
24 }
25
26 fetchCount += 1;
27
8 response = new Response({ 28 response = new Response({
9 statusCode: code, 29 statusCode: code,
jsbell 2014/04/03 21:47:34 And this would be sawSyncEvent ? 200 : 404;
jkarlin 2014/04/04 11:59:09 Done.
10 statusText: 'OK', 30 statusText: 'OK',
11 method: 'GET', 31 method: 'GET',
12 headers: { 32 headers: {
13 'Content-Language': 'fi', 33 'Content-Language': 'fi',
jsbell 2014/04/03 21:47:34 Just for kicks? :)
jkarlin 2014/04/04 11:59:09 Why not :)
14 'Content-Type': 'text/html; charset=UTF-8' 34 'Content-Type': 'text/html; charset=UTF-8'
15 } 35 }
16 }); 36 });
17 37
38 code = 404;
39
18 event.respondWith(new Promise(function(r) { 40 event.respondWith(new Promise(function(r) {
19 setTimeout(function() { r(response); }, 5); 41 setTimeout(function() { r(response); }, 5);
20 })); 42 }));
21 }; 43 };
22 44
23 this.onsync = function(event) { 45 this.onsync = function(event) {
24 code = 200; 46 code = 200;
25 }; 47 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698