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

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

Issue 1223193009: WIP attempt to replace StartWorker/StopWorker IPCs with a new mojo EmbeddedWorker service. Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-event-dispatching-option2
Patch Set: Created 5 years, 5 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_context_unittest.cc
diff --git a/content/browser/service_worker/service_worker_context_unittest.cc b/content/browser/service_worker/service_worker_context_unittest.cc
index d299a2e3ba82856595694b2d966906b4f964bd19..4e6f154e298a465da676ea1a24e99a1015dceeb4 100644
--- a/content/browser/service_worker/service_worker_context_unittest.cc
+++ b/content/browser/service_worker/service_worker_context_unittest.cc
@@ -26,20 +26,20 @@ namespace content {
namespace {
-void SaveResponseCallback(bool* called,
+void SaveResponseCallback(const scoped_refptr<MessageLoopRunner>& runner,
int64* store_registration_id,
ServiceWorkerStatusCode status,
const std::string& status_message,
int64 registration_id) {
EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status);
- *called = true;
*store_registration_id = registration_id;
+ runner->Quit();
}
ServiceWorkerContextCore::RegistrationCallback MakeRegisteredCallback(
- bool* called,
+ const scoped_refptr<MessageLoopRunner>& runner,
int64* store_registration_id) {
- return base::Bind(&SaveResponseCallback, called, store_registration_id);
+ return base::Bind(&SaveResponseCallback, runner, store_registration_id);
}
void CallCompletedCallback(bool* called, ServiceWorkerStatusCode) {
@@ -78,8 +78,7 @@ void ExpectRegisteredWorkers(
class RejectInstallTestHelper : public EmbeddedWorkerTestHelper {
public:
- explicit RejectInstallTestHelper(int mock_render_process_id)
- : EmbeddedWorkerTestHelper(base::FilePath(), mock_render_process_id) {}
+ RejectInstallTestHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {}
void OnInstallEvent(int embedded_worker_id,
int request_id) override {
@@ -92,8 +91,8 @@ class RejectInstallTestHelper : public EmbeddedWorkerTestHelper {
class RejectActivateTestHelper : public EmbeddedWorkerTestHelper {
public:
- explicit RejectActivateTestHelper(int mock_render_process_id)
- : EmbeddedWorkerTestHelper(base::FilePath(), mock_render_process_id) {}
+ explicit RejectActivateTestHelper()
+ : EmbeddedWorkerTestHelper(base::FilePath()) {}
void OnActivateEvent(int embedded_worker_id, int request_id) override {
SimulateSend(
@@ -121,12 +120,10 @@ class ServiceWorkerContextTest : public ServiceWorkerContextObserver,
public testing::Test {
public:
ServiceWorkerContextTest()
- : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
- render_process_id_(99) {}
+ : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
void SetUp() override {
- helper_.reset(
- new EmbeddedWorkerTestHelper(base::FilePath(), render_process_id_));
+ helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath()));
helper_->context_wrapper()->AddObserver(this);
}
@@ -160,7 +157,6 @@ class ServiceWorkerContextTest : public ServiceWorkerContextObserver,
protected:
TestBrowserThreadBundle browser_thread_bundle_;
scoped_ptr<EmbeddedWorkerTestHelper> helper_;
- const int render_process_id_;
std::vector<NotificationLog> notifications_;
};
@@ -170,26 +166,18 @@ TEST_F(ServiceWorkerContextTest, Register) {
GURL script_url("http://www.example.com/service_worker.js");
int64 registration_id = kInvalidServiceWorkerRegistrationId;
- bool called = false;
+ scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner);
context()->RegisterServiceWorker(
- pattern,
- script_url,
- NULL,
- MakeRegisteredCallback(&called, &registration_id));
+ pattern, script_url, NULL,
+ MakeRegisteredCallback(runner, &registration_id));
- ASSERT_FALSE(called);
- base::RunLoop().RunUntilIdle();
- EXPECT_TRUE(called);
+ runner->Run();
- EXPECT_EQ(4UL, helper_->ipc_sink()->message_count());
- EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
- EmbeddedWorkerMsg_StartWorker::ID));
+ EXPECT_EQ(2UL, helper_->ipc_sink()->message_count());
EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
ServiceWorkerMsg_InstallEvent::ID));
EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
ServiceWorkerMsg_ActivateEvent::ID));
- EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
- EmbeddedWorkerMsg_StopWorker::ID));
EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
ASSERT_EQ(1u, notifications_.size());
@@ -215,29 +203,21 @@ TEST_F(ServiceWorkerContextTest, Register_RejectInstall) {
GURL script_url("http://www.example.com/service_worker.js");
helper_.reset(); // Make sure the process lookups stay overridden.
- helper_.reset(new RejectInstallTestHelper(render_process_id_));
+ helper_.reset(new RejectInstallTestHelper());
helper_->context_wrapper()->AddObserver(this);
int64 registration_id = kInvalidServiceWorkerRegistrationId;
- bool called = false;
+ scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner);
context()->RegisterServiceWorker(
- pattern,
- script_url,
- NULL,
- MakeRegisteredCallback(&called, &registration_id));
+ pattern, script_url, NULL,
+ MakeRegisteredCallback(runner, &registration_id));
- ASSERT_FALSE(called);
- base::RunLoop().RunUntilIdle();
- EXPECT_TRUE(called);
+ runner->Run();
- EXPECT_EQ(3UL, helper_->ipc_sink()->message_count());
- EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
- EmbeddedWorkerMsg_StartWorker::ID));
+ EXPECT_EQ(1UL, helper_->ipc_sink()->message_count());
EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
ServiceWorkerMsg_InstallEvent::ID));
EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
ServiceWorkerMsg_ActivateEvent::ID));
- EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
- EmbeddedWorkerMsg_StopWorker::ID));
EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
ASSERT_EQ(1u, notifications_.size());
@@ -262,27 +242,21 @@ TEST_F(ServiceWorkerContextTest, Register_RejectActivate) {
GURL script_url("http://www.example.com/service_worker.js");
helper_.reset();
- helper_.reset(new RejectActivateTestHelper(render_process_id_));
+ helper_.reset(new RejectActivateTestHelper());
helper_->context_wrapper()->AddObserver(this);
int64 registration_id = kInvalidServiceWorkerRegistrationId;
- bool called = false;
+ scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner);
context()->RegisterServiceWorker(
pattern, script_url, NULL,
- MakeRegisteredCallback(&called, &registration_id));
+ MakeRegisteredCallback(runner, &registration_id));
- ASSERT_FALSE(called);
- base::RunLoop().RunUntilIdle();
- EXPECT_TRUE(called);
+ runner->Run();
- EXPECT_EQ(4UL, helper_->ipc_sink()->message_count());
- EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
- EmbeddedWorkerMsg_StartWorker::ID));
+ EXPECT_EQ(2UL, helper_->ipc_sink()->message_count());
EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
ServiceWorkerMsg_InstallEvent::ID));
EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
ServiceWorkerMsg_ActivateEvent::ID));
- EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
- EmbeddedWorkerMsg_StopWorker::ID));
EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
ASSERT_EQ(1u, notifications_.size());
@@ -301,20 +275,16 @@ TEST_F(ServiceWorkerContextTest, Register_RejectActivate) {
TEST_F(ServiceWorkerContextTest, Unregister) {
GURL pattern("http://www.example.com/");
- bool called = false;
+ scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner);
int64 registration_id = kInvalidServiceWorkerRegistrationId;
context()->RegisterServiceWorker(
- pattern,
- GURL("http://www.example.com/service_worker.js"),
- NULL,
- MakeRegisteredCallback(&called, &registration_id));
+ pattern, GURL("http://www.example.com/service_worker.js"), NULL,
+ MakeRegisteredCallback(runner, &registration_id));
- ASSERT_FALSE(called);
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(called);
+ runner->Run();
EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
- called = false;
+ bool called = false;
context()->UnregisterServiceWorker(pattern,
MakeUnregisteredCallback(&called));
@@ -347,42 +317,38 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) {
GURL origin2_p1("http://www.example.com:8080/again");
GURL origin3_p1("http://www.other.com/");
- bool called = false;
+ scoped_refptr<MessageLoopRunner> runner1(new MessageLoopRunner);
+ scoped_refptr<MessageLoopRunner> runner2(new MessageLoopRunner);
+ scoped_refptr<MessageLoopRunner> runner3(new MessageLoopRunner);
+ scoped_refptr<MessageLoopRunner> runner4(new MessageLoopRunner);
int64 registration_id1 = kInvalidServiceWorkerRegistrationId;
int64 registration_id2 = kInvalidServiceWorkerRegistrationId;
int64 registration_id3 = kInvalidServiceWorkerRegistrationId;
int64 registration_id4 = kInvalidServiceWorkerRegistrationId;
context()->RegisterServiceWorker(
- origin1_p1,
- GURL("http://www.example.com/service_worker.js"),
- NULL,
- MakeRegisteredCallback(&called, &registration_id1));
+ origin1_p1, GURL("http://www.example.com/service_worker.js"), NULL,
+ MakeRegisteredCallback(runner1, &registration_id1));
context()->RegisterServiceWorker(
- origin1_p2,
- GURL("http://www.example.com/service_worker2.js"),
- NULL,
- MakeRegisteredCallback(&called, &registration_id2));
+ origin1_p2, GURL("http://www.example.com/service_worker2.js"), NULL,
+ MakeRegisteredCallback(runner2, &registration_id2));
context()->RegisterServiceWorker(
- origin2_p1,
- GURL("http://www.example.com:8080/service_worker3.js"),
- NULL,
- MakeRegisteredCallback(&called, &registration_id3));
+ origin2_p1, GURL("http://www.example.com:8080/service_worker3.js"), NULL,
+ MakeRegisteredCallback(runner3, &registration_id3));
context()->RegisterServiceWorker(
- origin3_p1,
- GURL("http://www.other.com/service_worker4.js"),
- NULL,
- MakeRegisteredCallback(&called, &registration_id4));
+ origin3_p1, GURL("http://www.other.com/service_worker4.js"), NULL,
+ MakeRegisteredCallback(runner4, &registration_id4));
- ASSERT_FALSE(called);
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(called);
+ runner1->Run();
+ runner2->Run();
+ runner3->Run();
+ runner4->Run();
EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id1);
EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id2);
EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id3);
EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id4);
- called = false;
+ bool called = false;
context()->UnregisterServiceWorkers(origin1_p1.GetOrigin(),
MakeUnregisteredCallback(&called));
@@ -447,30 +413,22 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) {
TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
GURL pattern("http://www.example.com/");
- bool called = false;
+ scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner);
int64 old_registration_id = kInvalidServiceWorkerRegistrationId;
context()->RegisterServiceWorker(
- pattern,
- GURL("http://www.example.com/service_worker.js"),
- NULL,
- MakeRegisteredCallback(&called, &old_registration_id));
+ pattern, GURL("http://www.example.com/service_worker.js"), NULL,
+ MakeRegisteredCallback(runner, &old_registration_id));
- ASSERT_FALSE(called);
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(called);
+ runner->Run();
EXPECT_NE(kInvalidServiceWorkerRegistrationId, old_registration_id);
- called = false;
+ runner = new MessageLoopRunner;
int64 new_registration_id = kInvalidServiceWorkerRegistrationId;
context()->RegisterServiceWorker(
- pattern,
- GURL("http://www.example.com/service_worker_new.js"),
- NULL,
- MakeRegisteredCallback(&called, &new_registration_id));
+ pattern, GURL("http://www.example.com/service_worker_new.js"), NULL,
+ MakeRegisteredCallback(runner, &new_registration_id));
- ASSERT_FALSE(called);
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(called);
+ runner->Run();
EXPECT_NE(kInvalidServiceWorkerRegistrationId, new_registration_id);
EXPECT_EQ(old_registration_id, new_registration_id);
@@ -490,30 +448,22 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
GURL pattern("http://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js");
- bool called = false;
+ scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner);
int64 old_registration_id = kInvalidServiceWorkerRegistrationId;
context()->RegisterServiceWorker(
- pattern,
- script_url,
- NULL,
- MakeRegisteredCallback(&called, &old_registration_id));
+ pattern, script_url, NULL,
+ MakeRegisteredCallback(runner, &old_registration_id));
- ASSERT_FALSE(called);
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(called);
+ runner->Run();
EXPECT_NE(kInvalidServiceWorkerRegistrationId, old_registration_id);
- called = false;
+ runner = new MessageLoopRunner;
int64 new_registration_id = kInvalidServiceWorkerRegistrationId;
context()->RegisterServiceWorker(
- pattern,
- script_url,
- NULL,
- MakeRegisteredCallback(&called, &new_registration_id));
+ pattern, script_url, NULL,
+ MakeRegisteredCallback(runner, &new_registration_id));
- ASSERT_FALSE(called);
- base::RunLoop().RunUntilIdle();
- ASSERT_TRUE(called);
+ runner->Run();
EXPECT_EQ(old_registration_id, new_registration_id);
ASSERT_EQ(2u, notifications_.size());
@@ -620,22 +570,17 @@ TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) {
// Reinitialize the helper to test on-disk storage.
base::ScopedTempDir user_data_directory;
ASSERT_TRUE(user_data_directory.CreateUniqueTempDir());
- helper_.reset(new EmbeddedWorkerTestHelper(user_data_directory.path(),
- render_process_id_));
+ helper_.reset(new EmbeddedWorkerTestHelper(user_data_directory.path()));
helper_->context_wrapper()->AddObserver(this);
}
int64 registration_id = kInvalidServiceWorkerRegistrationId;
- bool called = false;
+ scoped_refptr<MessageLoopRunner> runner(new MessageLoopRunner);
context()->RegisterServiceWorker(
- pattern,
- script_url,
- NULL,
- MakeRegisteredCallback(&called, &registration_id));
+ pattern, script_url, NULL,
+ MakeRegisteredCallback(runner, &registration_id));
- ASSERT_FALSE(called);
- base::RunLoop().RunUntilIdle();
- EXPECT_TRUE(called);
+ runner->Run();
context()->storage()->FindRegistrationForId(
registration_id,
@@ -674,16 +619,12 @@ TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) {
true /* expect_active */));
base::RunLoop().RunUntilIdle();
- called = false;
+ runner = new MessageLoopRunner;
context()->RegisterServiceWorker(
- pattern,
- script_url,
- NULL,
- MakeRegisteredCallback(&called, &registration_id));
+ pattern, script_url, NULL,
+ MakeRegisteredCallback(runner, &registration_id));
- ASSERT_FALSE(called);
- base::RunLoop().RunUntilIdle();
- EXPECT_TRUE(called);
+ runner->Run();
context()->storage()->FindRegistrationForId(
registration_id,

Powered by Google App Engine
This is Rietveld 408576698