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

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

Issue 2432083002: Mojofy unittests: ServiceWorkerContextTest (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6c72fab2cab200307246278801a3f93195f486b2..093d88ff493734787b5205ced5aa8ef1ccb8f612 100644
--- a/content/browser/service_worker/service_worker_context_unittest.cc
+++ b/content/browser/service_worker/service_worker_context_unittest.cc
@@ -20,6 +20,7 @@
#include "content/browser/service_worker/service_worker_provider_host.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/browser/service_worker/service_worker_storage.h"
+#include "content/browser/service_worker/service_worker_test_utils.h"
#include "content/common/service_worker/embedded_worker_messages.h"
#include "content/common/service_worker/service_worker_messages.h"
#include "content/public/test/test_browser_thread_bundle.h"
@@ -161,8 +162,11 @@ class ServiceWorkerContextTest : public ServiceWorkerContextObserver,
std::vector<NotificationLog> notifications_;
};
+class ServiceWorkerContextTestP
+ : public MojoServiceWorkerTestP<ServiceWorkerContextTest> {};
+
// Make sure basic registration is working.
-TEST_F(ServiceWorkerContextTest, Register) {
+TEST_P(ServiceWorkerContextTestP, Register) {
GURL pattern("http://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js");
@@ -178,15 +182,23 @@ TEST_F(ServiceWorkerContextTest, Register) {
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called);
- EXPECT_EQ(4UL, helper_->ipc_sink()->message_count());
- EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
- EmbeddedWorkerMsg_StartWorker::ID));
- 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));
+ if (is_mojo_enabled()) {
+ EXPECT_EQ(2UL, helper_->ipc_sink()->message_count());
horo 2016/10/19 04:50:09 Please check this using CreateAndRegisterMockInsta
shimazu 2016/10/20 05:08:45 Done.
+ EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
+ ServiceWorkerMsg_InstallEvent::ID));
+ EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
+ ServiceWorkerMsg_ActivateEvent::ID));
+ } else {
+ EXPECT_EQ(4UL, helper_->ipc_sink()->message_count());
+ EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
+ EmbeddedWorkerMsg_StartWorker::ID));
+ 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());
@@ -207,7 +219,7 @@ TEST_F(ServiceWorkerContextTest, Register) {
// Test registration when the service worker rejects the install event. The
// registration callback should indicate success, but there should be no waiting
// or active worker in the registration.
-TEST_F(ServiceWorkerContextTest, Register_RejectInstall) {
+TEST_P(ServiceWorkerContextTestP, Register_RejectInstall) {
GURL pattern("http://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js");
@@ -226,15 +238,22 @@ TEST_F(ServiceWorkerContextTest, Register_RejectInstall) {
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called);
- EXPECT_EQ(3UL, helper_->ipc_sink()->message_count());
- EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
- EmbeddedWorkerMsg_StartWorker::ID));
- 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));
+ if (is_mojo_enabled()) {
+ EXPECT_EQ(1UL, helper_->ipc_sink()->message_count());
horo 2016/10/19 04:50:09 ditto
shimazu 2016/10/20 05:08:45 Done.
+ EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
+ ServiceWorkerMsg_InstallEvent::ID));
+ // ActivateEvent shouldn't be recorded.
+ } else {
+ EXPECT_EQ(3UL, helper_->ipc_sink()->message_count());
+ EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
+ EmbeddedWorkerMsg_StartWorker::ID));
+ 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());
@@ -254,7 +273,7 @@ TEST_F(ServiceWorkerContextTest, Register_RejectInstall) {
// Test registration when the service worker rejects the activate event. The
// worker should be activated anyway.
-TEST_F(ServiceWorkerContextTest, Register_RejectActivate) {
+TEST_P(ServiceWorkerContextTestP, Register_RejectActivate) {
GURL pattern("http://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js");
@@ -271,15 +290,23 @@ TEST_F(ServiceWorkerContextTest, Register_RejectActivate) {
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called);
- EXPECT_EQ(4UL, helper_->ipc_sink()->message_count());
- EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
- EmbeddedWorkerMsg_StartWorker::ID));
- 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));
+ if (is_mojo_enabled()) {
+ EXPECT_EQ(2UL, helper_->ipc_sink()->message_count());
horo 2016/10/19 04:50:09 ditto
shimazu 2016/10/20 05:08:45 Done.
+ EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
+ ServiceWorkerMsg_InstallEvent::ID));
+ EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
+ ServiceWorkerMsg_ActivateEvent::ID));
+ } else {
+ EXPECT_EQ(4UL, helper_->ipc_sink()->message_count());
+ EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
+ EmbeddedWorkerMsg_StartWorker::ID));
+ 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());
@@ -295,7 +322,7 @@ TEST_F(ServiceWorkerContextTest, Register_RejectActivate) {
}
// Make sure registrations are cleaned up when they are unregistered.
-TEST_F(ServiceWorkerContextTest, Unregister) {
+TEST_P(ServiceWorkerContextTestP, Unregister) {
GURL pattern("http://www.example.com/");
bool called = false;
@@ -338,7 +365,7 @@ TEST_F(ServiceWorkerContextTest, Unregister) {
}
// Make sure registrations are cleaned up when they are unregistered in bulk.
-TEST_F(ServiceWorkerContextTest, UnregisterMultiple) {
+TEST_P(ServiceWorkerContextTestP, UnregisterMultiple) {
GURL origin1_p1("http://www.example.com/test");
GURL origin1_p2("http://www.example.com/hello");
GURL origin2_p1("http://www.example.com:8080/again");
@@ -441,7 +468,7 @@ TEST_F(ServiceWorkerContextTest, UnregisterMultiple) {
}
// Make sure registering a new script shares an existing registration.
-TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
+TEST_P(ServiceWorkerContextTestP, RegisterNewScript) {
GURL pattern("http://www.example.com/");
bool called = false;
@@ -483,7 +510,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
// Make sure that when registering a duplicate pattern+script_url
// combination, that the same registration is used.
-TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
+TEST_P(ServiceWorkerContextTestP, RegisterDuplicateScript) {
GURL pattern("http://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js");
@@ -522,7 +549,7 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
EXPECT_EQ(old_registration_id, notifications_[1].registration_id);
}
-TEST_F(ServiceWorkerContextTest, ProviderHostIterator) {
+TEST_P(ServiceWorkerContextTestP, ProviderHostIterator) {
const int kRenderProcessId1 = 1;
const int kRenderProcessId2 = 2;
const GURL kOrigin1 = GURL("http://www.example.com/");
@@ -606,22 +633,29 @@ TEST_F(ServiceWorkerContextTest, ProviderHostIterator) {
class ServiceWorkerContextRecoveryTest
: public ServiceWorkerContextTest,
- public testing::WithParamInterface<bool> {
+ public testing::WithParamInterface<testing::tuple<bool, bool>> {
public:
ServiceWorkerContextRecoveryTest() {}
virtual ~ServiceWorkerContextRecoveryTest() {}
-};
-INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest,
- ServiceWorkerContextRecoveryTest,
- testing::Values(true, false));
+ protected:
+ void SetUp() override {
+ if (is_mojo_enabled()) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kMojoServiceWorker);
+ }
+ ServiceWorkerContextTest::SetUp();
+ }
+
+ bool is_mojo_enabled() const { return testing::get<0>(GetParam()); }
+ bool is_storage_on_disk() const { return testing::get<1>(GetParam()); }
+};
TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) {
GURL pattern("http://www.example.com/");
GURL script_url("http://www.example.com/service_worker.js");
- bool is_storage_on_disk = GetParam();
- if (is_storage_on_disk) {
+ if (is_storage_on_disk()) {
// Reinitialize the helper to test on-disk storage.
base::ScopedTempDir user_data_directory;
ASSERT_TRUE(user_data_directory.CreateUniqueTempDir());
@@ -709,5 +743,12 @@ TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) {
EXPECT_EQ(registration_id, notifications_[2].registration_id);
}
+INSTANTIATE_TEST_CASE_P(ServiceWorkerContextTest,
+ ServiceWorkerContextTestP,
+ testing::Bool());
+
+INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest,
+ ServiceWorkerContextRecoveryTest,
+ testing::Combine(testing::Bool(), testing::Bool()));
} // namespace content
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698