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 "chrome/browser/ui/webui/extensions/extension_settings_browsertest.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_settings_browsertest.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/crx_installer.h" | 11 #include "chrome/browser/extensions/crx_installer.h" |
12 #include "chrome/browser/extensions/extension_error_reporter.h" | 12 #include "chrome/browser/extensions/extension_error_reporter.h" |
13 #include "chrome/browser/extensions/extension_install_prompt.h" | 13 #include "chrome/browser/extensions/extension_install_prompt.h" |
14 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" | 14 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/unpacked_installer.h" | 16 #include "chrome/browser/extensions/unpacked_installer.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
26 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
27 #include "extensions/browser/api/management/management_api.h" | |
27 #include "extensions/browser/extension_registry.h" | 28 #include "extensions/browser/extension_registry.h" |
28 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
29 #include "extensions/browser/test_extension_registry_observer.h" | 30 #include "extensions/browser/test_extension_registry_observer.h" |
30 #include "extensions/common/extension_set.h" | 31 #include "extensions/common/extension_set.h" |
31 | 32 |
32 using extensions::Extension; | 33 using extensions::Extension; |
33 using extensions::TestManagementPolicyProvider; | 34 using extensions::TestManagementPolicyProvider; |
34 | 35 |
35 ExtensionSettingsUIBrowserTest::ExtensionSettingsUIBrowserTest() | 36 ExtensionSettingsUIBrowserTest::ExtensionSettingsUIBrowserTest() |
36 : profile_(NULL), | 37 : profile_(NULL), |
37 policy_provider_(TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS | | 38 policy_provider_(TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS | |
38 TestManagementPolicyProvider::MUST_REMAIN_ENABLED | | 39 TestManagementPolicyProvider::MUST_REMAIN_ENABLED | |
39 TestManagementPolicyProvider::MUST_REMAIN_INSTALLED) {} | 40 TestManagementPolicyProvider::MUST_REMAIN_INSTALLED) { |
41 CHECK(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); | |
42 test_data_dir_ = test_data_dir_.AppendASCII("extensions"); | |
43 } | |
40 | 44 |
41 ExtensionSettingsUIBrowserTest::~ExtensionSettingsUIBrowserTest() {} | 45 ExtensionSettingsUIBrowserTest::~ExtensionSettingsUIBrowserTest() {} |
42 | 46 |
43 Profile* ExtensionSettingsUIBrowserTest::GetProfile() { | 47 Profile* ExtensionSettingsUIBrowserTest::GetProfile() { |
44 if (!profile_) { | 48 if (!profile_) { |
45 profile_ = browser() ? browser()->profile() : | 49 profile_ = browser() ? browser()->profile() : |
46 ProfileManager::GetActiveUserProfile(); | 50 ProfileManager::GetActiveUserProfile(); |
47 } | 51 } |
48 return profile_; | 52 return profile_; |
49 } | 53 } |
50 | 54 |
51 void ExtensionSettingsUIBrowserTest::SetUpOnMainThread() { | 55 void ExtensionSettingsUIBrowserTest::SetUpOnMainThread() { |
52 WebUIBrowserTest::SetUpOnMainThread(); | 56 WebUIBrowserTest::SetUpOnMainThread(); |
53 observer_.reset(new ExtensionTestNotificationObserver(browser())); | 57 observer_.reset(new ExtensionTestNotificationObserver(browser())); |
54 } | 58 } |
55 | 59 |
56 void ExtensionSettingsUIBrowserTest::InstallGoodExtension() { | 60 void ExtensionSettingsUIBrowserTest::InstallGoodExtension() { |
57 base::FilePath test_data_dir; | 61 EXPECT_TRUE(InstallExtension(test_data_dir_.AppendASCII("good.crx"))); |
58 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { | |
59 ADD_FAILURE(); | |
60 return; | |
61 } | |
62 base::FilePath extensions_data_dir = test_data_dir.AppendASCII("extensions"); | |
63 EXPECT_TRUE(InstallExtension(extensions_data_dir.AppendASCII("good.crx"))); | |
64 } | 62 } |
65 | 63 |
66 void ExtensionSettingsUIBrowserTest::InstallErrorsExtension() { | 64 void ExtensionSettingsUIBrowserTest::InstallErrorsExtension() { |
67 base::FilePath test_data_dir; | |
68 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { | |
69 ADD_FAILURE(); | |
70 return; | |
71 } | |
72 base::FilePath extensions_data_dir = test_data_dir.AppendASCII("extensions"); | |
73 extensions_data_dir = extensions_data_dir.AppendASCII("error_console"); | |
74 EXPECT_TRUE(InstallUnpackedExtension( | 65 EXPECT_TRUE(InstallUnpackedExtension( |
75 extensions_data_dir.AppendASCII("runtime_and_manifest_errors"), | 66 test_data_dir_.AppendASCII("error_console") |
76 "pdlpifnclfacjobnmbpngemkalkjamnf")); | 67 .AppendASCII("runtime_and_manifest_errors"))); |
77 } | 68 } |
78 | 69 |
79 void ExtensionSettingsUIBrowserTest::AddManagedPolicyProvider() { | 70 void ExtensionSettingsUIBrowserTest::AddManagedPolicyProvider() { |
80 auto* extension_service = extensions::ExtensionSystem::Get(GetProfile()); | 71 auto* extension_service = extensions::ExtensionSystem::Get(GetProfile()); |
81 extension_service->management_policy()->RegisterProvider(&policy_provider_); | 72 extension_service->management_policy()->RegisterProvider(&policy_provider_); |
82 } | 73 } |
83 | 74 |
75 void ExtensionSettingsUIBrowserTest::SetAutoConfirmUninstall() { | |
76 extensions::ManagementUninstallFunctionBase::SetAutoConfirmForTest(true); | |
77 } | |
78 | |
79 void ExtensionSettingsUIBrowserTest::InstallSharedModule() { | |
80 base::FilePath shared_module_path = | |
81 test_data_dir_.AppendASCII("api_test").AppendASCII("shared_module"); | |
82 EXPECT_TRUE(InstallUnpackedExtension( | |
83 shared_module_path.AppendASCII("shared"))); | |
84 EXPECT_TRUE(InstallUnpackedExtension( | |
85 shared_module_path.AppendASCII("import_pass"))); | |
86 } | |
87 | |
84 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { | 88 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { |
85 public: | 89 public: |
86 explicit MockAutoConfirmExtensionInstallPrompt( | 90 explicit MockAutoConfirmExtensionInstallPrompt( |
87 content::WebContents* web_contents) | 91 content::WebContents* web_contents) |
88 : ExtensionInstallPrompt(web_contents) {} | 92 : ExtensionInstallPrompt(web_contents) {} |
89 | 93 |
90 // Proceed without confirmation prompt. | 94 // Proceed without confirmation prompt. |
91 void ConfirmInstall(Delegate* delegate, | 95 void ConfirmInstall(Delegate* delegate, |
92 const Extension* extension, | 96 const Extension* extension, |
93 const ShowDialogCallback& show_dialog_callback) override { | 97 const ShowDialogCallback& show_dialog_callback) override { |
94 delegate->InstallUIProceed(); | 98 delegate->InstallUIProceed(); |
95 } | 99 } |
96 }; | 100 }; |
97 | 101 |
98 const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension( | 102 const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension( |
99 const base::FilePath& path, const char* id) { | 103 const base::FilePath& path) { |
100 if (path.empty()) | 104 if (path.empty()) |
101 return NULL; | 105 return NULL; |
102 | 106 |
103 Profile* profile = GetProfile(); | 107 Profile* profile = GetProfile(); |
104 ExtensionService* service = | 108 ExtensionService* service = |
105 extensions::ExtensionSystem::Get(profile)->extension_service(); | 109 extensions::ExtensionSystem::Get(profile)->extension_service(); |
106 service->set_show_extensions_prompts(false); | 110 service->set_show_extensions_prompts(false); |
107 extensions::ExtensionRegistry* registry = | 111 extensions::ExtensionRegistry* registry = |
108 extensions::ExtensionRegistry::Get(profile); | 112 extensions::ExtensionRegistry::Get(profile); |
109 extensions::TestExtensionRegistryObserver observer(registry, id); | 113 extensions::TestExtensionRegistryObserver observer(registry); |
114 extensions::UnpackedInstaller::Create(service)->Load(path); | |
115 base::FilePath extension_path = base::MakeAbsoluteFilePath(path); | |
116 const Extension* extension = nullptr; | |
117 do { | |
118 extension = observer.WaitForExtensionLoaded(); | |
Dan Beam
2015/04/01 23:12:04
can this return nullptr?
Devlin
2015/04/02 00:01:38
Nope.
| |
119 } while (extension->path() != extension_path); | |
110 | 120 |
111 extensions::UnpackedInstaller::Create(service)->Load(path); | 121 return extension; |
112 | |
113 // Test will timeout if extension is not loaded. | |
114 observer.WaitForExtensionLoaded(); | |
115 return service->GetExtensionById(last_loaded_extension_id(), false); | |
116 } | 122 } |
117 | 123 |
118 const Extension* ExtensionSettingsUIBrowserTest::InstallExtension( | 124 const Extension* ExtensionSettingsUIBrowserTest::InstallExtension( |
119 const base::FilePath& path) { | 125 const base::FilePath& path) { |
120 Profile* profile = GetProfile(); | 126 Profile* profile = GetProfile(); |
121 ExtensionService* service = | 127 ExtensionService* service = |
122 extensions::ExtensionSystem::Get(profile)->extension_service(); | 128 extensions::ExtensionSystem::Get(profile)->extension_service(); |
123 extensions::ExtensionRegistry* registry = | 129 extensions::ExtensionRegistry* registry = |
124 extensions::ExtensionRegistry::Get(profile); | 130 extensions::ExtensionRegistry::Get(profile); |
125 service->set_show_extensions_prompts(false); | 131 service->set_show_extensions_prompts(false); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 iter != errors->end(); ++iter) | 175 iter != errors->end(); ++iter) |
170 VLOG(1) << *iter; | 176 VLOG(1) << *iter; |
171 | 177 |
172 return NULL; | 178 return NULL; |
173 } | 179 } |
174 | 180 |
175 if (!observer_->WaitForExtensionViewsToLoad()) | 181 if (!observer_->WaitForExtensionViewsToLoad()) |
176 return NULL; | 182 return NULL; |
177 return service->GetExtensionById(last_loaded_extension_id(), false); | 183 return service->GetExtensionById(last_loaded_extension_id(), false); |
178 } | 184 } |
OLD | NEW |