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

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

Issue 1282013004: BackgroundSyncManager tracks client registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 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 ca2d440592867bba8341066408ddcd3901ead707..cad5f62b4084a6ba81627750d88e9a92ec54c496 100644
--- a/content/browser/service_worker/service_worker_browsertest.cc
+++ b/content/browser/service_worker/service_worker_browsertest.cc
@@ -171,12 +171,6 @@ void ExpectResultAndRun(bool expected,
continuation.Run();
}
-SyncRegistrationPtr CreateOneShotSyncRegistration(const std::string& tag) {
- SyncRegistrationPtr registration = SyncRegistration::New();
- registration->tag = tag;
- return registration.Pass();
-}
-
class WorkerActivatedObserver
: public ServiceWorkerContextObserver,
public base::RefCountedThreadSafe<WorkerActivatedObserver> {
@@ -540,37 +534,6 @@ class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest {
ASSERT_EQ(expected_status, status);
}
- base::string16 RunSyncTestWithConsoleOutput(
- const std::string& worker_url,
- ServiceWorkerStatusCode expected_status) {
- RunOnIOThread(
- base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url));
- return SyncOnRegisteredWorkerWithConsoleOutput(expected_status);
- }
-
- void SyncOnRegisteredWorker(ServiceWorkerStatusCode expected_status) {
- 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(expected_status, status);
- }
-
- base::string16 SyncOnRegisteredWorkerWithConsoleOutput(
- ServiceWorkerStatusCode expected_status) {
- ConsoleListener console_listener;
- version_->embedded_worker()->AddListener(&console_listener);
-
- SyncOnRegisteredWorker(expected_status);
-
- console_listener.WaitForConsoleMessages(1);
- base::string16 console_output = console_listener.messages()[0];
- version_->embedded_worker()->RemoveListener(&console_listener);
- return console_output;
- }
-
void FetchOnRegisteredWorker(
ServiceWorkerFetchEventResult* result,
ServiceWorkerResponse* response,
@@ -790,15 +753,6 @@ 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_->SetStatus(ServiceWorkerVersion::ACTIVATED);
- version_->DispatchSyncEvent(
- CreateOneShotSyncRegistration(""),
- CreateReceiver(BrowserThread::UI, done, result));
- }
-
protected:
scoped_refptr<ServiceWorkerRegistration> registration_;
scoped_refptr<ServiceWorkerVersion> version_;
@@ -1117,84 +1071,6 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
ASSERT_FALSE(blob_data_handle);
}
-IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, SyncEventHandled) {
- RunOnIOThread(base::Bind(
- &self::SetUpRegistrationOnIOThread, this, "/service_worker/sync.js"));
- ServiceWorkerFetchEventResult result;
- ServiceWorkerResponse response;
- scoped_ptr<storage::BlobDataHandle> blob_data_handle;
- // Should 404 before sync event.
- FetchOnRegisteredWorker(&result, &response, &blob_data_handle);
- 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, &blob_data_handle);
- EXPECT_EQ(200, response.status_code);
-}
-
-IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, SyncEventInterface) {
- // Verify that the fired sync event has the correct interface.
- // The js event handler will console.log the event properties.
- base::string16 console_output = RunSyncTestWithConsoleOutput(
- "/background_sync/sync_event_interface.js", SERVICE_WORKER_OK);
-
- EXPECT_FALSE(console_output.empty());
-
- // Console output is a pipe-delimited string, as:
- // <event prototype>|<typeof waitUntil>
- std::vector<base::string16> event_properties =
- base::SplitString(console_output, base::string16(1, '|'),
- base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
-
- const base::string16::size_type num_properties = 2;
- const base::string16 event_type = base::ASCIIToUTF16("SyncEvent");
- const base::string16 wait_until_type = base::ASCIIToUTF16("function");
- EXPECT_EQ(num_properties, event_properties.size());
- EXPECT_EQ(event_type, event_properties[0]);
- EXPECT_EQ(wait_until_type, event_properties[1]);
-}
-
-IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
- SyncEventWaitUntil_Fulfilled) {
- base::string16 console_output = RunSyncTestWithConsoleOutput(
- "/background_sync/sync_event_fulfilled.js", SERVICE_WORKER_OK);
-
- // Verify that the event.waitUntil function resolved the promise. If so,
- // the js event handler will console.log the expected output.
- const base::string16 expected = base::ASCIIToUTF16("Fulfilling onsync event");
- EXPECT_EQ(expected, console_output);
-}
-
-// https://crbug.com/504202
-#if defined(THREAD_SANITIZER)
-#define MAYBE_SyncEventWaitUntil_Rejected DISABLED_SyncEventWaitUntil_Rejected
-#else
-#define MAYBE_SyncEventWaitUntil_Rejected SyncEventWaitUntil_Rejected
-#endif
-IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
- MAYBE_SyncEventWaitUntil_Rejected) {
- base::string16 console_output = RunSyncTestWithConsoleOutput(
- "/background_sync/sync_event_rejected.js",
- SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED);
-
- // Verify that the event.waitUntil function rejected the promise. If so,
- // the js event handler will console.log the expected output.
- const base::string16 expected = base::ASCIIToUTF16("Rejecting onsync event");
- EXPECT_EQ(expected, console_output);
-}
-
IN_PROC_BROWSER_TEST_F(ServiceWorkerBrowserTest, Reload) {
const char kPageUrl[] = "/service_worker/reload.html";
const char kWorkerUrl[] = "/service_worker/fetch_event_reload.js";

Powered by Google App Engine
This is Rietveld 408576698