| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/browser/extensions/test_extension_system.h" | 17 #include "chrome/browser/extensions/test_extension_system.h" |
| 18 #include "chrome/browser/extensions/zipfile_installer.h" | 18 #include "chrome/browser/extensions/zipfile_installer.h" |
| 19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 21 #include "content/public/browser/shell_context.h" |
| 21 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 22 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
| 23 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
| 24 #include "extensions/browser/extension_registry_observer.h" | 25 #include "extensions/browser/extension_registry_observer.h" |
| 25 #include "extensions/common/constants.h" | 26 #include "extensions/common/constants.h" |
| 26 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 29 |
| 29 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
| 30 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | 31 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 60 | 61 |
| 61 class ZipFileInstallerTest : public testing::Test { | 62 class ZipFileInstallerTest : public testing::Test { |
| 62 public: | 63 public: |
| 63 ZipFileInstallerTest() | 64 ZipFileInstallerTest() |
| 64 : browser_threads_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} | 65 : browser_threads_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 65 | 66 |
| 66 void SetUp() override { | 67 void SetUp() override { |
| 67 in_process_utility_thread_helper_.reset( | 68 in_process_utility_thread_helper_.reset( |
| 68 new content::InProcessUtilityThreadHelper); | 69 new content::InProcessUtilityThreadHelper); |
| 69 | 70 |
| 71 shell_context_ = content::ShellContext::Create(); |
| 72 |
| 70 // Create profile for extension service. | 73 // Create profile for extension service. |
| 71 profile_.reset(new TestingProfile()); | 74 profile_.reset(new TestingProfile()); |
| 72 TestExtensionSystem* system = | 75 TestExtensionSystem* system = |
| 73 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile_.get())); | 76 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile_.get())); |
| 74 extension_service_ = system->CreateExtensionService( | 77 extension_service_ = system->CreateExtensionService( |
| 75 base::CommandLine::ForCurrentProcess(), base::FilePath(), false); | 78 base::CommandLine::ForCurrentProcess(), base::FilePath(), false); |
| 76 ExtensionRegistry* registry(ExtensionRegistry::Get(profile_.get())); | 79 ExtensionRegistry* registry(ExtensionRegistry::Get(profile_.get())); |
| 77 registry->AddObserver(&observer_); | 80 registry->AddObserver(&observer_); |
| 78 } | 81 } |
| 79 | 82 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 108 protected: | 111 protected: |
| 109 scoped_refptr<ZipFileInstaller> zipfile_installer_; | 112 scoped_refptr<ZipFileInstaller> zipfile_installer_; |
| 110 | 113 |
| 111 std::unique_ptr<TestingProfile> profile_; | 114 std::unique_ptr<TestingProfile> profile_; |
| 112 ExtensionService* extension_service_; | 115 ExtensionService* extension_service_; |
| 113 | 116 |
| 114 content::TestBrowserThreadBundle browser_threads_; | 117 content::TestBrowserThreadBundle browser_threads_; |
| 115 std::unique_ptr<content::InProcessUtilityThreadHelper> | 118 std::unique_ptr<content::InProcessUtilityThreadHelper> |
| 116 in_process_utility_thread_helper_; | 119 in_process_utility_thread_helper_; |
| 117 MockExtensionRegistryObserver observer_; | 120 MockExtensionRegistryObserver observer_; |
| 121 std::unique_ptr<content::ShellContext> shell_context_; |
| 118 | 122 |
| 119 #if defined(OS_CHROMEOS) | 123 #if defined(OS_CHROMEOS) |
| 120 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 124 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 121 chromeos::ScopedTestCrosSettings test_cros_settings_; | 125 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 122 // ChromeOS needs a user manager to instantiate an extension service. | 126 // ChromeOS needs a user manager to instantiate an extension service. |
| 123 chromeos::ScopedTestUserManager test_user_manager_; | 127 chromeos::ScopedTestUserManager test_user_manager_; |
| 124 #endif | 128 #endif |
| 125 }; | 129 }; |
| 126 | 130 |
| 127 TEST_F(ZipFileInstallerTest, GoodZip) { | 131 TEST_F(ZipFileInstallerTest, GoodZip) { |
| 128 RunInstaller("good.zip"); | 132 RunInstaller("good.zip"); |
| 129 } | 133 } |
| 130 | 134 |
| 131 TEST_F(ZipFileInstallerTest, ZipWithPublicKey) { | 135 TEST_F(ZipFileInstallerTest, ZipWithPublicKey) { |
| 132 RunInstaller("public_key.zip"); | 136 RunInstaller("public_key.zip"); |
| 133 const char kIdForPublicKey[] = "ikppjpenhoddphklkpdfdfdabbakkpal"; | 137 const char kIdForPublicKey[] = "ikppjpenhoddphklkpdfdfdabbakkpal"; |
| 134 EXPECT_EQ(observer_.last_extension_installed, kIdForPublicKey); | 138 EXPECT_EQ(observer_.last_extension_installed, kIdForPublicKey); |
| 135 } | 139 } |
| 136 | 140 |
| 137 } // namespace extensions | 141 } // namespace extensions |
| OLD | NEW |