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 72% |
rename from chrome/browser/services/gcm/gcm_profile_service_unittest.cc |
rename to components/gcm_driver/gcm_profile_service_unittest.cc |
index 2ba5b185c200f9084f7798907d04e8f5ad2a98f7..593e8af8b83105e06bfdea18f349b091fd25f1a8 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/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 "components/signin/core/browser/test_signin_client.h" |
+#include "components/signin/core/common/signin_pref_names.h" |
#include "content/public/browser/browser_thread.h" |
-#include "content/public/test/test_browser_thread_bundle.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,28 @@ 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); |
+ |
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
+ scoped_ptr<TestSigninClient> client; |
+ client.reset(new TestSigninClient(&prefs_)); |
droger
2015/12/14 13:54:34
If you do this, the client will be destroyed at th
Jitu( very slow this week)
2015/12/14 14:27:54
Done.
|
+ AccountTrackerService tracker; |
droger
2015/12/14 13:54:34
Same for AccountTrackerService, you probably need
Jitu( very slow this week)
2015/12/14 14:27:54
Done.
|
+ tracker.Initialize(client.get()); |
+ signin_manager_.reset(new FakeSigninManagerBase(client.get(), &tracker)); |
+ signin_manager_->Initialize(&prefs_); |
+ |
+ 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 +139,31 @@ 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()); |
+ net::URLRequestContextGetter* request_context = |
+ new net::TestURLRequestContextGetter(message_loop_.task_runner()); |
+ |
+ 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)); |
+ 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(), |
+ message_loop_.task_runner())) |
+ .Pass(), |
+ base::ThreadTaskRunnerHandle::Get(), message_loop_.task_runner(), |
droger
2015/12/14 13:54:34
Nit: I think that message_loop_.task_runner() and
Jitu( very slow this week)
2015/12/14 14:27:54
message_loop_.task_runner() and
base::ThreadTaskRu
droger
2015/12/14 14:31:47
SingleThreadTaskRunner inherits from SequencedTask
|
+ blocking_task_runner); |
droger
2015/12/14 13:54:34
Does it fail if you use message_loop_.task_runner(
Jitu( very slow this week)
2015/12/14 14:27:54
Getting below Compilation error
../../components/
droger
2015/12/14 14:31:47
Same here, the conversion should work.
|
+ gcm_profile_service_->driver()->AddAppHandler(kTestAppID, |
+ gcm_app_handler_.get()); |
} |
void GCMProfileServiceTest::RegisterAndWaitForCompletion( |