Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: chrome/browser/extensions/extension_browsertest.cc

Issue 5543001: Tests for incognito app install, plus some cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make PackExtension return FilePath and change ASSERTs to ADD_FAILURES Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 FilePath ExtensionBrowserTest::PackExtension(const FilePath& dir_path) {
107 FilePath crx_path;
108 if (!PathService::Get(base::DIR_TEMP, &crx_path)) {
109 ADD_FAILURE() << "Failed to get DIR_TEMP from PathService.";
110 return FilePath();
111 }
112 crx_path = crx_path.AppendASCII("temp.crx");
113 if (!file_util::Delete(crx_path, false)) {
114 ADD_FAILURE() << "Failed to delete crx: " << crx_path.value();
115 return FilePath();
116 }
117
118 FilePath pem_path = crx_path.DirName().AppendASCII("temp.pem");
119 if (!file_util::Delete(pem_path, false)) {
120 ADD_FAILURE() << "Failed to delete pem: " << pem_path.value();
121 return FilePath();
122 }
123
124 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
125 if (!creator->Run(dir_path,
126 crx_path,
127 FilePath(), // no existing pem, use empty path
128 pem_path)) {
129 ADD_FAILURE() << "ExtensionCreator::Run() failed.";
130 return FilePath();
131 }
132
133 if (!file_util::PathExists(crx_path)) {
134 ADD_FAILURE() << crx_path.value() << " was not created.";
135 return FilePath();
136 }
137 return crx_path;
138 }
139
104 // This class is used to simulate an installation abort by the user. 140 // This class is used to simulate an installation abort by the user.
105 class MockAbortExtensionInstallUI : public ExtensionInstallUI { 141 class MockAbortExtensionInstallUI : public ExtensionInstallUI {
106 public: 142 public:
107 MockAbortExtensionInstallUI() : ExtensionInstallUI(NULL) {} 143 MockAbortExtensionInstallUI() : ExtensionInstallUI(NULL) {}
108 144
109 // Simulate a user abort on an extension installation. 145 // Simulate a user abort on an extension installation.
110 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { 146 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) {
111 delegate->InstallUIAbort(); 147 delegate->InstallUIAbort();
112 MessageLoopForUI::current()->Quit(); 148 MessageLoopForUI::current()->Quit();
113 } 149 }
114 150
115 virtual void ConfirmUninstall(Delegate* delegate, 151 virtual void ConfirmUninstall(Delegate* delegate,
116 const Extension* extension) {} 152 const Extension* extension) {}
117 153
118 virtual void OnInstallSuccess(const Extension* extension) {} 154 virtual void OnInstallSuccess(const Extension* extension) {}
119 155
120 virtual void OnInstallFailure(const std::string& error) {} 156 virtual void OnInstallFailure(const std::string& error) {}
121 }; 157 };
122 158
159 class MockAutoConfirmExtensionInstallUI : public ExtensionInstallUI {
160 public:
161 MockAutoConfirmExtensionInstallUI(Profile* profile) :
162 ExtensionInstallUI(profile) {}
163
164 // Proceed without confirmation prompt.
165 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) {
166 delegate->InstallUIProceed();
167 }
168 };
169
123 bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id, 170 bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id,
124 const FilePath& path, 171 const FilePath& path,
125 InstallUIType ui_type, 172 InstallUIType ui_type,
126 int expected_change) { 173 int expected_change) {
127 ExtensionService* service = browser()->profile()->GetExtensionService(); 174 return InstallOrUpdateExtension(id, path, ui_type, expected_change,
175 browser()->profile());
176 }
177
178 bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id,
179 const FilePath& path,
180 InstallUIType ui_type,
181 int expected_change,
182 Profile* profile) {
183 ExtensionService* service = profile->GetExtensionService();
128 service->set_show_extensions_prompts(false); 184 service->set_show_extensions_prompts(false);
129 size_t num_before = service->extensions()->size(); 185 size_t num_before = service->extensions()->size();
130 186
131 { 187 {
132 NotificationRegistrar registrar; 188 NotificationRegistrar registrar;
133 registrar.Add(this, NotificationType::EXTENSION_LOADED, 189 registrar.Add(this, NotificationType::EXTENSION_LOADED,
134 NotificationService::AllSources()); 190 NotificationService::AllSources());
135 registrar.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, 191 registrar.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED,
136 NotificationService::AllSources()); 192 NotificationService::AllSources());
137 registrar.Add(this, NotificationType::EXTENSION_INSTALL_ERROR, 193 registrar.Add(this, NotificationType::EXTENSION_INSTALL_ERROR,
138 NotificationService::AllSources()); 194 NotificationService::AllSources());
139 195
140 ExtensionInstallUI* install_ui = NULL; 196 ExtensionInstallUI* install_ui = NULL;
141 if (ui_type == INSTALL_UI_TYPE_CANCEL) 197 if (ui_type == INSTALL_UI_TYPE_CANCEL)
142 install_ui = new MockAbortExtensionInstallUI(); 198 install_ui = new MockAbortExtensionInstallUI();
143 else if (ui_type == INSTALL_UI_TYPE_NORMAL) 199 else if (ui_type == INSTALL_UI_TYPE_NORMAL)
144 install_ui = new ExtensionInstallUI(browser()->profile()); 200 install_ui = new ExtensionInstallUI(profile);
201 else if (ui_type == INSTALL_UI_TYPE_AUTO_CONFIRM)
202 install_ui = new MockAutoConfirmExtensionInstallUI(profile);
203
204 // TODO(tessamac): Update callers to always pass an unpacked extension
205 // and then always pack the extension here.
206 FilePath crx_path = path;
207 if (crx_path.Extension() != FILE_PATH_LITERAL(".crx")) {
208 crx_path = PackExtension(path);
209 }
210 if (crx_path.empty())
211 return false;
145 212
146 scoped_refptr<CrxInstaller> installer( 213 scoped_refptr<CrxInstaller> installer(
147 new CrxInstaller(service, install_ui)); 214 new CrxInstaller(service, install_ui));
148 installer->set_expected_id(id); 215 installer->set_expected_id(id);
149 installer->InstallCrx(path); 216 installer->InstallCrx(crx_path);
150 217
151 ui_test_utils::RunMessageLoop(); 218 ui_test_utils::RunMessageLoop();
152 } 219 }
153 220
154 size_t num_after = service->extensions()->size(); 221 size_t num_after = service->extensions()->size();
155 if (num_after != (num_before + expected_change)) { 222 if (num_after != (num_before + expected_change)) {
156 VLOG(1) << "Num extensions before: " << base::IntToString(num_before) 223 VLOG(1) << "Num extensions before: " << base::IntToString(num_before)
157 << " num after: " << base::IntToString(num_after) 224 << " num after: " << base::IntToString(num_after)
158 << " Installed extensions follow:"; 225 << " Installed extensions follow:";
159 226
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 MessageLoopForUI::current()->Quit(); 417 MessageLoopForUI::current()->Quit();
351 } 418 }
352 break; 419 break;
353 } 420 }
354 421
355 default: 422 default:
356 NOTREACHED(); 423 NOTREACHED();
357 break; 424 break;
358 } 425 }
359 } 426 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.h ('k') | chrome/browser/extensions/extension_install_ui_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698