| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/instance_id/instance_id_api.h" | 6 #include "chrome/browser/extensions/api/instance_id/instance_id_api.h" |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/extensions/extension_gcm_app_handler.h" | 8 #include "chrome/browser/extensions/extension_gcm_app_handler.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | 10 #include "chrome/browser/services/gcm/fake_gcm_profile_service.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/browser/services/gcm/instance_id/instance_id_profile_service_fa
ctory.h" | 12 #include "chrome/browser/services/gcm/instance_id/instance_id_profile_service_fa
ctory.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" |
| 15 #include "extensions/test/result_catcher.h" | 16 #include "extensions/test/result_catcher.h" |
| 16 | 17 |
| 17 using extensions::ResultCatcher; | 18 using extensions::ResultCatcher; |
| 18 | 19 |
| 19 namespace extensions { | 20 namespace extensions { |
| 20 | 21 |
| 22 namespace { |
| 23 |
| 24 KeyedService* BuildFakeGCMProfileService(content::BrowserContext* context) { |
| 25 gcm::FakeGCMProfileService* service = |
| 26 new gcm::FakeGCMProfileService(Profile::FromBrowserContext(context)); |
| 27 service->SetDriverForTesting(new instance_id::FakeGCMDriverForInstanceID()); |
| 28 return service; |
| 29 } |
| 30 |
| 31 } // namespace |
| 32 |
| 21 class InstanceIDApiTest : public ExtensionApiTest { | 33 class InstanceIDApiTest : public ExtensionApiTest { |
| 22 public: | 34 public: |
| 23 InstanceIDApiTest() {} | 35 InstanceIDApiTest() {} |
| 24 | 36 |
| 25 protected: | 37 protected: |
| 26 void SetUpOnMainThread() override; | 38 void SetUpOnMainThread() override; |
| 27 void SetUpCommandLine(base::CommandLine* command_line) override; | 39 void SetUpCommandLine(base::CommandLine* command_line) override; |
| 28 | 40 |
| 29 private: | 41 private: |
| 30 DISALLOW_COPY_AND_ASSIGN(InstanceIDApiTest); | 42 DISALLOW_COPY_AND_ASSIGN(InstanceIDApiTest); |
| 31 }; | 43 }; |
| 32 | 44 |
| 33 void InstanceIDApiTest::SetUpOnMainThread() { | 45 void InstanceIDApiTest::SetUpOnMainThread() { |
| 34 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory( | 46 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory( |
| 35 browser()->profile(), &gcm::FakeGCMProfileService::Build); | 47 browser()->profile(), &BuildFakeGCMProfileService); |
| 36 | 48 |
| 37 ExtensionApiTest::SetUpOnMainThread(); | 49 ExtensionApiTest::SetUpOnMainThread(); |
| 38 } | 50 } |
| 39 | 51 |
| 40 void InstanceIDApiTest::SetUpCommandLine(base::CommandLine* command_line) { | 52 void InstanceIDApiTest::SetUpCommandLine(base::CommandLine* command_line) { |
| 41 ExtensionApiTest::SetUpCommandLine(command_line); | 53 ExtensionApiTest::SetUpCommandLine(command_line); |
| 42 | 54 |
| 43 // Makes sure InstanceID is enabled for testing. | 55 // Makes sure InstanceID is enabled for testing. |
| 44 command_line->AppendSwitchASCII( | 56 command_line->AppendSwitchASCII( |
| 45 switches::kForceFieldTrials, "InstanceID/Enabled/"); | 57 switches::kForceFieldTrials, "InstanceID/Enabled/"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 72 incognito_catcher.RestrictToBrowserContext( | 84 incognito_catcher.RestrictToBrowserContext( |
| 73 profile()->GetOffTheRecordProfile()); | 85 profile()->GetOffTheRecordProfile()); |
| 74 | 86 |
| 75 ASSERT_TRUE(RunExtensionTestIncognito("instance_id/incognito")); | 87 ASSERT_TRUE(RunExtensionTestIncognito("instance_id/incognito")); |
| 76 | 88 |
| 77 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 89 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 78 EXPECT_TRUE(incognito_catcher.GetNextResult()) << incognito_catcher.message(); | 90 EXPECT_TRUE(incognito_catcher.GetNextResult()) << incognito_catcher.message(); |
| 79 } | 91 } |
| 80 | 92 |
| 81 } // namespace extensions | 93 } // namespace extensions |
| OLD | NEW |