OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_browsertest.h" | 5 #include "chrome/browser/extensions/extension_browsertest.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | |
11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
12 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
13 #include "chrome/browser/browser_window.h" | 14 #include "chrome/browser/browser_window.h" |
14 #include "chrome/browser/extensions/crx_installer.h" | 15 #include "chrome/browser/extensions/crx_installer.h" |
16 #include "chrome/browser/extensions/extension_creator.h" | |
15 #include "chrome/browser/extensions/extension_error_reporter.h" | 17 #include "chrome/browser/extensions/extension_error_reporter.h" |
16 #include "chrome/browser/extensions/extension_host.h" | 18 #include "chrome/browser/extensions/extension_host.h" |
17 #include "chrome/browser/extensions/extension_install_ui.h" | 19 #include "chrome/browser/extensions/extension_install_ui.h" |
18 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
19 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/omnibox/location_bar.h" | 23 #include "chrome/browser/ui/omnibox/location_bar.h" |
22 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
23 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/notification_registrar.h" | 26 #include "chrome/common/notification_registrar.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 } | 96 } |
95 | 97 |
96 bool ExtensionBrowserTest::LoadExtension(const FilePath& path) { | 98 bool ExtensionBrowserTest::LoadExtension(const FilePath& path) { |
97 return LoadExtensionImpl(path, false); | 99 return LoadExtensionImpl(path, false); |
98 } | 100 } |
99 | 101 |
100 bool ExtensionBrowserTest::LoadExtensionIncognito(const FilePath& path) { | 102 bool ExtensionBrowserTest::LoadExtensionIncognito(const FilePath& path) { |
101 return LoadExtensionImpl(path, true); | 103 return LoadExtensionImpl(path, true); |
102 } | 104 } |
103 | 105 |
106 void ExtensionBrowserTest::PackExtension(const FilePath& dir_path, | |
107 FilePath* crx_path) { | |
108 // Init paths to output files and ensure files do not already exist. | |
109 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, crx_path)); | |
110 *crx_path = crx_path->AppendASCII("temp.crx"); | |
111 ASSERT_TRUE(file_util::Delete(*crx_path, false)); | |
Aaron Boodman
2010/12/15 22:29:18
You should double-check that this returns true in
Tessa MacDuff
2010/12/16 00:08:04
Done.
There is even a test that checks this: http
| |
112 FilePath pem_path = crx_path->DirName().AppendASCII("temp.pem"); | |
113 ASSERT_TRUE(file_util::Delete(pem_path, false)); | |
114 | |
115 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | |
116 ASSERT_TRUE(creator->Run(dir_path, | |
117 *crx_path, | |
118 FilePath(), // no existing pem, use empty path | |
119 pem_path)); | |
120 | |
121 ASSERT_TRUE(file_util::PathExists(*crx_path)); | |
122 } | |
123 | |
104 // This class is used to simulate an installation abort by the user. | 124 // This class is used to simulate an installation abort by the user. |
105 class MockAbortExtensionInstallUI : public ExtensionInstallUI { | 125 class MockAbortExtensionInstallUI : public ExtensionInstallUI { |
106 public: | 126 public: |
107 MockAbortExtensionInstallUI() : ExtensionInstallUI(NULL) {} | 127 MockAbortExtensionInstallUI() : ExtensionInstallUI(NULL) {} |
108 | 128 |
109 // Simulate a user abort on an extension installation. | 129 // Simulate a user abort on an extension installation. |
110 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { | 130 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { |
111 delegate->InstallUIAbort(); | 131 delegate->InstallUIAbort(); |
112 MessageLoopForUI::current()->Quit(); | 132 MessageLoopForUI::current()->Quit(); |
113 } | 133 } |
114 | 134 |
115 virtual void ConfirmUninstall(Delegate* delegate, | 135 virtual void ConfirmUninstall(Delegate* delegate, |
116 const Extension* extension) {} | 136 const Extension* extension) {} |
117 | 137 |
118 virtual void OnInstallSuccess(const Extension* extension) {} | 138 virtual void OnInstallSuccess(const Extension* extension) {} |
119 | 139 |
120 virtual void OnInstallFailure(const std::string& error) {} | 140 virtual void OnInstallFailure(const std::string& error) {} |
121 }; | 141 }; |
122 | 142 |
143 class MockAutoConfirmExtensionInstallUI : public ExtensionInstallUI { | |
144 public: | |
145 MockAutoConfirmExtensionInstallUI(Profile* profile) : | |
146 ExtensionInstallUI(profile) {} | |
147 | |
148 // Proceed without confirmation prompt. | |
149 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { | |
150 delegate->InstallUIProceed(); | |
151 } | |
152 }; | |
153 | |
123 bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id, | 154 bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id, |
124 const FilePath& path, | 155 const FilePath& path, |
125 InstallUIType ui_type, | 156 InstallUIType ui_type, |
126 int expected_change) { | 157 int expected_change) { |
127 ExtensionService* service = browser()->profile()->GetExtensionService(); | 158 return InstallOrUpdateExtension(id, path, ui_type, expected_change, |
159 browser()->profile()); | |
160 } | |
161 | |
162 bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id, | |
163 const FilePath& path, | |
164 InstallUIType ui_type, | |
165 int expected_change, | |
166 Profile* profile) { | |
167 ExtensionService* service = profile->GetExtensionService(); | |
128 service->set_show_extensions_prompts(false); | 168 service->set_show_extensions_prompts(false); |
129 size_t num_before = service->extensions()->size(); | 169 size_t num_before = service->extensions()->size(); |
130 | 170 |
131 { | 171 { |
132 NotificationRegistrar registrar; | 172 NotificationRegistrar registrar; |
133 registrar.Add(this, NotificationType::EXTENSION_LOADED, | 173 registrar.Add(this, NotificationType::EXTENSION_LOADED, |
134 NotificationService::AllSources()); | 174 NotificationService::AllSources()); |
135 registrar.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, | 175 registrar.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, |
136 NotificationService::AllSources()); | 176 NotificationService::AllSources()); |
137 registrar.Add(this, NotificationType::EXTENSION_INSTALL_ERROR, | 177 registrar.Add(this, NotificationType::EXTENSION_INSTALL_ERROR, |
138 NotificationService::AllSources()); | 178 NotificationService::AllSources()); |
139 | 179 |
140 ExtensionInstallUI* install_ui = NULL; | 180 ExtensionInstallUI* install_ui = NULL; |
141 if (ui_type == INSTALL_UI_TYPE_CANCEL) | 181 if (ui_type == INSTALL_UI_TYPE_CANCEL) |
142 install_ui = new MockAbortExtensionInstallUI(); | 182 install_ui = new MockAbortExtensionInstallUI(); |
143 else if (ui_type == INSTALL_UI_TYPE_NORMAL) | 183 else if (ui_type == INSTALL_UI_TYPE_NORMAL) |
144 install_ui = new ExtensionInstallUI(browser()->profile()); | 184 install_ui = new ExtensionInstallUI(profile); |
185 else if (ui_type == INSTALL_UI_TYPE_AUTO_CONFIRM) | |
186 install_ui = new MockAutoConfirmExtensionInstallUI(profile); | |
145 | 187 |
188 FilePath crx_path; | |
189 if (path.Extension() == FILE_PATH_LITERAL(".crx")) { | |
Aaron Boodman
2010/12/15 22:29:18
Can you fix all the callers so that we don't need
Tessa MacDuff
2010/12/16 00:08:04
Do you mind if I do it in a separate CL? I'll lea
Aaron Boodman
2011/01/14 20:58:43
No that is fine.
| |
190 crx_path = path; | |
191 } else { | |
192 PackExtension(path, &crx_path); | |
193 } | |
146 scoped_refptr<CrxInstaller> installer( | 194 scoped_refptr<CrxInstaller> installer( |
147 new CrxInstaller(service, install_ui)); | 195 new CrxInstaller(service, install_ui)); |
148 installer->set_expected_id(id); | 196 installer->set_expected_id(id); |
149 installer->InstallCrx(path); | 197 installer->InstallCrx(crx_path); |
150 | 198 |
151 ui_test_utils::RunMessageLoop(); | 199 ui_test_utils::RunMessageLoop(); |
152 } | 200 } |
153 | 201 |
154 size_t num_after = service->extensions()->size(); | 202 size_t num_after = service->extensions()->size(); |
155 if (num_after != (num_before + expected_change)) { | 203 if (num_after != (num_before + expected_change)) { |
156 VLOG(1) << "Num extensions before: " << base::IntToString(num_before) | 204 VLOG(1) << "Num extensions before: " << base::IntToString(num_before) |
157 << " num after: " << base::IntToString(num_after) | 205 << " num after: " << base::IntToString(num_after) |
158 << " Installed extensions follow:"; | 206 << " Installed extensions follow:"; |
159 | 207 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 MessageLoopForUI::current()->Quit(); | 398 MessageLoopForUI::current()->Quit(); |
351 } | 399 } |
352 break; | 400 break; |
353 } | 401 } |
354 | 402 |
355 default: | 403 default: |
356 NOTREACHED(); | 404 NOTREACHED(); |
357 break; | 405 break; |
358 } | 406 } |
359 } | 407 } |
OLD | NEW |