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

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: Cleaned up the testing code 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..4f16b995fcbb15ac05217b775e19627e7cd2cb5a 100644
--- a/content/test/data/service_worker/sync.js
+++ b/content/test/data/service_worker/sync.js
@@ -2,9 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-var code = 404;
+var sawSyncEvent = false;
+var fetchCount = 0;
+
+// onfetch is a state machine:
+// 1st call returns 404 and calls requestSyncEvents()
+// .. sync doesn't fire ..
+// 2nd call returns 404 and calls requestSyncEvents(true)
+// .. sync fires ..
+// 3rd call returns 200 and calls requestSyncEvents(false)
+// .. sync doesn't fire ..
+// 4th call returns 404
this.onfetch = function(event) {
+ var code = sawSyncEvent ? 200 : 404;
response = new Response({
statusCode: code,
statusText: 'OK',
@@ -18,8 +29,19 @@ this.onfetch = function(event) {
event.respondWith(new Promise(function(r) {
setTimeout(function() { r(response); }, 5);
}));
+
+ if (fetchCount == 0) {
+ requestSyncEvents();
+ } else if (fetchCount == 1) {
+ requestSyncEvents(true);
+ } else if (fetchCount == 2) {
+ requestSyncEvents(false);
+ }
+
+ fetchCount += 1;
+ sawSyncEvent = false;
};
this.onsync = function(event) {
- code = 200;
+ sawSyncEvent = true;
};

Powered by Google App Engine
This is Rietveld 408576698