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

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: Rebased 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 66%
rename from chrome/browser/services/gcm/gcm_profile_service_unittest.cc
rename to components/gcm_driver/gcm_profile_service_unittest.cc
index 2ba5b185c200f9084f7798907d04e8f5ad2a98f7..8cf3da80d926e3cfce8326f6c8aeb439381bdf9d 100644
--- a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc
+++ b/components/gcm_driver/gcm_profile_service_unittest.cc
@@ -10,27 +10,25 @@
#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 "testing/gtest/include/gtest/gtest.h"
namespace gcm {
@@ -40,34 +38,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 +76,11 @@ 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<TestSigninClient> signin_client_;
+ scoped_ptr<AccountTrackerService> tracker_;
GCMProfileService* gcm_profile_service_;
scoped_ptr<FakeGCMAppHandler> gcm_app_handler_;
@@ -136,13 +109,17 @@ 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() {
@@ -150,12 +127,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_ = 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(
@@ -175,8 +165,8 @@ void GCMProfileServiceTest::UnregisterAndWaitForCompletion() {
gcm_profile_service_->driver()->Unregister(
kTestAppID,
base::Bind(&GCMProfileServiceTest::UnregisterCompleted,
- base::Unretained(this),
- run_loop.QuitClosure()));
+ base::Unretained(this),
+ run_loop.QuitClosure()));
run_loop.Run();
}
@@ -188,31 +178,31 @@ void GCMProfileServiceTest::SendAndWaitForCompletion(
kUserID,
message,
base::Bind(&GCMProfileServiceTest::SendCompleted,
- base::Unretained(this),
- run_loop.QuitClosure()));
+ base::Unretained(this),
+ run_loop.QuitClosure()));
run_loop.Run();
}
void GCMProfileServiceTest::RegisterCompleted(
- const base::Closure& callback,
- const std::string& registration_id,
- GCMClient::Result result) {
+ const base::Closure& callback,
+ const std::string& registration_id,
+ GCMClient::Result result) {
registration_id_ = registration_id;
registration_result_ = result;
callback.Run();
}
void GCMProfileServiceTest::UnregisterCompleted(
- const base::Closure& callback,
- GCMClient::Result result) {
+ const base::Closure& callback,
+ GCMClient::Result result) {
unregistration_result_ = result;
callback.Run();
}
void GCMProfileServiceTest::SendCompleted(
- const base::Closure& callback,
- const std::string& message_id,
- GCMClient::Result result) {
+ const base::Closure& callback,
+ const std::string& message_id,
+ GCMClient::Result result) {
send_message_id_ = message_id;
send_result_ = result;
callback.Run();
« 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