| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/extensions/extension_web_ui.h" | 5 #include "chrome/browser/extensions/extension_web_ui.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" | |
| 10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 11 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_web_ui_override_registrar.h" | 12 #include "chrome/browser/extensions/extension_web_ui_override_registrar.h" |
| 14 #include "chrome/browser/extensions/test_extension_system.h" | 13 #include "chrome/browser/extensions/test_extension_system.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "extensions/browser/extension_system.h" | 16 #include "extensions/browser/extension_system.h" |
| 18 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
| 19 #include "extensions/common/extension_builder.h" | 18 #include "extensions/common/extension_builder.h" |
| 20 #include "extensions/common/manifest_constants.h" | 19 #include "extensions/common/manifest_constants.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 #if defined(OS_CHROMEOS) | 22 #if defined(OS_CHROMEOS) |
| 24 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | 23 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" |
| 25 #include "chrome/browser/chromeos/settings/cros_settings.h" | 24 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 26 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 25 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 27 #endif | 26 #endif |
| 28 | 27 |
| 29 namespace extensions { | 28 namespace extensions { |
| 30 | 29 |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 std::unique_ptr<KeyedService> BuildOverrideRegistrar( | 32 std::unique_ptr<KeyedService> BuildOverrideRegistrar( |
| 34 content::BrowserContext* context) { | 33 content::BrowserContext* context) { |
| 35 return base::MakeUnique<ExtensionWebUIOverrideRegistrar>(context); | 34 return base::MakeUnique<ExtensionWebUIOverrideRegistrar>(context); |
| 36 } | 35 } |
| 37 | 36 |
| 38 } // namespace | 37 } // namespace |
| 39 | 38 |
| 40 class ExtensionWebUITest : public testing::Test { | 39 class ExtensionWebUITest : public testing::Test { |
| 41 public: | 40 public: |
| 42 ExtensionWebUITest() | 41 ExtensionWebUITest() = default; |
| 43 : ui_thread_(content::BrowserThread::UI, &message_loop_) {} | |
| 44 | 42 |
| 45 protected: | 43 protected: |
| 46 void SetUp() override { | 44 void SetUp() override { |
| 47 profile_.reset(new TestingProfile()); | 45 profile_.reset(new TestingProfile()); |
| 48 TestExtensionSystem* system = | 46 TestExtensionSystem* system = |
| 49 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile_.get())); | 47 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile_.get())); |
| 50 extension_service_ = system->CreateExtensionService( | 48 extension_service_ = system->CreateExtensionService( |
| 51 base::CommandLine::ForCurrentProcess(), base::FilePath(), false); | 49 base::CommandLine::ForCurrentProcess(), base::FilePath(), false); |
| 52 ExtensionWebUIOverrideRegistrar::GetFactoryInstance()->SetTestingFactory( | 50 ExtensionWebUIOverrideRegistrar::GetFactoryInstance()->SetTestingFactory( |
| 53 profile_.get(), &BuildOverrideRegistrar); | 51 profile_.get(), &BuildOverrideRegistrar); |
| 54 ExtensionWebUIOverrideRegistrar::GetFactoryInstance()->Get(profile_.get()); | 52 ExtensionWebUIOverrideRegistrar::GetFactoryInstance()->Get(profile_.get()); |
| 55 } | 53 } |
| 56 | 54 |
| 57 void TearDown() override { | 55 void TearDown() override { |
| 58 profile_.reset(); | 56 profile_.reset(); |
| 59 base::RunLoop().RunUntilIdle(); | 57 base::RunLoop().RunUntilIdle(); |
| 60 } | 58 } |
| 61 | 59 |
| 62 std::unique_ptr<TestingProfile> profile_; | 60 std::unique_ptr<TestingProfile> profile_; |
| 63 ExtensionService* extension_service_; | 61 ExtensionService* extension_service_; |
| 64 base::MessageLoop message_loop_; | 62 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 65 content::TestBrowserThread ui_thread_; | |
| 66 | 63 |
| 67 #if defined OS_CHROMEOS | 64 #if defined OS_CHROMEOS |
| 68 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 65 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 69 chromeos::ScopedTestCrosSettings test_cros_settings_; | 66 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 70 chromeos::ScopedTestUserManager test_user_manager_; | 67 chromeos::ScopedTestUserManager test_user_manager_; |
| 71 #endif | 68 #endif |
| 72 }; | 69 }; |
| 73 | 70 |
| 74 // Test that component extension url overrides have lower priority than | 71 // Test that component extension url overrides have lower priority than |
| 75 // non-component extension url overrides. | 72 // non-component extension url overrides. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 changed_url = kBookmarksUrl; | 152 changed_url = kBookmarksUrl; |
| 156 EXPECT_TRUE( | 153 EXPECT_TRUE( |
| 157 ExtensionWebUI::HandleChromeURLOverride(&changed_url, profile_.get())); | 154 ExtensionWebUI::HandleChromeURLOverride(&changed_url, profile_.get())); |
| 158 EXPECT_EQ(kExpectedUnpackedOverrideUrl, changed_url); | 155 EXPECT_EQ(kExpectedUnpackedOverrideUrl, changed_url); |
| 159 EXPECT_TRUE(ExtensionWebUI::HandleChromeURLOverrideReverse(&changed_url, | 156 EXPECT_TRUE(ExtensionWebUI::HandleChromeURLOverrideReverse(&changed_url, |
| 160 profile_.get())); | 157 profile_.get())); |
| 161 EXPECT_EQ(kBookmarksUrl, changed_url); | 158 EXPECT_EQ(kBookmarksUrl, changed_url); |
| 162 } | 159 } |
| 163 | 160 |
| 164 } // namespace extensions | 161 } // namespace extensions |
| OLD | NEW |