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

Unified Diff: components/gcm_driver/gcm_profile_service_unittest.cc

Issue 1464463004: Componentize Unit Test for gcm_profile_service Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Created 5 years 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 | « components/gcm_driver/gcm_profile_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/gcm_driver/gcm_profile_service_unittest.cc
diff --git a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc b/components/gcm_driver/gcm_profile_service_unittest.cc
similarity index 70%
rename from chrome/browser/services/gcm/gcm_profile_service_unittest.cc
rename to components/gcm_driver/gcm_profile_service_unittest.cc
index 2ba5b185c200f9084f7798907d04e8f5ad2a98f7..1a66786bccf5af7f48ececcb592d8882668cb698 100644
--- a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc
+++ b/components/gcm_driver/gcm_profile_service_unittest.cc
@@ -10,27 +10,27 @@
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop/message_loop.h"
+#include "base/prefs/testing_pref_service.h"
#include "base/run_loop.h"
-#include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
-#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
-#include "chrome/browser/signin/signin_manager_factory.h"
-#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
-#include "chrome/common/channel_info.h"
-#include "chrome/test/base/testing_profile.h"
+#include "base/single_thread_task_runner.h"
+#include "base/test/test_simple_task_runner.h"
#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h"
#endif
#include "components/gcm_driver/fake_gcm_app_handler.h"
#include "components/gcm_driver/fake_gcm_client.h"
#include "components/gcm_driver/fake_gcm_client_factory.h"
+#include "components/gcm_driver/gcm_channel_status_syncer.h"
#include "components/gcm_driver/gcm_client.h"
#include "components/gcm_driver/gcm_client_factory.h"
#include "components/gcm_driver/gcm_driver.h"
#include "components/pref_registry/pref_registry_syncable.h"
+#include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
+#include "components/signin/core/browser/fake_signin_manager.h"
#include "components/signin/core/browser/signin_manager.h"
-#include "content/public/browser/browser_context.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/test/test_browser_thread_bundle.h"
+#include "components/signin/core/browser/test_signin_client.h"
+#include "components/signin/core/common/signin_pref_names.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gcm {
@@ -40,34 +40,6 @@ namespace {
const char kTestAppID[] = "TestApp";
const char kUserID[] = "user";
-scoped_ptr<KeyedService> BuildGCMProfileService(
- content::BrowserContext* context) {
- Profile* profile = Profile::FromBrowserContext(context);
- base::SequencedWorkerPool* worker_pool =
- content::BrowserThread::GetBlockingPool();
- scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
- worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
- worker_pool->GetSequenceToken(),
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
- return make_scoped_ptr(new gcm::GCMProfileService(
- profile->GetPrefs(), profile->GetPath(), profile->GetRequestContext(),
- chrome::GetChannel(),
- scoped_ptr<ProfileIdentityProvider>(new ProfileIdentityProvider(
- SigninManagerFactory::GetForProfile(profile),
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
- LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile))),
- scoped_ptr<gcm::GCMClientFactory>(new gcm::FakeGCMClientFactory(
- content::BrowserThread::GetMessageLoopProxyForThread(
- content::BrowserThread::UI),
- content::BrowserThread::GetMessageLoopProxyForThread(
- content::BrowserThread::IO))),
- content::BrowserThread::GetMessageLoopProxyForThread(
- content::BrowserThread::UI),
- content::BrowserThread::GetMessageLoopProxyForThread(
- content::BrowserThread::IO),
- blocking_task_runner));
-}
-
} // namespace
class GCMProfileServiceTest : public testing::Test {
@@ -106,8 +78,12 @@ class GCMProfileServiceTest : public testing::Test {
GCMClient::Result send_result() const { return send_result_; }
private:
- content::TestBrowserThreadBundle thread_bundle_;
- scoped_ptr<TestingProfile> profile_;
+ base::ScopedTempDir temp_dir_;
+ base::MessageLoop message_loop_;
+
+ TestingPrefServiceSimple prefs_;
+ scoped_ptr<FakeSigninManagerBase> signin_manager_;
+ scoped_ptr<ProfileOAuth2TokenService> fake_token_service_;
GCMProfileService* gcm_profile_service_;
scoped_ptr<FakeGCMAppHandler> gcm_app_handler_;
@@ -124,11 +100,9 @@ GCMProfileServiceTest::GCMProfileServiceTest()
: gcm_profile_service_(NULL),
gcm_app_handler_(new FakeGCMAppHandler),
registration_result_(GCMClient::UNKNOWN_ERROR),
- send_result_(GCMClient::UNKNOWN_ERROR) {
-}
+ send_result_(GCMClient::UNKNOWN_ERROR) {}
-GCMProfileServiceTest::~GCMProfileServiceTest() {
-}
+GCMProfileServiceTest::~GCMProfileServiceTest() {}
FakeGCMClient* GCMProfileServiceTest::GetGCMClient() const {
return static_cast<FakeGCMClient*>(
@@ -136,13 +110,22 @@ FakeGCMClient* GCMProfileServiceTest::GetGCMClient() const {
}
void GCMProfileServiceTest::SetUp() {
+ GCMChannelStatusSyncer::RegisterPrefs(prefs_.registry());
+
+ prefs_.registry()->RegisterListPref(AccountTrackerService::kAccountInfoPref);
+ prefs_.registry()->RegisterIntegerPref(
+ ::prefs::kAccountIdMigrationState,
+ AccountTrackerService::MIGRATION_NOT_STARTED);
droger 2015/12/17 13:23:22 These prefs may no longer be necessary, please che
Jitu( very slow this week) 2015/12/17 14:02:01 Done.
+
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ signin_manager_.reset(new FakeSigninManagerBase(nullptr, nullptr));
+ fake_token_service_.reset(new FakeProfileOAuth2TokenService());
+
#if defined(OS_CHROMEOS)
// Create a DBus thread manager setter for its side effect.
// Ignore the return value.
chromeos::DBusThreadManager::GetSetterForTesting();
#endif
- TestingProfile::Builder builder;
- profile_ = builder.Build();
}
void GCMProfileServiceTest::TearDown() {
@@ -150,12 +133,26 @@ void GCMProfileServiceTest::TearDown() {
}
void GCMProfileServiceTest::CreateGCMProfileService() {
- gcm_profile_service_ = static_cast<GCMProfileService*>(
- GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse(
- profile_.get(),
- &BuildGCMProfileService));
- gcm_profile_service_->driver()->AddAppHandler(
- kTestAppID, gcm_app_handler_.get());
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner =
+ message_loop_.task_runner();
+ net::URLRequestContextGetter* request_context =
droger 2015/12/17 13:23:22 Nit: it would be more correct to use a scoped_refp
Jitu( very slow this week) 2015/12/17 14:02:01 Done.
+ new net::TestURLRequestContextGetter(task_runner);
+ gcm_profile_service_ = new gcm::GCMProfileService(
+ &prefs_, temp_dir_.path(), request_context,
+ version_info::Channel::UNKNOWN,
+ scoped_ptr<ProfileIdentityProvider>(
+ new ProfileIdentityProvider(signin_manager_.get(),
+ fake_token_service_.get(),
+ base::Closure()))
+ .Pass(),
+ scoped_ptr<gcm::GCMClientFactory>(
+ new gcm::FakeGCMClientFactory(base::ThreadTaskRunnerHandle::Get(),
+ task_runner))
+ .Pass(),
+ base::ThreadTaskRunnerHandle::Get(), task_runner,
+ task_runner);
+ gcm_profile_service_->driver()->AddAppHandler(kTestAppID,
+ gcm_app_handler_.get());
}
void GCMProfileServiceTest::RegisterAndWaitForCompletion(
« no previous file with comments | « components/gcm_driver/gcm_profile_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698