Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 #include "chrome/browser/extensions/api/gcm/gcm_api.h" | 6 #include "chrome/browser/extensions/api/gcm/gcm_api.h" |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | 9 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" |
| 10 #include "chrome/browser/services/gcm/gcm_client_factory.h" | 10 #include "chrome/browser/services/gcm/gcm_client_factory.h" |
| 11 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 11 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 12 #include "chrome/common/chrome_switches.h" | |
| 12 #include "chrome/common/extensions/features/feature_channel.h" | 13 #include "chrome/common/extensions/features/feature_channel.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 const char kEventsExtension[] = "gcm/events"; | 18 const char kEventsExtension[] = "gcm/events"; |
| 18 | 19 |
| 19 } // namespace | 20 } // namespace |
| 20 | 21 |
| 21 namespace extensions { | 22 namespace extensions { |
| 22 | 23 |
| 23 class GcmApiTest : public ExtensionApiTest { | 24 class GcmApiTest : public ExtensionApiTest { |
| 24 public: | 25 public: |
| 25 GcmApiTest() : fake_gcm_profile_service_(NULL) {} | 26 GcmApiTest() : fake_gcm_profile_service_(NULL) {} |
| 26 | 27 |
| 27 protected: | 28 protected: |
| 29 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; | |
| 28 virtual void SetUpOnMainThread() OVERRIDE; | 30 virtual void SetUpOnMainThread() OVERRIDE; |
| 29 | 31 |
| 30 void StartCollecting(); | 32 void StartCollecting(); |
| 31 | 33 |
| 32 const Extension* LoadTestExtension(const std::string& extension_path, | 34 const Extension* LoadTestExtension(const std::string& extension_path, |
| 33 const std::string& page_name); | 35 const std::string& page_name); |
| 34 gcm::FakeGCMProfileService* service() const; | 36 gcm::FakeGCMProfileService* service() const; |
| 35 bool ShouldSkipTest() const; | 37 bool ShouldSkipTest() const; |
| 36 | 38 |
| 37 private: | 39 private: |
| 38 gcm::FakeGCMProfileService* fake_gcm_profile_service_; | 40 gcm::FakeGCMProfileService* fake_gcm_profile_service_; |
| 39 }; | 41 }; |
| 40 | 42 |
| 43 void GcmApiTest::SetUpCommandLine(CommandLine* command_line) { | |
| 44 // The GCMProfileService instance could now be created in | |
| 45 // ProfileSyncServiceFactory::BuildServiceInstanceFor that is invoked when | |
| 46 // a profile is being initialized. This prevents us from settings a faked | |
| 47 // GCMProfileService instance as in SetUpOnMainThread. To work around this | |
|
Nicolas Zea
2014/02/21 20:58:58
nit: fix comment. Not sure what "settings a faked
jianli
2014/02/22 00:03:06
Done.
| |
| 48 // problem, we disable the ProfileSyncServiceFactory logic since GCM API | |
| 49 // tests do not depend on any sync feature. | |
| 50 command_line->AppendSwitch(switches::kDisableSync); | |
| 51 | |
| 52 ExtensionApiTest::SetUpCommandLine(command_line); | |
| 53 } | |
| 54 | |
| 41 void GcmApiTest::SetUpOnMainThread() { | 55 void GcmApiTest::SetUpOnMainThread() { |
| 42 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory( | 56 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory( |
| 43 browser()->profile(), &gcm::FakeGCMProfileService::Build); | 57 browser()->profile(), &gcm::FakeGCMProfileService::Build); |
| 44 fake_gcm_profile_service_ = static_cast<gcm::FakeGCMProfileService*>( | 58 fake_gcm_profile_service_ = static_cast<gcm::FakeGCMProfileService*>( |
| 45 gcm::GCMProfileServiceFactory::GetInstance()->GetForProfile( | 59 gcm::GCMProfileServiceFactory::GetInstance()->GetForProfile( |
| 46 browser()->profile())); | 60 browser()->profile())); |
| 47 gcm::FakeGCMProfileService::EnableGCMForTesting(); | 61 gcm::FakeGCMProfileService::EnableGCMForTesting(); |
| 62 | |
| 63 ExtensionApiTest::SetUpOnMainThread(); | |
| 48 } | 64 } |
| 49 | 65 |
| 50 void GcmApiTest::StartCollecting() { | 66 void GcmApiTest::StartCollecting() { |
| 51 service()->set_collect(true); | 67 service()->set_collect(true); |
| 52 } | 68 } |
| 53 | 69 |
| 54 gcm::FakeGCMProfileService* GcmApiTest::service() const { | 70 gcm::FakeGCMProfileService* GcmApiTest::service() const { |
| 55 return fake_gcm_profile_service_; | 71 return fake_gcm_profile_service_; |
| 56 } | 72 } |
| 57 | 73 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 ResultCatcher incognito_catcher; | 213 ResultCatcher incognito_catcher; |
| 198 incognito_catcher.RestrictToProfile(profile()->GetOffTheRecordProfile()); | 214 incognito_catcher.RestrictToProfile(profile()->GetOffTheRecordProfile()); |
| 199 | 215 |
| 200 ASSERT_TRUE(RunExtensionTestIncognito("gcm/functions/incognito")); | 216 ASSERT_TRUE(RunExtensionTestIncognito("gcm/functions/incognito")); |
| 201 | 217 |
| 202 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 218 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 203 EXPECT_TRUE(incognito_catcher.GetNextResult()) << incognito_catcher.message(); | 219 EXPECT_TRUE(incognito_catcher.GetNextResult()) << incognito_catcher.message(); |
| 204 } | 220 } |
| 205 | 221 |
| 206 } // namespace extensions | 222 } // namespace extensions |
| OLD | NEW |