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

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

Issue 10448037: Fix regression when off-store install is disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/download/download_crx_util.h" 5 #include "chrome/browser/download/download_crx_util.h"
6 #include "chrome/browser/download/download_service.h" 6 #include "chrome/browser/download/download_service.h"
7 #include "chrome/browser/download/download_service_factory.h" 7 #include "chrome/browser/download/download_service_factory.h"
8 #include "chrome/browser/download/download_test_observer.h" 8 #include "chrome/browser/download/download_test_observer.h"
9 #include "chrome/browser/extensions/crx_installer.h" 9 #include "chrome/browser/extensions/crx_installer.h"
10 #include "chrome/browser/extensions/extension_browsertest.h" 10 #include "chrome/browser/extensions/extension_browsertest.h"
11 #include "chrome/browser/extensions/extension_install_ui.h" 11 #include "chrome/browser/extensions/extension_install_ui.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/extensions/extension_file_util.h" 16 #include "chrome/common/extensions/extension_file_util.h"
17 #include "chrome/common/extensions/extension_switch_utils.h" 17 #include "chrome/common/extensions/extension_switch_utils.h"
18 #include "chrome/test/base/ui_test_utils.h" 18 #include "chrome/test/base/ui_test_utils.h"
19 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h"
19 21
20 class SkBitmap; 22 class SkBitmap;
21 23
22 namespace { 24 namespace {
23 25
24 // Observer waits for exactly one download to finish. 26 // Observer waits for exactly one download to finish.
25 27
26 class MockInstallUI : public ExtensionInstallUI { 28 class MockInstallUI : public ExtensionInstallUI {
27 public: 29 public:
28 explicit MockInstallUI(Profile* profile) : 30 explicit MockInstallUI(Profile* profile) :
29 ExtensionInstallUI(profile), confirmation_requested_(false) {} 31 ExtensionInstallUI(profile),
32 did_succeed_(false),
33 confirmation_requested_(false) {}
30 34
31 // Did the Delegate request confirmation? 35 bool did_succeed() const { return did_succeed_; }
32 bool confirmation_requested() { return confirmation_requested_; } 36 bool confirmation_requested() const { return confirmation_requested_; }
37 const string16& error() const { return error_; }
33 38
34 // Overriding some of the ExtensionInstallUI API. 39 // Overriding some of the ExtensionInstallUI API.
35 void ConfirmInstall(Delegate* delegate, 40 void ConfirmInstall(Delegate* delegate,
36 const extensions::Extension* extension) { 41 const extensions::Extension* extension) {
37 confirmation_requested_ = true; 42 confirmation_requested_ = true;
38 delegate->InstallUIProceed(); 43 delegate->InstallUIProceed();
39 } 44 }
40 void OnInstallSuccess(const extensions::Extension* extension, 45 void OnInstallSuccess(const extensions::Extension* extension,
41 SkBitmap* icon) { 46 SkBitmap* icon) {
47 did_succeed_ = true;
42 MessageLoopForUI::current()->Quit(); 48 MessageLoopForUI::current()->Quit();
43 } 49 }
44 void OnInstallFailure(const string16& error) { 50 void OnInstallFailure(const string16& error) {
45 ADD_FAILURE() << "install failed"; 51 error_ = error;
46 MessageLoopForUI::current()->Quit(); 52 MessageLoopForUI::current()->Quit();
47 } 53 }
48 54
49 private: 55 private:
56 bool did_succeed_;
50 bool confirmation_requested_; 57 bool confirmation_requested_;
58 string16 error_;
51 }; 59 };
52 60
53 } // namespace 61 } // namespace
54 62
55 class ExtensionCrxInstallerTest : public ExtensionBrowserTest { 63 class ExtensionCrxInstallerTest : public ExtensionBrowserTest {
56 public: 64 public:
57 // Installs a crx from |crx_relpath| (a path relative to the extension test 65 // Installs a crx from |crx_relpath| (a path relative to the extension test
58 // data dir) with expected id |id|. Returns whether a confirmation prompt 66 // data dir) with expected id |id|. Returns whether a confirmation prompt
59 // happened or not. 67 // happened or not.
60 bool DidWhitelistInstallPrompt(const std::string& ext_relpath, 68 bool DidWhitelistInstallPrompt(const std::string& ext_relpath,
(...skipping 16 matching lines...) Expand all
77 85
78 scoped_refptr<CrxInstaller> installer( 86 scoped_refptr<CrxInstaller> installer(
79 CrxInstaller::Create(service, 87 CrxInstaller::Create(service,
80 mock_install_ui, /* ownership transferred */ 88 mock_install_ui, /* ownership transferred */
81 approval.get() /* keep ownership */)); 89 approval.get() /* keep ownership */));
82 installer->set_allow_silent_install(true); 90 installer->set_allow_silent_install(true);
83 installer->set_is_gallery_install(true); 91 installer->set_is_gallery_install(true);
84 installer->InstallCrx(PackExtension(ext_path)); 92 installer->InstallCrx(PackExtension(ext_path));
85 ui_test_utils::RunMessageLoop(); 93 ui_test_utils::RunMessageLoop();
86 94
95 EXPECT_TRUE(mock_install_ui->did_succeed());
87 return mock_install_ui->confirmation_requested(); 96 return mock_install_ui->confirmation_requested();
88 } 97 }
89 }; 98 };
90 99
91 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Whitelisting) { 100 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Whitelisting) {
92 #if !defined(OS_CHROMEOS) 101 #if !defined(OS_CHROMEOS)
93 std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd"; 102 std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd";
94 ExtensionService* service = browser()->profile()->GetExtensionService(); 103 ExtensionService* service = browser()->profile()->GetExtensionService();
95 104
96 // Even whitelisted extensions with NPAPI should not prompt. 105 // Even whitelisted extensions with NPAPI should not prompt.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 164 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
156 LOG(ERROR) << "PackAndInstallExtension: Navigating to URL"; 165 LOG(ERROR) << "PackAndInstallExtension: Navigating to URL";
157 ui_test_utils::NavigateToURLWithDisposition(browser(), url, CURRENT_TAB, 166 ui_test_utils::NavigateToURLWithDisposition(browser(), url, CURRENT_TAB,
158 ui_test_utils::BROWSER_TEST_NONE); 167 ui_test_utils::BROWSER_TEST_NONE);
159 168
160 EXPECT_TRUE(WaitForExtensionInstall()); 169 EXPECT_TRUE(WaitForExtensionInstall());
161 LOG(ERROR) << "PackAndInstallExtension: Extension install"; 170 LOG(ERROR) << "PackAndInstallExtension: Extension install";
162 EXPECT_TRUE(mock_ui->confirmation_requested()); 171 EXPECT_TRUE(mock_ui->confirmation_requested());
163 LOG(ERROR) << "PackAndInstallExtension: Extension install confirmed"; 172 LOG(ERROR) << "PackAndInstallExtension: Extension install confirmed";
164 } 173 }
174
175 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, AllowOffStore) {
176 ExtensionService* service = browser()->profile()->GetExtensionService();
177
178 const bool kTestData[] = {false, true};
179
180 for (size_t i = 0; i < arraysize(kTestData); ++i) {
181 MockInstallUI* mock_ui = new MockInstallUI(browser()->profile());
182 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
183 switches::kEnableOffStoreExtensionInstall, "0");
184 scoped_refptr<CrxInstaller> crx_installer(
185 CrxInstaller::Create(service, mock_ui));
186 if (kTestData[i])
187 crx_installer->set_allow_off_store_install(true);
Yoyo Zhou 2012/05/29 18:28:55 set_allow_off_store_install(kTestData[i]);
188
189 crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx"));
190 EXPECT_EQ(kTestData[i], WaitForExtensionInstall()) << kTestData[i];
191 EXPECT_EQ(kTestData[i], mock_ui->did_succeed());
192 EXPECT_EQ(kTestData[i], mock_ui->confirmation_requested()) << kTestData[i];
193 if (kTestData[i]) {
194 EXPECT_EQ(string16(), mock_ui->error()) << kTestData[i];
195 } else {
196 EXPECT_EQ(l10n_util::GetStringUTF16(
197 IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE),
198 mock_ui->error()) << kTestData[i];
199 }
200 }
201 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer.cc ('k') | chrome/browser/ui/webui/extensions/install_extension_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698