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 33a68cde4621eb8f74d42062aba1cef8ff6b9b54..599affca8c930c6cb6326b1e240303f5c7467c2a 100644 |
--- a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc |
+++ b/components/gcm_driver/gcm_profile_service_unittest.cc |
@@ -11,28 +11,27 @@ |
#include "base/callback.h" |
#include "base/macros.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 "base/single_thread_task_runner.h" |
+#include "base/test/test_simple_task_runner.h" |
#include "build/build_config.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" |
#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/account_tracker_service.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 "testing/gtest/include/gtest/gtest.h" |
namespace gcm { |
@@ -42,34 +41,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 { |
@@ -108,9 +79,12 @@ class GCMProfileServiceTest : public testing::Test { |
GCMClient::Result send_result() const { return send_result_; } |
private: |
- content::TestBrowserThreadBundle thread_bundle_; |
- scoped_ptr<TestingProfile> profile_; |
- GCMProfileService* gcm_profile_service_; |
+ base::ScopedTempDir temp_dir_; |
+ base::MessageLoop message_loop_; |
+ TestingPrefServiceSimple prefs_; |
+ scoped_ptr<TestSigninClient> signin_client_; |
+ scoped_ptr<AccountTrackerService> tracker_; |
+ scoped_ptr<GCMProfileService> gcm_profile_service_; |
scoped_ptr<FakeGCMAppHandler> gcm_app_handler_; |
std::string registration_id_; |
@@ -123,8 +97,7 @@ class GCMProfileServiceTest : public testing::Test { |
}; |
GCMProfileServiceTest::GCMProfileServiceTest() |
- : gcm_profile_service_(NULL), |
- gcm_app_handler_(new FakeGCMAppHandler), |
+ : gcm_app_handler_(new FakeGCMAppHandler), |
registration_result_(GCMClient::UNKNOWN_ERROR), |
send_result_(GCMClient::UNKNOWN_ERROR) { |
} |
@@ -138,13 +111,16 @@ FakeGCMClient* GCMProfileServiceTest::GetGCMClient() const { |
} |
void GCMProfileServiceTest::SetUp() { |
+ GCMChannelStatusSyncer::RegisterPrefs(prefs_.registry()); |
+ signin_client_.reset(new TestSigninClient(&prefs_)); |
+ tracker_.reset(new AccountTrackerService()); |
+ |
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
#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() { |
@@ -152,12 +128,25 @@ 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(); |
+ scoped_refptr<net::URLRequestContextGetter> request_context = |
+ new net::TestURLRequestContextGetter(task_runner); |
+ gcm_profile_service_.reset(new gcm::GCMProfileService( |
+ &prefs_, temp_dir_.path(), request_context.get(), |
+ version_info::Channel::UNKNOWN, |
+ scoped_ptr<ProfileIdentityProvider>( |
+ new ProfileIdentityProvider( |
+ new FakeSigninManagerBase(signin_client_.get(), tracker_.get()), |
+ new FakeProfileOAuth2TokenService(), 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( |