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

Unified Diff: chrome/browser/services/gcm/gcm_driver_unittest.cc

Issue 286213003: Make GCMProfileService own GCMDriver, instead of deriving from it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync Created 6 years, 7 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 | « chrome/browser/services/gcm/gcm_driver.cc ('k') | chrome/browser/services/gcm/gcm_profile_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/services/gcm/gcm_driver_unittest.cc
diff --git a/chrome/browser/services/gcm/gcm_driver_unittest.cc b/chrome/browser/services/gcm/gcm_driver_unittest.cc
index 3d220797532e811fdc7eff7782e1884ac9bd1110..9d272c3714b7867b14bec07213afceddc8e356bb 100644
--- a/chrome/browser/services/gcm/gcm_driver_unittest.cc
+++ b/chrome/browser/services/gcm/gcm_driver_unittest.cc
@@ -101,29 +101,6 @@ class FakeGCMAppHandler : public GCMAppHandler {
DISALLOW_COPY_AND_ASSIGN(FakeGCMAppHandler);
};
-class TestGCMDriver : public GCMDriver {
- public:
- TestGCMDriver(
- bool start_automatically,
- scoped_ptr<IdentityProvider> identity_provider,
- const scoped_refptr<net::URLRequestContextGetter>& request_context);
- virtual ~TestGCMDriver();
-
- protected:
- // GCMDriver:
- virtual bool ShouldStartAutomatically() const OVERRIDE;
- virtual base::FilePath GetStorePath() const OVERRIDE;
- virtual scoped_refptr<net::URLRequestContextGetter>
- GetURLRequestContextGetter() const OVERRIDE;
-
- private:
- base::ScopedTempDir temp_dir_;
- scoped_refptr<net::URLRequestContextGetter> request_context_;
- const bool start_automatically_;
-
- DISALLOW_COPY_AND_ASSIGN(TestGCMDriver);
-};
-
FakeGCMAppHandler::FakeGCMAppHandler() : received_event_(NO_EVENT) {
}
@@ -175,33 +152,6 @@ void FakeGCMAppHandler::ClearResults() {
send_error_details_ = GCMClient::SendErrorDetails();
}
-TestGCMDriver::TestGCMDriver(
- bool start_automatically,
- scoped_ptr<IdentityProvider> identity_provider,
- const scoped_refptr<net::URLRequestContextGetter>& request_context)
- : GCMDriver(identity_provider.Pass()),
- request_context_(request_context),
- start_automatically_(start_automatically) {
- if (!temp_dir_.CreateUniqueTempDir())
- ADD_FAILURE();
-}
-
-TestGCMDriver::~TestGCMDriver() {
-}
-
-bool TestGCMDriver::ShouldStartAutomatically() const {
- return start_automatically_;
-}
-
-base::FilePath TestGCMDriver::GetStorePath() const {
- return temp_dir_.path();
-}
-
-scoped_refptr<net::URLRequestContextGetter>
-TestGCMDriver::GetURLRequestContextGetter() const {
- return request_context_;
-}
-
} // namespace
class GCMDriverTest : public testing::Test {
@@ -218,7 +168,7 @@ class GCMDriverTest : public testing::Test {
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
- TestGCMDriver* driver() { return driver_.get(); }
+ GCMDriver* driver() { return driver_.get(); }
FakeGCMAppHandler* gcm_app_handler() { return gcm_app_handler_.get(); }
const std::string& registration_id() const { return registration_id_; }
GCMClient::Result registration_result() const { return registration_result_; }
@@ -228,14 +178,12 @@ class GCMDriverTest : public testing::Test {
return unregistration_result_;
}
- void ClearRegistrationResult();
- void ClearUnregistrationResult();
+ void ClearResults();
bool HasAppHandlers() const;
FakeGCMClient* GetGCMClient();
- void CreateDriver(bool start_automatically,
- FakeGCMClient::StartMode gcm_client_start_mode);
+ void CreateDriver(FakeGCMClient::StartMode gcm_client_start_mode);
void SignIn(const std::string& account_id);
void SignOut();
@@ -258,10 +206,11 @@ class GCMDriverTest : public testing::Test {
void UnregisterCompleted(GCMClient::Result result);
scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_;
+ base::ScopedTempDir temp_dir_;
FakeOAuth2TokenService token_service_;
scoped_ptr<FakeIdentityProvider> identity_provider_owner_;
FakeIdentityProvider* identity_provider_;
- scoped_ptr<TestGCMDriver> driver_;
+ scoped_ptr<GCMDriver> driver_;
scoped_ptr<FakeGCMAppHandler> gcm_app_handler_;
base::Closure async_operation_completed_callback_;
@@ -290,23 +239,25 @@ GCMDriverTest::~GCMDriverTest() {
void GCMDriverTest::SetUp() {
thread_bundle_.reset(new content::TestBrowserThreadBundle(
content::TestBrowserThreadBundle::REAL_IO_THREAD));
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
}
void GCMDriverTest::TearDown() {
if (!driver_)
return;
- driver_->ShutdownService();
+ driver_->Shutdown();
driver_.reset();
PumpIOLoop();
}
-void GCMDriverTest::ClearRegistrationResult() {
+void GCMDriverTest::ClearResults() {
registration_id_.clear();
registration_result_ = GCMClient::UNKNOWN_ERROR;
-}
-void GCMDriverTest::ClearUnregistrationResult() {
+ send_message_id_.clear();
+ send_result_ = GCMClient::UNKNOWN_ERROR;
+
unregistration_result_ = GCMClient::UNKNOWN_ERROR;
}
@@ -319,18 +270,17 @@ FakeGCMClient* GCMDriverTest::GetGCMClient() {
}
void GCMDriverTest::CreateDriver(
- bool start_automatically,
FakeGCMClient::StartMode gcm_client_start_mode) {
scoped_refptr<net::URLRequestContextGetter> request_context =
new net::TestURLRequestContextGetter(
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::IO));
- driver_.reset(new TestGCMDriver(
- start_automatically,
+ driver_.reset(new GCMDriver(
+ scoped_ptr<GCMClientFactory>(new FakeGCMClientFactory(
+ gcm_client_start_mode)).Pass(),
identity_provider_owner_.PassAs<IdentityProvider>(),
+ temp_dir_.path(),
request_context));
- driver_->Initialize(scoped_ptr<GCMClientFactory>(
- new FakeGCMClientFactory(gcm_client_start_mode)));
gcm_app_handler_.reset(new FakeGCMAppHandler);
driver_->AddAppHandler(kTestAppID1, gcm_app_handler_.get());
@@ -419,7 +369,7 @@ void GCMDriverTest::UnregisterCompleted(GCMClient::Result result) {
TEST_F(GCMDriverTest, CreateGCMDriverBeforeSignIn) {
// Create CreateGMCService first.
- CreateDriver(true, FakeGCMClient::NO_DELAY_START);
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
EXPECT_FALSE(driver()->IsStarted());
// Sign in. This will kick off the check-in.
@@ -432,20 +382,20 @@ TEST_F(GCMDriverTest, CreateGCMDriverAfterSignIn) {
SignIn(kTestAccountID1);
// Create GCMeService after sign-in.
- CreateDriver(true, FakeGCMClient::NO_DELAY_START);
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
EXPECT_TRUE(driver()->IsStarted());
}
TEST_F(GCMDriverTest, Shutdown) {
- CreateDriver(true, FakeGCMClient::NO_DELAY_START);
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
EXPECT_TRUE(HasAppHandlers());
- driver()->ShutdownService();
+ driver()->Shutdown();
EXPECT_FALSE(HasAppHandlers());
}
TEST_F(GCMDriverTest, SignInAndSignOutUnderPositiveChannelSignal) {
- CreateDriver(true, FakeGCMClient::NO_DELAY_START);
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
SignIn(kTestAccountID1);
// GCMClient should be loaded.
@@ -459,25 +409,8 @@ TEST_F(GCMDriverTest, SignInAndSignOutUnderPositiveChannelSignal) {
EXPECT_EQ(FakeGCMClient::CHECKED_OUT, GetGCMClient()->status());
}
-TEST_F(GCMDriverTest, SignInAndSignOutUnderNonPositiveChannelSignal) {
- // Non-positive channel signal will prevent GCMClient from checking in during
- // sign-in.
- CreateDriver(false, FakeGCMClient::NO_DELAY_START);
- SignIn(kTestAccountID1);
-
- // GCMClient should not be loaded.
- EXPECT_FALSE(driver()->IsGCMClientReady());
- EXPECT_EQ(FakeGCMClient::UNINITIALIZED, GetGCMClient()->status());
-
- SignOut();
-
- // Check-out should still be performed.
- EXPECT_FALSE(driver()->IsGCMClientReady());
- EXPECT_EQ(FakeGCMClient::CHECKED_OUT, GetGCMClient()->status());
-}
-
TEST_F(GCMDriverTest, SignOutAndThenSignIn) {
- CreateDriver(true, FakeGCMClient::NO_DELAY_START);
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
SignIn(kTestAccountID1);
// GCMClient should be loaded.
@@ -498,16 +431,16 @@ TEST_F(GCMDriverTest, SignOutAndThenSignIn) {
EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status());
}
-TEST_F(GCMDriverTest, StopAndRestartGCM) {
- CreateDriver(true, FakeGCMClient::NO_DELAY_START);
+TEST_F(GCMDriverTest, DisableAndReenableGCM) {
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
SignIn(kTestAccountID1);
- // GCMClient should be loaded.
+ // GCMClient should be started.
EXPECT_TRUE(driver()->IsGCMClientReady());
EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status());
- // Stops the GCM.
- driver()->Stop();
+ // Disables the GCM.
+ driver()->Disable();
PumpIOLoop();
PumpUILoop();
@@ -515,17 +448,17 @@ TEST_F(GCMDriverTest, StopAndRestartGCM) {
EXPECT_FALSE(driver()->IsGCMClientReady());
EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status());
- // Restarts the GCM.
- driver()->Start();
+ // Enables the GCM.
+ driver()->Enable();
PumpIOLoop();
PumpUILoop();
- // GCMClient should be loaded.
+ // GCMClient should be started.
EXPECT_TRUE(driver()->IsGCMClientReady());
EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status());
- // Stops the GCM.
- driver()->Stop();
+ // Disables the GCM.
+ driver()->Disable();
PumpIOLoop();
PumpUILoop();
@@ -541,83 +474,68 @@ TEST_F(GCMDriverTest, StopAndRestartGCM) {
EXPECT_EQ(FakeGCMClient::CHECKED_OUT, GetGCMClient()->status());
}
-TEST_F(GCMDriverTest, RegisterWhenNotSignedIn) {
- CreateDriver(true, FakeGCMClient::NO_DELAY_START);
-
- std::vector<std::string> sender_ids;
- sender_ids.push_back("sender1");
- Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT);
-
- EXPECT_TRUE(registration_id().empty());
- EXPECT_EQ(GCMClient::NOT_SIGNED_IN, registration_result());
-}
-
-TEST_F(GCMDriverTest, RegisterUnderNonPositiveChannelSignal) {
- // Non-positive channel signal will prevent GCMClient from checking in during
- // sign-in.
- CreateDriver(false, FakeGCMClient::NO_DELAY_START);
- SignIn(kTestAccountID1);
-
- // GCMClient should not be checked in.
- EXPECT_FALSE(driver()->IsGCMClientReady());
- EXPECT_EQ(FakeGCMClient::UNINITIALIZED, GetGCMClient()->status());
-
- // Invoking register will make GCMClient checked in.
- std::vector<std::string> sender_ids;
- sender_ids.push_back("sender1");
- Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT);
-
- // GCMClient should be checked in.
- EXPECT_TRUE(driver()->IsGCMClientReady());
- EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status());
-
- // Registration should succeed.
- const std::string expected_registration_id =
- FakeGCMClient::GetRegistrationIdFromSenderIds(sender_ids);
- EXPECT_EQ(expected_registration_id, registration_id());
- EXPECT_EQ(GCMClient::SUCCESS, registration_result());
-}
-
-TEST_F(GCMDriverTest, SendWhenNotSignedIn) {
- CreateDriver(true, FakeGCMClient::NO_DELAY_START);
-
- GCMClient::OutgoingMessage message;
- message.id = "1";
- message.data["key1"] = "value1";
- Send(kTestAppID1, kUserID1, message, GCMDriverTest::WAIT);
-
- EXPECT_TRUE(send_message_id().empty());
- EXPECT_EQ(GCMClient::NOT_SIGNED_IN, send_result());
-}
-
-TEST_F(GCMDriverTest, SendUnderNonPositiveChannelSignal) {
- // Non-positive channel signal will prevent GCMClient from checking in during
- // sign-in.
- CreateDriver(false, FakeGCMClient::NO_DELAY_START);
- SignIn(kTestAccountID1);
-
- // GCMClient should not be checked in.
- EXPECT_FALSE(driver()->IsGCMClientReady());
- EXPECT_EQ(FakeGCMClient::UNINITIALIZED, GetGCMClient()->status());
-
- // Invoking send will make GCMClient checked in.
- GCMClient::OutgoingMessage message;
- message.id = "1";
- message.data["key1"] = "value1";
- Send(kTestAppID1, kUserID1, message, GCMDriverTest::WAIT);
-
- // GCMClient should be checked in.
- EXPECT_TRUE(driver()->IsGCMClientReady());
- EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status());
-
- // Sending should succeed.
- EXPECT_EQ(message.id, send_message_id());
- EXPECT_EQ(GCMClient::SUCCESS, send_result());
+TEST_F(GCMDriverTest, RegisterFailed) {
+ std::vector<std::string> sender_ids;
+ sender_ids.push_back("sender1");
+
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
+
+ // Registration fails when GCM is disabled.
+ driver()->Disable();
+ Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT);
+ EXPECT_TRUE(registration_id().empty());
+ EXPECT_EQ(GCMClient::GCM_DISABLED, registration_result());
+
+ ClearResults();
+
+ // Registration fails when the sign-in does not occur.
+ driver()->Enable();
+ Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT);
+ EXPECT_TRUE(registration_id().empty());
+ EXPECT_EQ(GCMClient::NOT_SIGNED_IN, registration_result());
+}
+
+TEST_F(GCMDriverTest, UnregisterFailed) {
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
+
+ // Unregistration fails when GCM is disabled.
+ driver()->Disable();
+ Unregister(kTestAppID1, GCMDriverTest::WAIT);
+ EXPECT_EQ(GCMClient::GCM_DISABLED, unregistration_result());
+
+ ClearResults();
+
+ // Unregistration fails when the sign-in does not occur.
+ driver()->Enable();
+ Unregister(kTestAppID1, GCMDriverTest::WAIT);
+ EXPECT_EQ(GCMClient::NOT_SIGNED_IN, unregistration_result());
+}
+
+TEST_F(GCMDriverTest, SendFailed) {
+ GCMClient::OutgoingMessage message;
+ message.id = "1";
+ message.data["key1"] = "value1";
+
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
+
+ // Sending fails when GCM is disabled.
+ driver()->Disable();
+ Send(kTestAppID1, kUserID1, message, GCMDriverTest::WAIT);
+ EXPECT_TRUE(send_message_id().empty());
+ EXPECT_EQ(GCMClient::GCM_DISABLED, send_result());
+
+ ClearResults();
+
+ // Registration fails when the sign-in does not occur.
+ driver()->Enable();
+ Send(kTestAppID1, kUserID1, message, GCMDriverTest::WAIT);
+ EXPECT_TRUE(send_message_id().empty());
+ EXPECT_EQ(GCMClient::NOT_SIGNED_IN, send_result());
}
TEST_F(GCMDriverTest, GCMClientNotReadyBeforeRegistration) {
// Make GCMClient not ready initially.
- CreateDriver(true, FakeGCMClient::DELAY_START);
+ CreateDriver(FakeGCMClient::DELAY_START);
SignIn(kTestAccountID1);
// The registration is on hold until GCMClient is ready.
@@ -640,7 +558,7 @@ TEST_F(GCMDriverTest, GCMClientNotReadyBeforeRegistration) {
TEST_F(GCMDriverTest, GCMClientNotReadyBeforeSending) {
// Make GCMClient not ready initially.
- CreateDriver(true, FakeGCMClient::DELAY_START);
+ CreateDriver(FakeGCMClient::DELAY_START);
SignIn(kTestAccountID1);
// The sending is on hold until GCMClient is ready.
@@ -684,7 +602,7 @@ GCMDriverFunctionalTest::~GCMDriverFunctionalTest() {
void GCMDriverFunctionalTest::SetUp() {
GCMDriverTest::SetUp();
- CreateDriver(true, FakeGCMClient::NO_DELAY_START);
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
SignIn(kTestAccountID1);
}
@@ -721,7 +639,7 @@ TEST_F(GCMDriverFunctionalTest, RegisterAgainWithSameSenderIDs) {
// Clears the results the would be set by the Register callback in preparation
// to call register 2nd time.
- ClearRegistrationResult();
+ ClearResults();
// Calling register 2nd time with the same set of sender IDs but different
// ordering will get back the same registration ID.
@@ -808,7 +726,7 @@ TEST_F(GCMDriverFunctionalTest, UnregisterWhenAsyncOperationPending) {
Unregister(kTestAppID1, GCMDriverTest::WAIT);
EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING,
unregistration_result());
- ClearUnregistrationResult();
+ ClearResults();
// Complete unregistration.
WaitForAsyncOperation();
@@ -828,7 +746,7 @@ TEST_F(GCMDriverFunctionalTest, RegisterWhenAsyncOperationPending) {
Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT);
EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING,
registration_result());
- ClearRegistrationResult();
+ ClearResults();
// Complete the registration.
WaitForAsyncOperation();
« no previous file with comments | « chrome/browser/services/gcm/gcm_driver.cc ('k') | chrome/browser/services/gcm/gcm_profile_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698