Index: chrome/browser/extensions/extension_gcm_app_handler_unittest.cc |
diff --git a/chrome/browser/extensions/extension_gcm_app_handler_unittest.cc b/chrome/browser/extensions/extension_gcm_app_handler_unittest.cc |
index 1adc3dc21f20895e15847fbc7c2c781fbf3e6168..941199679ae0833c28ac43922698833881f7c81a 100644 |
--- a/chrome/browser/extensions/extension_gcm_app_handler_unittest.cc |
+++ b/chrome/browser/extensions/extension_gcm_app_handler_unittest.cc |
@@ -2,30 +2,58 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "chrome/browser/extensions/extension_gcm_app_handler.h" |
+ |
+#include <vector> |
+ |
#include "base/bind.h" |
+#include "base/bind_helpers.h" |
#include "base/command_line.h" |
+#include "base/files/file_path.h" |
+#include "base/location.h" |
+#include "base/logging.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/message_loop/message_loop.h" |
+#include "base/observer_list.h" |
#include "base/prefs/pref_service.h" |
-#include "chrome/browser/extensions/extension_gcm_app_handler.h" |
+#include "base/run_loop.h" |
+#include "base/values.h" |
+#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/extensions/test_extension_service.h" |
#include "chrome/browser/extensions/test_extension_system.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/services/gcm/fake_gcm_client_factory.h" |
+#include "chrome/browser/services/gcm/gcm_client_factory.h" |
#include "chrome/browser/services/gcm/gcm_client_mock.h" |
#include "chrome/browser/services/gcm/gcm_profile_service.h" |
#include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
-#include "chrome/browser/services/gcm/gcm_profile_service_test_helper.h" |
+#include "chrome/browser/signin/chrome_signin_client_factory.h" |
#include "chrome/browser/signin/signin_manager_factory.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/test/base/testing_profile.h" |
+#include "components/keyed_service/core/keyed_service.h" |
+#include "components/signin/core/common/signin_pref_names.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 "extensions/browser/extension_system.h" |
#include "extensions/common/extension.h" |
+#include "extensions/common/manifest.h" |
#include "extensions/common/manifest_constants.h" |
+#include "extensions/common/permissions/api_permission.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#if !defined(OS_ANDROID) |
+#include "chrome/browser/extensions/api/gcm/gcm_api.h" |
+#endif |
+ |
#if defined(OS_CHROMEOS) |
#include "chrome/browser/chromeos/login/user_manager.h" |
#include "chrome/browser/chromeos/settings/cros_settings.h" |
#include "chrome/browser/chromeos/settings/device_settings_service.h" |
+#include "components/signin/core/browser/signin_manager_base.h" |
#else |
+#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
#include "components/signin/core/browser/signin_manager.h" |
#endif |
@@ -40,6 +68,118 @@ const char kTestingUsername[] = "user1@example.com"; |
} // namespace |
+#if defined(OS_CHROMEOS) |
+class FakeSigninManager : public SigninManagerBase { |
+#else |
+class FakeSigninManager : public SigninManager { |
+#endif |
+ public: |
+ static KeyedService* Build(content::BrowserContext* context) { |
+ return new FakeSigninManager(static_cast<Profile*>(context)); |
+ } |
+ |
+ explicit FakeSigninManager(Profile* profile) |
+#if defined(OS_CHROMEOS) |
+ : SigninManagerBase( |
+ ChromeSigninClientFactory::GetInstance()->GetForProfile(profile)), |
+#else |
+ : SigninManager( |
+ ChromeSigninClientFactory::GetInstance()->GetForProfile(profile), |
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile)), |
+#endif |
+ profile_(profile) { |
+ Initialize(NULL); |
+ } |
+ |
+ virtual ~FakeSigninManager() {} |
+ |
+ void SignIn(const std::string& username) { |
+ SetAuthenticatedUsername(username); |
+ FOR_EACH_OBSERVER(Observer, |
+ observer_list_, |
+ GoogleSigninSucceeded(username, std::string())); |
+ } |
+ |
+#if defined(OS_CHROMEOS) |
+ void SignOut() { |
+#else |
+ virtual void SignOut() OVERRIDE { |
+#endif |
+ std::string username = GetAuthenticatedUsername(); |
+ clear_authenticated_username(); |
+ profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); |
+ FOR_EACH_OBSERVER(Observer, observer_list_, GoogleSignedOut(username)); |
+ } |
+ |
+ private: |
+ Profile* profile_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FakeSigninManager); |
+}; |
+ |
+// Helper class for asynchronous waiting. |
+class Waiter { |
+ public: |
+ Waiter() {} |
+ ~Waiter() {} |
+ |
+ // Waits until the asynchronous operation finishes. |
+ void WaitUntilCompleted() { |
+ run_loop_.reset(new base::RunLoop); |
+ run_loop_->Run(); |
+ } |
+ |
+ // Signals that the asynchronous operation finishes. |
+ void SignalCompleted() { |
+ if (run_loop_ && run_loop_->running()) |
+ run_loop_->Quit(); |
+ } |
+ |
+ // Runs until UI loop becomes idle. |
+ void PumpUILoop() { |
+ base::MessageLoop::current()->RunUntilIdle(); |
+ } |
+ |
+ // Runs until IO loop becomes idle. |
+ void PumpIOLoop() { |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&Waiter::OnIOLoopPump, base::Unretained(this))); |
+ |
+ WaitUntilCompleted(); |
+ } |
+ |
+ private: |
+ void PumpIOLoopCompleted() { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
+ |
+ SignalCompleted(); |
+ } |
+ |
+ void OnIOLoopPump() { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
+ |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&Waiter::OnIOLoopPumpCompleted, base::Unretained(this))); |
+ } |
+ |
+ void OnIOLoopPumpCompleted() { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
+ |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind(&Waiter::PumpIOLoopCompleted, base::Unretained(this))); |
+ } |
+ |
+ scoped_ptr<base::RunLoop> run_loop_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Waiter); |
+}; |
+ |
class FakeExtensionGCMAppHandler : public ExtensionGCMAppHandler { |
public: |
FakeExtensionGCMAppHandler(Profile* profile, Waiter* waiter) |
@@ -53,7 +193,7 @@ class FakeExtensionGCMAppHandler : public ExtensionGCMAppHandler { |
virtual void OnMessage( |
const std::string& app_id, |
- const GCMClient::IncomingMessage& message)OVERRIDE { |
+ const GCMClient::IncomingMessage& message) OVERRIDE { |
} |
virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE { |
@@ -111,9 +251,9 @@ class ExtensionGCMAppHandlerTest : public testing::Test { |
// Create a new profile. |
TestingProfile::Builder builder; |
builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
- gcm::FakeSigninManager::Build); |
+ FakeSigninManager::Build); |
profile_ = builder.Build(); |
- signin_manager_ = static_cast<gcm::FakeSigninManager*>( |
+ signin_manager_ = static_cast<FakeSigninManager*>( |
SigninManagerFactory::GetInstance()->GetForProfile(profile_.get())); |
// Create extension service in order to uninstall the extension. |
@@ -239,7 +379,7 @@ class ExtensionGCMAppHandlerTest : public testing::Test { |
scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; |
scoped_ptr<TestingProfile> profile_; |
ExtensionService* extension_service_; // Not owned. |
- gcm::FakeSigninManager* signin_manager_; // Not owned. |
+ FakeSigninManager* signin_manager_; // Not owned. |
// This is needed to create extension service under CrOS. |
#if defined(OS_CHROMEOS) |