Index: content/browser/service_worker/service_worker_browsertest.cc |
diff --git a/content/browser/service_worker/service_worker_browsertest.cc b/content/browser/service_worker/service_worker_browsertest.cc |
index c9b16fe90a6665624d4ff767ec3b2043d8e9cab2..af857d65f1049369b10ee35a6fdb77a43367d084 100644 |
--- a/content/browser/service_worker/service_worker_browsertest.cc |
+++ b/content/browser/service_worker/service_worker_browsertest.cc |
@@ -276,7 +276,7 @@ class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest { |
ASSERT_EQ(expected_status, status); |
} |
- void FetchOnRegisteredWorker(ServiceWorkerFetchEventResult* result, |
+ bool FetchOnRegisteredWorker(ServiceWorkerFetchEventResult* result, |
ServiceWorkerResponse* response) { |
FetchResult fetch_result; |
fetch_result.status = SERVICE_WORKER_ERROR_FAILED; |
@@ -290,7 +290,7 @@ class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest { |
fetch_run_loop.Run(); |
*result = fetch_result.result; |
*response = fetch_result.response; |
- ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status); |
+ return fetch_result.status == SERVICE_WORKER_OK; |
} |
void FetchTestHelper(const std::string& worker_url, |
@@ -360,6 +360,20 @@ class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest { |
CreateReceiver(BrowserThread::UI, done, result)); |
} |
+ bool FireSyncEvent() { |
+ // Run the sync event. |
+ ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
+ base::RunLoop sync_run_loop; |
+ BrowserThread::PostTask(BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&self::SyncEventOnIOThread, |
+ this, |
+ sync_run_loop.QuitClosure(), |
+ &status)); |
+ sync_run_loop.Run(); |
+ return status == SERVICE_WORKER_OK; |
+ } |
+ |
protected: |
int64 next_registration_id_; |
scoped_refptr<ServiceWorkerRegistration> registration_; |
@@ -481,29 +495,41 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Rejected) { |
ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, result); |
} |
-IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, SyncEventHandled) { |
- RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, |
- "/service_worker/sync.js")); |
+// Show that sync works and that the requestSyncEvents function appropriately |
+// controls sync events. |
+IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, |
+ SyncEventAndRequestFunction) { |
+ RunOnIOThread(base::Bind( |
+ &self::SetUpRegistrationOnIOThread, this, "/service_worker/sync.js")); |
ServiceWorkerFetchEventResult result; |
ServiceWorkerResponse response; |
- // Should 404 before sync event. |
- FetchOnRegisteredWorker(&result, &response); |
+ // Fetch will return 200 if the sync event was fired, else 404. |
+ // Each fetch event will cause requestSyncEvent to be called with |
+ // different parameters, as described in the comments below. |
+ // The simpler ways to do this (e.g., putting the command in the URL) |
+ // don't work because at the time of writing SWs don't actually pass |
+ // the URL to the fetch event. |
+ |
+ EXPECT_FALSE(FireSyncEvent()); // Should not fire, next response 404. |
+ EXPECT_TRUE(FetchOnRegisteredWorker(&result, |
+ &response)); // Calls requestSyncEvents() |
EXPECT_EQ(404, response.status_code); |
- // Run the sync event. |
- ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
- base::RunLoop sync_run_loop; |
- BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
- base::Bind(&self::SyncEventOnIOThread, this, |
- sync_run_loop.QuitClosure(), |
- &status)); |
- sync_run_loop.Run(); |
- ASSERT_EQ(SERVICE_WORKER_OK, status); |
+ EXPECT_FALSE(FireSyncEvent()); // Should not fire, next response 404. |
+ EXPECT_TRUE( |
+ FetchOnRegisteredWorker(&result, |
+ &response)); // Calls requestSyncEvents(true) |
+ EXPECT_EQ(404, response.status_code); |
- // Should 200 after sync event. |
- FetchOnRegisteredWorker(&result, &response); |
+ EXPECT_TRUE(FireSyncEvent()); // Should fire, next response 200. |
+ EXPECT_TRUE(FetchOnRegisteredWorker( |
+ &result, &response)); // Calls requestSyncEvents(false) |
EXPECT_EQ(200, response.status_code); |
+ |
+ EXPECT_FALSE(FireSyncEvent()); // Should fire, next response 404. |
+ EXPECT_TRUE(FetchOnRegisteredWorker(&result, &response)); |
+ EXPECT_EQ(404, response.status_code); |
} |
class ServiceWorkerBlackBoxBrowserTest : public ServiceWorkerBrowserTest { |