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

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

Issue 10699057: Move application creation and extension install prompt showing off Browser and onto ExtensionTabHel… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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_prompt.h" 11 #include "chrome/browser/extensions/extension_install_prompt.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/browser/ui/browser_window.h"
15 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/extension_file_util.h" 18 #include "chrome/common/extensions/extension_file_util.h"
18 #include "chrome/common/extensions/extension_switch_utils.h" 19 #include "chrome/common/extensions/extension_switch_utils.h"
19 #include "chrome/common/extensions/permissions/permission_set.h" 20 #include "chrome/common/extensions/permissions/permission_set.h"
20 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
21 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 24
24 class SkBitmap; 25 class SkBitmap;
25 26
26 using extensions::Extension; 27 using extensions::Extension;
27 28
28 namespace { 29 namespace {
29 30
30 // Observer waits for exactly one download to finish. 31 // Observer waits for exactly one download to finish.
31 32
32 class MockInstallPrompt : public ExtensionInstallPrompt { 33 class MockInstallPrompt : public ExtensionInstallPrompt {
33 public: 34 public:
34 explicit MockInstallPrompt(Browser* browser) : 35 explicit MockInstallPrompt(gfx::NativeWindow parent,
35 ExtensionInstallPrompt(browser), 36 content::PageNavigator* navigator,
37 Profile* profile) :
38 ExtensionInstallPrompt(parent, navigator, profile),
36 confirmation_requested_(false), 39 confirmation_requested_(false),
37 extension_(NULL) {} 40 extension_(NULL) {}
38 41
39 bool did_succeed() const { return !!extension_; } 42 bool did_succeed() const { return !!extension_; }
40 const Extension* extension() const { return extension_; } 43 const Extension* extension() const { return extension_; }
41 bool confirmation_requested() const { return confirmation_requested_; } 44 bool confirmation_requested() const { return confirmation_requested_; }
42 const string16& error() const { return error_; } 45 const string16& error() const { return error_; }
43 void set_record_oauth2_grant(bool record) { record_oauth2_grant_ = record; } 46 void set_record_oauth2_grant(bool record) { record_oauth2_grant_ = record; }
44 47
45 // Overriding some of the ExtensionInstallUI API. 48 // Overriding some of the ExtensionInstallUI API.
(...skipping 11 matching lines...) Expand all
57 error_ = error.message(); 60 error_ = error.message();
58 MessageLoopForUI::current()->Quit(); 61 MessageLoopForUI::current()->Quit();
59 } 62 }
60 63
61 private: 64 private:
62 bool confirmation_requested_; 65 bool confirmation_requested_;
63 string16 error_; 66 string16 error_;
64 const Extension* extension_; 67 const Extension* extension_;
65 }; 68 };
66 69
70 MockInstallPrompt* CreateMockInstallPromptForBrowser(Browser* browser) {
71 gfx::NativeWindow parent =
72 browser->window() ? browser->window()->GetNativeWindow() : NULL;
73 return new MockInstallPrompt(parent, browser, browser->profile());
74 }
75
67 } // namespace 76 } // namespace
68 77
69 class ExtensionCrxInstallerTest : public ExtensionBrowserTest { 78 class ExtensionCrxInstallerTest : public ExtensionBrowserTest {
70 public: 79 public:
71 // Installs a crx from |crx_relpath| (a path relative to the extension test 80 // Installs a crx from |crx_relpath| (a path relative to the extension test
72 // data dir) with expected id |id|. Returns the installer. 81 // data dir) with expected id |id|. Returns the installer.
73 scoped_refptr<CrxInstaller> InstallWithPrompt( 82 scoped_refptr<CrxInstaller> InstallWithPrompt(
74 const std::string& ext_relpath, 83 const std::string& ext_relpath,
75 const std::string& id, 84 const std::string& id,
76 MockInstallPrompt* mock_install_prompt) { 85 MockInstallPrompt* mock_install_prompt) {
(...skipping 29 matching lines...) Expand all
106 115
107 // Installs an extension and checks that it has scopes granted IFF 116 // Installs an extension and checks that it has scopes granted IFF
108 // |record_oauth2_grant| is true. 117 // |record_oauth2_grant| is true.
109 void CheckHasEmptyScopesAfterInstall(const std::string& ext_relpath, 118 void CheckHasEmptyScopesAfterInstall(const std::string& ext_relpath,
110 bool record_oauth2_grant) { 119 bool record_oauth2_grant) {
111 CommandLine::ForCurrentProcess()->AppendSwitch( 120 CommandLine::ForCurrentProcess()->AppendSwitch(
112 switches::kEnableExperimentalExtensionApis); 121 switches::kEnableExperimentalExtensionApis);
113 122
114 ExtensionService* service = browser()->profile()->GetExtensionService(); 123 ExtensionService* service = browser()->profile()->GetExtensionService();
115 124
116 MockInstallPrompt* mock_prompt = new MockInstallPrompt(browser()); 125 MockInstallPrompt* mock_prompt =
126 CreateMockInstallPromptForBrowser(browser());
117 mock_prompt->set_record_oauth2_grant(record_oauth2_grant); 127 mock_prompt->set_record_oauth2_grant(record_oauth2_grant);
118 scoped_refptr<CrxInstaller> installer = 128 scoped_refptr<CrxInstaller> installer =
119 InstallWithPrompt("browsertest/scopes", std::string(), mock_prompt); 129 InstallWithPrompt("browsertest/scopes", std::string(), mock_prompt);
120 130
121 scoped_refptr<extensions::PermissionSet> permissions = 131 scoped_refptr<extensions::PermissionSet> permissions =
122 service->extension_prefs()->GetGrantedPermissions( 132 service->extension_prefs()->GetGrantedPermissions(
123 mock_prompt->extension()->id()); 133 mock_prompt->extension()->id());
124 ASSERT_TRUE(permissions.get()); 134 ASSERT_TRUE(permissions.get());
125 EXPECT_NE(record_oauth2_grant, permissions->scopes().empty()); 135 EXPECT_NE(record_oauth2_grant, permissions->scopes().empty());
126 } 136 }
127 }; 137 };
128 138
129 #if defined(OS_CHROMEOS) 139 #if defined(OS_CHROMEOS)
130 #define MAYBE_Whitelisting DISABLED_Whitelisting 140 #define MAYBE_Whitelisting DISABLED_Whitelisting
131 #else 141 #else
132 #define MAYBE_Whitelisting Whitelisting 142 #define MAYBE_Whitelisting Whitelisting
133 #endif 143 #endif
134 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, MAYBE_Whitelisting) { 144 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, MAYBE_Whitelisting) {
135 std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd"; 145 std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd";
136 ExtensionService* service = browser()->profile()->GetExtensionService(); 146 ExtensionService* service = browser()->profile()->GetExtensionService();
137 147
138 // Even whitelisted extensions with NPAPI should not prompt. 148 // Even whitelisted extensions with NPAPI should not prompt.
139 MockInstallPrompt* mock_prompt = new MockInstallPrompt(browser()); 149 MockInstallPrompt* mock_prompt =
150 CreateMockInstallPromptForBrowser(browser());
140 scoped_refptr<CrxInstaller> installer = 151 scoped_refptr<CrxInstaller> installer =
141 InstallWithPrompt("uitest/plugins", id, mock_prompt); 152 InstallWithPrompt("uitest/plugins", id, mock_prompt);
142 EXPECT_FALSE(mock_prompt->confirmation_requested()); 153 EXPECT_FALSE(mock_prompt->confirmation_requested());
143 EXPECT_TRUE(service->GetExtensionById(id, false)); 154 EXPECT_TRUE(service->GetExtensionById(id, false));
144 } 155 }
145 156
146 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, 157 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
147 GalleryInstallGetsExperimental) { 158 GalleryInstallGetsExperimental) {
148 // We must modify the command line temporarily in order to pack an extension 159 // We must modify the command line temporarily in order to pack an extension
149 // that requests the experimental permission. 160 // that requests the experimental permission.
(...skipping 26 matching lines...) Expand all
176 const int kNumDownloadsExpected = 1; 187 const int kNumDownloadsExpected = 1;
177 const bool kExpectFileSelectDialog = false; 188 const bool kExpectFileSelectDialog = false;
178 189
179 LOG(ERROR) << "PackAndInstallExtension: Packing extension"; 190 LOG(ERROR) << "PackAndInstallExtension: Packing extension";
180 FilePath crx_path = PackExtension( 191 FilePath crx_path = PackExtension(
181 test_data_dir_.AppendASCII("common/background_page")); 192 test_data_dir_.AppendASCII("common/background_page"));
182 ASSERT_FALSE(crx_path.empty()); 193 ASSERT_FALSE(crx_path.empty());
183 std::string crx_path_string(crx_path.value().begin(), crx_path.value().end()); 194 std::string crx_path_string(crx_path.value().begin(), crx_path.value().end());
184 GURL url = GURL(std::string("file:///").append(crx_path_string)); 195 GURL url = GURL(std::string("file:///").append(crx_path_string));
185 196
186 MockInstallPrompt* mock_prompt = new MockInstallPrompt(browser()); 197 MockInstallPrompt* mock_prompt =
198 CreateMockInstallPromptForBrowser(browser());
187 download_crx_util::SetMockInstallPromptForTesting(mock_prompt); 199 download_crx_util::SetMockInstallPromptForTesting(mock_prompt);
188 200
189 LOG(ERROR) << "PackAndInstallExtension: Getting download manager"; 201 LOG(ERROR) << "PackAndInstallExtension: Getting download manager";
190 content::DownloadManager* download_manager = 202 content::DownloadManager* download_manager =
191 content::BrowserContext::GetDownloadManager(browser()->profile()); 203 content::BrowserContext::GetDownloadManager(browser()->profile());
192 204
193 LOG(ERROR) << "PackAndInstallExtension: Setting observer"; 205 LOG(ERROR) << "PackAndInstallExtension: Setting observer";
194 scoped_ptr<DownloadTestObserver> observer( 206 scoped_ptr<DownloadTestObserver> observer(
195 new DownloadTestObserverTerminal( 207 new DownloadTestObserverTerminal(
196 download_manager, kNumDownloadsExpected, kExpectFileSelectDialog, 208 download_manager, kNumDownloadsExpected, kExpectFileSelectDialog,
(...skipping 24 matching lines...) Expand all
221 #if defined(USE_AURA) 233 #if defined(USE_AURA)
222 #define MAYBE_AllowOffStore DISABLED_AllowOffStore 234 #define MAYBE_AllowOffStore DISABLED_AllowOffStore
223 #else 235 #else
224 #define MAYBE_AllowOffStore AllowOffStore 236 #define MAYBE_AllowOffStore AllowOffStore
225 #endif 237 #endif
226 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, MAYBE_AllowOffStore) { 238 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, MAYBE_AllowOffStore) {
227 ExtensionService* service = browser()->profile()->GetExtensionService(); 239 ExtensionService* service = browser()->profile()->GetExtensionService();
228 const bool kTestData[] = {false, true}; 240 const bool kTestData[] = {false, true};
229 241
230 for (size_t i = 0; i < arraysize(kTestData); ++i) { 242 for (size_t i = 0; i < arraysize(kTestData); ++i) {
231 MockInstallPrompt* mock_prompt = new MockInstallPrompt(browser()); 243 MockInstallPrompt* mock_prompt =
244 CreateMockInstallPromptForBrowser(browser());
232 scoped_refptr<CrxInstaller> crx_installer( 245 scoped_refptr<CrxInstaller> crx_installer(
233 CrxInstaller::Create(service, mock_prompt)); 246 CrxInstaller::Create(service, mock_prompt));
234 crx_installer->set_install_cause( 247 crx_installer->set_install_cause(
235 extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); 248 extension_misc::INSTALL_CAUSE_USER_DOWNLOAD);
236 249
237 if (kTestData[i]) { 250 if (kTestData[i]) {
238 crx_installer->set_off_store_install_allow_reason( 251 crx_installer->set_off_store_install_allow_reason(
239 CrxInstaller::OffStoreInstallAllowedInTest); 252 CrxInstaller::OffStoreInstallAllowedInTest);
240 } 253 }
241 254
242 crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx")); 255 crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx"));
243 EXPECT_EQ(kTestData[i], WaitForExtensionInstall()) << kTestData[i]; 256 EXPECT_EQ(kTestData[i], WaitForExtensionInstall()) << kTestData[i];
244 EXPECT_EQ(kTestData[i], mock_prompt->did_succeed()); 257 EXPECT_EQ(kTestData[i], mock_prompt->did_succeed());
245 EXPECT_EQ(kTestData[i], mock_prompt->confirmation_requested()) << 258 EXPECT_EQ(kTestData[i], mock_prompt->confirmation_requested()) <<
246 kTestData[i]; 259 kTestData[i];
247 if (kTestData[i]) { 260 if (kTestData[i]) {
248 EXPECT_EQ(string16(), mock_prompt->error()) << kTestData[i]; 261 EXPECT_EQ(string16(), mock_prompt->error()) << kTestData[i];
249 } else { 262 } else {
250 EXPECT_EQ(l10n_util::GetStringUTF16( 263 EXPECT_EQ(l10n_util::GetStringUTF16(
251 IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE), 264 IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE),
252 mock_prompt->error()) << kTestData[i]; 265 mock_prompt->error()) << kTestData[i];
253 } 266 }
254 } 267 }
255 } 268 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/bundle_installer.cc ('k') | chrome/browser/extensions/extension_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698