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 60% |
rename from chrome/browser/services/gcm/gcm_profile_service_unittest.cc |
rename to components/gcm_driver/gcm_profile_service_unittest.cc |
index 2ba5b185c200f9084f7798907d04e8f5ad2a98f7..d2260fcb960f19a002c7cf79e8e2de22e5eb1e5b 100644 |
--- a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc |
+++ b/components/gcm_driver/gcm_profile_service_unittest.cc |
@@ -10,26 +10,26 @@ |
#include "base/bind_helpers.h" |
#include "base/callback.h" |
#include "base/memory/scoped_ptr.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 "content/public/browser/browser_thread.h" |
+ |
#include "content/public/test/test_browser_thread_bundle.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -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,16 @@ class GCMProfileServiceTest : public testing::Test { |
GCMClient::Result send_result() const { return send_result_; } |
private: |
+ base::ScopedTempDir temp_dir_; |
content::TestBrowserThreadBundle thread_bundle_; |
- scoped_ptr<TestingProfile> profile_; |
+ scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
+ base::Thread io_thread_; |
droger
2015/11/25 09:19:20
Remove task_runner_ and io_thread_ and use a base:
Jitu( very slow this week)
2015/12/14 13:40:37
Done.
|
+ |
+ TestingPrefServiceSimple prefs_; |
+ // scoped_ptr<TestSigninClient> signin_client_; |
+ scoped_ptr<FakeSigninManagerBase> signin_manager_; |
+ // scoped_ptr<AccountTrackerService> account_tracker_; |
+ scoped_ptr<ProfileOAuth2TokenService> fake_token_service_; |
GCMProfileService* gcm_profile_service_; |
scoped_ptr<FakeGCMAppHandler> gcm_app_handler_; |
@@ -121,13 +101,15 @@ class GCMProfileServiceTest : public testing::Test { |
}; |
GCMProfileServiceTest::GCMProfileServiceTest() |
- : gcm_profile_service_(NULL), |
+ : task_runner_(new base::TestSimpleTaskRunner()), |
+ io_thread_("IOThread"), |
+ 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() { |
+ VLOG(0) << "JITU" << __FUNCTION__; |
} |
FakeGCMClient* GCMProfileServiceTest::GetGCMClient() const { |
@@ -136,89 +118,125 @@ FakeGCMClient* GCMProfileServiceTest::GetGCMClient() const { |
} |
void GCMProfileServiceTest::SetUp() { |
+ VLOG(0) << "JITU" << __FUNCTION__; |
+ GCMChannelStatusSyncer::RegisterPrefs(prefs_.registry()); |
+ io_thread_.Start(); |
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
+ // Setup account tracker. |
+ scoped_ptr<TestSigninClient> client; |
+ client.reset(new TestSigninClient(&prefs_)); |
+ AccountTrackerService tracker; |
+ // tracker.Initialize(client.get()); |
+ signin_manager_.reset(new FakeSigninManagerBase(client.get(), &tracker)); |
+ // signin_manager_->Initialize(&prefs_); |
+ |
+ fake_token_service_.reset(new FakeProfileOAuth2TokenService()); |
+ VLOG(0) << "JITU" << __FUNCTION__; |
+ |
#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(); |
+ // TestingProfile::Builder builder; |
+ // profile_ = builder.Build(); |
} |
void GCMProfileServiceTest::TearDown() { |
+ VLOG(0) << "JITU::" << __FUNCTION__; |
gcm_profile_service_->driver()->RemoveAppHandler(kTestAppID); |
} |
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(io_thread_.task_runner()); |
droger
2015/11/25 09:19:20
Use message_loop_.task_runner()
Jitu( very slow this week)
2015/12/14 13:40:37
Done.
|
+ VLOG(0) << "JITU::" << __FUNCTION__; |
+ |
+ base::SequencedWorkerPool* worker_pool = |
+ content::BrowserThread::GetBlockingPool(); |
+ VLOG(0) << "JITU::" << __FUNCTION__; |
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( |
+ worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
+ worker_pool->GetSequenceToken(), |
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
+ VLOG(0) << "JITU::" << __FUNCTION__; |
+ 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(), |
+ io_thread_.task_runner())) |
+ .Pass(), |
+ base::ThreadTaskRunnerHandle::Get(), io_thread_.task_runner(), |
+ blocking_task_runner); |
+ gcm_profile_service_->driver()->AddAppHandler(kTestAppID, |
+ gcm_app_handler_.get()); |
} |
void GCMProfileServiceTest::RegisterAndWaitForCompletion( |
const std::vector<std::string>& sender_ids) { |
+ VLOG(0) << "JITU::" << __FUNCTION__; |
base::RunLoop run_loop; |
gcm_profile_service_->driver()->Register( |
- kTestAppID, |
- sender_ids, |
+ kTestAppID, sender_ids, |
base::Bind(&GCMProfileServiceTest::RegisterCompleted, |
- base::Unretained(this), |
- run_loop.QuitClosure())); |
+ base::Unretained(this), run_loop.QuitClosure())); |
run_loop.Run(); |
} |
void GCMProfileServiceTest::UnregisterAndWaitForCompletion() { |
+ VLOG(0) << "JITU::" << __FUNCTION__; |
base::RunLoop run_loop; |
gcm_profile_service_->driver()->Unregister( |
- kTestAppID, |
- base::Bind(&GCMProfileServiceTest::UnregisterCompleted, |
- base::Unretained(this), |
- run_loop.QuitClosure())); |
+ kTestAppID, base::Bind(&GCMProfileServiceTest::UnregisterCompleted, |
+ base::Unretained(this), run_loop.QuitClosure())); |
run_loop.Run(); |
} |
void GCMProfileServiceTest::SendAndWaitForCompletion( |
const OutgoingMessage& message) { |
+ VLOG(0) << "JITU::" << __FUNCTION__; |
base::RunLoop run_loop; |
gcm_profile_service_->driver()->Send( |
- kTestAppID, |
- kUserID, |
- message, |
- base::Bind(&GCMProfileServiceTest::SendCompleted, |
- base::Unretained(this), |
+ kTestAppID, kUserID, message, |
+ base::Bind(&GCMProfileServiceTest::SendCompleted, 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) { |
+ VLOG(0) << "JITU::" << __FUNCTION__; |
registration_id_ = registration_id; |
registration_result_ = result; |
callback.Run(); |
} |
-void GCMProfileServiceTest::UnregisterCompleted( |
- const base::Closure& callback, |
- GCMClient::Result result) { |
+void GCMProfileServiceTest::UnregisterCompleted(const base::Closure& callback, |
+ GCMClient::Result result) { |
+ VLOG(0) << "JITU::" << __FUNCTION__; |
unregistration_result_ = result; |
callback.Run(); |
} |
-void GCMProfileServiceTest::SendCompleted( |
- const base::Closure& callback, |
- const std::string& message_id, |
- GCMClient::Result result) { |
+void GCMProfileServiceTest::SendCompleted(const base::Closure& callback, |
+ const std::string& message_id, |
+ GCMClient::Result result) { |
+ VLOG(0) << "JITU::" << __FUNCTION__; |
send_message_id_ = message_id; |
send_result_ = result; |
callback.Run(); |
} |
TEST_F(GCMProfileServiceTest, RegisterAndUnregister) { |
+ VLOG(0) << "JITU::" << __FUNCTION__; |
CreateGCMProfileService(); |
std::vector<std::string> sender_ids; |
@@ -229,12 +247,13 @@ TEST_F(GCMProfileServiceTest, RegisterAndUnregister) { |
FakeGCMClient::GenerateGCMRegistrationID(sender_ids); |
EXPECT_EQ(expected_registration_id, registration_id()); |
EXPECT_EQ(GCMClient::SUCCESS, registration_result()); |
- |
UnregisterAndWaitForCompletion(); |
EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); |
} |
TEST_F(GCMProfileServiceTest, Send) { |
+ |
+ VLOG(0) << "JITU::" << __FUNCTION__; |
CreateGCMProfileService(); |
OutgoingMessage message; |