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

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
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..f894740fb3b94267e9d0417dcaebfea7faf6b915 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_; }
@@ -234,8 +184,7 @@ class GCMDriverTest : public testing::Test {
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 +207,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,13 +240,14 @@ 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();
}
@@ -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.
@@ -499,7 +432,7 @@ TEST_F(GCMDriverTest, SignOutAndThenSignIn) {
}
TEST_F(GCMDriverTest, StopAndRestartGCM) {
- CreateDriver(true, FakeGCMClient::NO_DELAY_START);
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
SignIn(kTestAccountID1);
// GCMClient should be loaded.
@@ -507,7 +440,7 @@ TEST_F(GCMDriverTest, StopAndRestartGCM) {
EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status());
// Stops the GCM.
- driver()->Stop();
+ driver()->Disable();
PumpIOLoop();
PumpUILoop();
@@ -516,7 +449,7 @@ TEST_F(GCMDriverTest, StopAndRestartGCM) {
EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status());
// Restarts the GCM.
- driver()->Start();
+ driver()->Enable();
PumpIOLoop();
PumpUILoop();
@@ -525,7 +458,7 @@ TEST_F(GCMDriverTest, StopAndRestartGCM) {
EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status());
// Stops the GCM.
- driver()->Stop();
+ driver()->Disable();
PumpIOLoop();
PumpUILoop();
@@ -542,7 +475,7 @@ TEST_F(GCMDriverTest, StopAndRestartGCM) {
}
TEST_F(GCMDriverTest, RegisterWhenNotSignedIn) {
- CreateDriver(true, FakeGCMClient::NO_DELAY_START);
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
std::vector<std::string> sender_ids;
sender_ids.push_back("sender1");
@@ -552,34 +485,8 @@ TEST_F(GCMDriverTest, RegisterWhenNotSignedIn) {
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);
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
GCMClient::OutgoingMessage message;
message.id = "1";
@@ -590,34 +497,9 @@ TEST_F(GCMDriverTest, SendWhenNotSignedIn) {
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, 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 +522,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 +566,7 @@ GCMDriverFunctionalTest::~GCMDriverFunctionalTest() {
void GCMDriverFunctionalTest::SetUp() {
GCMDriverTest::SetUp();
- CreateDriver(true, FakeGCMClient::NO_DELAY_START);
+ CreateDriver(FakeGCMClient::NO_DELAY_START);
SignIn(kTestAccountID1);
}

Powered by Google App Engine
This is Rietveld 408576698