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

Unified Diff: content/browser/service_worker/service_worker_browsertest.cc

Issue 205033002: Browser side of new ServiceWorker 'sync' event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Kinuko comments 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/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 65afe8d82067baf9e1eaecf96e9aa97d66403edd..3a69a41d60e706634c0f4b817b939037908b8ec8 100644
--- a/content/browser/service_worker/service_worker_browsertest.cc
+++ b/content/browser/service_worker/service_worker_browsertest.cc
@@ -259,12 +259,8 @@ class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest {
ASSERT_EQ(SERVICE_WORKER_OK, status);
}
- void FetchTestHelper(const std::string& worker_url,
- ServiceWorkerFetchEventResult* result,
- ServiceWorkerResponse* response) {
- RunOnIOThread(
- base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url));
-
+ void FetchOnRegisteredWorker(ServiceWorkerFetchEventResult* result,
+ ServiceWorkerResponse* response) {
FetchResult fetch_result;
fetch_result.status = SERVICE_WORKER_ERROR_FAILED;
base::RunLoop fetch_run_loop;
@@ -280,6 +276,15 @@ class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest {
ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status);
}
+ void FetchTestHelper(const std::string& worker_url,
+ ServiceWorkerFetchEventResult* result,
+ ServiceWorkerResponse* response) {
+ RunOnIOThread(
+ base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url));
+
+ FetchOnRegisteredWorker(result, response);
+ }
+
void SetUpRegistrationOnIOThread(const std::string& worker_url) {
const int64 version_id = 1L;
registration_ = new ServiceWorkerRegistration(
@@ -323,6 +328,13 @@ class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest {
version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result));
}
+ void SyncEventOnIOThread(const base::Closure& done,
+ ServiceWorkerStatusCode* result) {
+ ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ version_->DispatchSyncEvent(
+ CreateReceiver(BrowserThread::UI, done, result));
+ }
+
protected:
int64 next_registration_id_;
scoped_refptr<ServiceWorkerRegistration> registration_;
@@ -433,6 +445,31 @@ 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"));
+ ServiceWorkerFetchEventResult result;
+ ServiceWorkerResponse response;
+
+ // Should 404 before sync event.
+ FetchOnRegisteredWorker(&result, &response);
+ 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);
+
+ // Should 200 after sync event.
+ FetchOnRegisteredWorker(&result, &response);
+ EXPECT_EQ(200, response.status_code);
+}
+
class ServiceWorkerBlackBoxBrowserTest : public ServiceWorkerBrowserTest {
public:
typedef ServiceWorkerBlackBoxBrowserTest self;

Powered by Google App Engine
This is Rietveld 408576698