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

Unified 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, 9 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: content/test/data/service_worker/sync.js
diff --git a/content/test/data/service_worker/sync.js b/content/test/data/service_worker/sync.js
index 993e771778a505bc5ff78dedbe29a9d5655026fd..a2b4bffc83dbb7020b38d32c113ebba00178de11 100644
--- a/content/test/data/service_worker/sync.js
+++ b/content/test/data/service_worker/sync.js
@@ -3,8 +3,28 @@
// found in the LICENSE file.
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.
+var fetchCount = 0;
+
+// onfetch is a state machine:
+// 1st call returns 404 and calls requestSyncEvents()
+// .. expect sync call here ..
+// 2nd call returns 200 because sync ran and calls requestSyncEvents(false)
+// .. sync doesn't fire ..
+// 3rd call returns 404 and calls requestSyncEvents(true)
+// .. expect sync call here ..
+// 4th call returns 200 because sync ran
this.onfetch = function(event) {
+ 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.
+ requestSyncEvents();
+ } else if (fetchCount == 1) {
+ requestSyncEvents(false);
+ } else if (fetchCount == 2) {
+ requestSyncEvents(true);
+ }
+
+ fetchCount += 1;
+
response = new Response({
statusCode: code,
jsbell 2014/04/03 21:47:34 And this would be sawSyncEvent ? 200 : 404;
jkarlin 2014/04/04 11:59:09 Done.
statusText: 'OK',
@@ -15,6 +35,8 @@ this.onfetch = function(event) {
}
});
+ code = 404;
+
event.respondWith(new Promise(function(r) {
setTimeout(function() { r(response); }, 5);
}));

Powered by Google App Engine
This is Rietveld 408576698