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

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

Issue 1752293002: The command line flag is now set during the test startup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/experimental.crx » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/extensions/crx_installer.h" 5 #include "chrome/browser/extensions/crx_installer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 return "ManagementPolicyMock"; 196 return "ManagementPolicyMock";
197 } 197 }
198 198
199 bool UserMayLoad(const Extension* extension, 199 bool UserMayLoad(const Extension* extension,
200 base::string16* error) const override { 200 base::string16* error) const override {
201 *error = base::UTF8ToUTF16("Dummy error message"); 201 *error = base::UTF8ToUTF16("Dummy error message");
202 return false; 202 return false;
203 } 203 }
204 }; 204 };
205 205
206 // Appends "enable-experimental-extension-apis" to the command line for the
207 // lifetime of this class.
208 class ScopedExperimentalCommandLine {
209 public:
210 ScopedExperimentalCommandLine()
211 : saved_(*base::CommandLine::ForCurrentProcess()) {
212 base::CommandLine::ForCurrentProcess()->AppendSwitch(
213 switches::kEnableExperimentalExtensionApis);
214 }
215
216 ~ScopedExperimentalCommandLine() {
217 *base::CommandLine::ForCurrentProcess() = saved_;
218 }
219
220 private:
221 base::CommandLine saved_;
222 };
223
224 } // namespace 206 } // namespace
225 207
226 class ExtensionCrxInstallerTest : public ExtensionBrowserTest { 208 class ExtensionCrxInstallerTest : public ExtensionBrowserTest {
227 protected: 209 protected:
228 scoped_ptr<WebstoreInstaller::Approval> GetApproval( 210 scoped_ptr<WebstoreInstaller::Approval> GetApproval(
229 const char* manifest_dir, 211 const char* manifest_dir,
230 const std::string& id, 212 const std::string& id,
231 bool strict_manifest_checks) { 213 bool strict_manifest_checks) {
232 scoped_ptr<WebstoreInstaller::Approval> result; 214 scoped_ptr<WebstoreInstaller::Approval> result;
233 215
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 RunCrxInstaller(approval.get(), mock_install_prompt->CreatePrompt(), 254 RunCrxInstaller(approval.get(), mock_install_prompt->CreatePrompt(),
273 crx_path); 255 crx_path);
274 256
275 EXPECT_TRUE(mock_install_prompt->did_succeed()); 257 EXPECT_TRUE(mock_install_prompt->did_succeed());
276 } 258 }
277 259
278 // Installs an extension and checks that it has scopes granted IFF 260 // Installs an extension and checks that it has scopes granted IFF
279 // |record_oauth2_grant| is true. 261 // |record_oauth2_grant| is true.
280 void CheckHasEmptyScopesAfterInstall(const std::string& ext_relpath, 262 void CheckHasEmptyScopesAfterInstall(const std::string& ext_relpath,
281 bool record_oauth2_grant) { 263 bool record_oauth2_grant) {
282 ScopedExperimentalCommandLine scope;
283
284 scoped_ptr<MockPromptProxy> mock_prompt = 264 scoped_ptr<MockPromptProxy> mock_prompt =
285 CreateMockPromptProxyForBrowser(browser()); 265 CreateMockPromptProxyForBrowser(browser());
286 266
287 InstallWithPrompt("browsertest/scopes", std::string(), mock_prompt.get()); 267 InstallWithPrompt("browsertest/scopes", std::string(), mock_prompt.get());
288 268
289 scoped_ptr<const PermissionSet> permissions = 269 scoped_ptr<const PermissionSet> permissions =
290 ExtensionPrefs::Get(browser()->profile()) 270 ExtensionPrefs::Get(browser()->profile())
291 ->GetGrantedPermissions(mock_prompt->extension_id()); 271 ->GetGrantedPermissions(mock_prompt->extension_id());
292 ASSERT_TRUE(permissions.get()); 272 ASSERT_TRUE(permissions.get());
293 } 273 }
294 274
295 // Returns a FilePath to an unpacked "experimental" extension (a test
296 // Extension which requests the "experimental" permission).
297 base::FilePath PackExperimentalExtension() {
298 // We must modify the command line temporarily in order to pack an
299 // extension that requests the experimental permission.
300 ScopedExperimentalCommandLine scope;
301 base::FilePath test_path = test_data_dir_.AppendASCII("experimental");
302 base::FilePath crx_path = PackExtension(test_path);
303 CHECK(!crx_path.empty()) << "Extension not found at " << test_path.value();
304 return crx_path;
305 }
306
307 void InstallWebAppAndVerifyNoErrors() { 275 void InstallWebAppAndVerifyNoErrors() {
308 ExtensionService* service = 276 ExtensionService* service =
309 extensions::ExtensionSystem::Get(browser()->profile()) 277 extensions::ExtensionSystem::Get(browser()->profile())
310 ->extension_service(); 278 ->extension_service();
311 scoped_refptr<CrxInstaller> crx_installer( 279 scoped_refptr<CrxInstaller> crx_installer(
312 CrxInstaller::CreateSilent(service)); 280 CrxInstaller::CreateSilent(service));
313 crx_installer->set_error_on_unsupported_requirements(true); 281 crx_installer->set_error_on_unsupported_requirements(true);
314 crx_installer->InstallWebApp( 282 crx_installer->InstallWebApp(
315 CreateWebAppInfo(kAppTitle, kAppDescription, kAppUrl, 64)); 283 CreateWebAppInfo(kAppTitle, kAppDescription, kAppUrl, 64));
316 EXPECT_TRUE(WaitForCrxInstallerDone()); 284 EXPECT_TRUE(WaitForCrxInstallerDone());
317 ASSERT_TRUE(crx_installer->extension()); 285 ASSERT_TRUE(crx_installer->extension());
318 ASSERT_FALSE(HasRequirementErrors(crx_installer.get())); 286 ASSERT_FALSE(HasRequirementErrors(crx_installer.get()));
319 ASSERT_FALSE(HasPolicyErrors(crx_installer.get())); 287 ASSERT_FALSE(HasPolicyErrors(crx_installer.get()));
320 } 288 }
321 289
322 bool HasRequirementErrors(CrxInstaller* crx_installer) { 290 bool HasRequirementErrors(CrxInstaller* crx_installer) {
323 return !crx_installer->install_checker_.requirement_errors().empty(); 291 return !crx_installer->install_checker_.requirement_errors().empty();
324 } 292 }
325 293
326 bool HasPolicyErrors(CrxInstaller* crx_installer) { 294 bool HasPolicyErrors(CrxInstaller* crx_installer) {
327 return !crx_installer->install_checker_.policy_error().empty(); 295 return !crx_installer->install_checker_.policy_error().empty();
328 } 296 }
329 }; 297 };
330 298
299 class ExtensionCrxInstallerTestWithExperimentalApis
300 : public ExtensionCrxInstallerTest {
301 protected:
302 void SetUpCommandLine(base::CommandLine* command_line) override {
303 ExtensionCrxInstallerTest::SetUpCommandLine(command_line);
304 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
305 }
306 };
307
331 // This test is skipped on ChromeOS because it requires the NPAPI, 308 // This test is skipped on ChromeOS because it requires the NPAPI,
332 // which is not available on that platform. 309 // which is not available on that platform.
333 #if !defined(OS_CHROMEOS) 310 #if !defined(OS_CHROMEOS)
334 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Whitelisting) { 311 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Whitelisting) {
335 std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd"; 312 std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd";
336 ExtensionRegistry* registry = ExtensionRegistry::Get( 313 ExtensionRegistry* registry = ExtensionRegistry::Get(
337 browser()->profile()); 314 browser()->profile());
338 315
339 // Even whitelisted extensions with NPAPI should not prompt. 316 // Even whitelisted extensions with NPAPI should not prompt.
340 scoped_ptr<MockPromptProxy> mock_prompt = 317 scoped_ptr<MockPromptProxy> mock_prompt =
341 CreateMockPromptProxyForBrowser(browser()); 318 CreateMockPromptProxyForBrowser(browser());
342 InstallWithPrompt("uitest/plugins", id, mock_prompt.get()); 319 InstallWithPrompt("uitest/plugins", id, mock_prompt.get());
343 EXPECT_FALSE(mock_prompt->confirmation_requested()); 320 EXPECT_FALSE(mock_prompt->confirmation_requested());
344 EXPECT_TRUE(registry->enabled_extensions().GetByID(id)); 321 EXPECT_TRUE(registry->enabled_extensions().GetByID(id));
345 } 322 }
346 #endif 323 #endif
347 324
348 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, 325 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
349 ExperimentalExtensionFromGallery) { 326 ExperimentalExtensionFromGallery) {
350 // Gallery-installed extensions should have their experimental permission 327 // Gallery-installed extensions should have their experimental permission
351 // preserved, since we allow the Webstore to make that decision. 328 // preserved, since we allow the Webstore to make that decision.
352 base::FilePath crx_path = PackExperimentalExtension(); 329 const Extension* extension = InstallExtensionFromWebstore(
353 const Extension* extension = InstallExtensionFromWebstore(crx_path, 1); 330 test_data_dir_.AppendASCII("experimental.crx"), 1);
354 ASSERT_TRUE(extension); 331 ASSERT_TRUE(extension);
355 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( 332 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
356 APIPermission::kExperimental)); 333 APIPermission::kExperimental));
357 } 334 }
358 335
359 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, 336 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
360 ExperimentalExtensionFromOutsideGallery) { 337 ExperimentalExtensionFromOutsideGallery) {
361 // Non-gallery-installed extensions should lose their experimental 338 // Non-gallery-installed extensions should lose their experimental
362 // permission if the flag isn't enabled. 339 // permission if the flag isn't enabled.
363 base::FilePath crx_path = PackExperimentalExtension(); 340 const Extension* extension = InstallExtension(
364 const Extension* extension = InstallExtension(crx_path, 1); 341 test_data_dir_.AppendASCII("experimental.crx"), 1);
365 ASSERT_TRUE(extension); 342 ASSERT_TRUE(extension);
366 EXPECT_FALSE(extension->permissions_data()->HasAPIPermission( 343 EXPECT_FALSE(extension->permissions_data()->HasAPIPermission(
367 APIPermission::kExperimental)); 344 APIPermission::kExperimental));
368 } 345 }
369 346
370 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, 347 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
371 ExperimentalExtensionFromOutsideGalleryWithFlag) { 348 ExperimentalExtensionFromOutsideGalleryWithFlag) {
372 // Non-gallery-installed extensions should maintain their experimental 349 // Non-gallery-installed extensions should maintain their experimental
373 // permission if the flag is enabled. 350 // permission if the flag is enabled.
374 base::FilePath crx_path = PackExperimentalExtension(); 351 const Extension* extension = InstallExtension(
375 ScopedExperimentalCommandLine scope; 352 test_data_dir_.AppendASCII("experimental.crx"), 1);
376 const Extension* extension = InstallExtension(crx_path, 1);
377 ASSERT_TRUE(extension); 353 ASSERT_TRUE(extension);
378 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( 354 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
379 APIPermission::kExperimental)); 355 APIPermission::kExperimental));
380 } 356 }
381 357
382 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, PlatformAppCrx) { 358 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
383 ScopedExperimentalCommandLine scope; 359 PlatformAppCrx) {
384 EXPECT_TRUE(InstallExtension( 360 EXPECT_TRUE(InstallExtension(
385 test_data_dir_.AppendASCII("minimal_platform_app.crx"), 1)); 361 test_data_dir_.AppendASCII("minimal_platform_app.crx"), 1));
386 } 362 }
387 363
388 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, PackAndInstallExtension) { 364 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, PackAndInstallExtension) {
389 if (!FeatureSwitch::easy_off_store_install()->IsEnabled()) 365 if (!FeatureSwitch::easy_off_store_install()->IsEnabled())
390 return; 366 return;
391 367
392 const int kNumDownloadsExpected = 1; 368 const int kNumDownloadsExpected = 1;
393 369
(...skipping 28 matching lines...) Expand all
422 LOG(ERROR) << "PackAndInstallExtension: Extension install confirmed"; 398 LOG(ERROR) << "PackAndInstallExtension: Extension install confirmed";
423 } 399 }
424 400
425 // Tests that scopes are only granted if |record_oauth2_grant_| on the prompt is 401 // Tests that scopes are only granted if |record_oauth2_grant_| on the prompt is
426 // true. 402 // true.
427 #if defined(OS_WIN) 403 #if defined(OS_WIN)
428 #define MAYBE_GrantScopes DISABLED_GrantScopes 404 #define MAYBE_GrantScopes DISABLED_GrantScopes
429 #else 405 #else
430 #define MAYBE_GrantScopes GrantScopes 406 #define MAYBE_GrantScopes GrantScopes
431 #endif 407 #endif
432 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, MAYBE_GrantScopes) { 408 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
409 MAYBE_GrantScopes) {
433 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes", 410 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes",
434 true)); 411 true));
435 } 412 }
436 413
437 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DoNotGrantScopes) { 414 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
415 DoNotGrantScopes) {
438 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes", 416 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes",
439 false)); 417 false));
440 } 418 }
441 419
442 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, AllowOffStore) { 420 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, AllowOffStore) {
443 ExtensionService* service = extensions::ExtensionSystem::Get( 421 ExtensionService* service = extensions::ExtensionSystem::Get(
444 browser()->profile())->extension_service(); 422 browser()->profile())->extension_service();
445 const bool kTestData[] = {false, true}; 423 const bool kTestData[] = {false, true};
446 424
447 for (size_t i = 0; i < arraysize(kTestData); ++i) { 425 for (size_t i = 0; i < arraysize(kTestData); ++i) {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 EXPECT_TRUE(WaitForCrxInstallerDone()); 706 EXPECT_TRUE(WaitForCrxInstallerDone());
729 const Extension* extension = installer->extension(); 707 const Extension* extension = installer->extension();
730 ASSERT_TRUE(extension); 708 ASSERT_TRUE(extension);
731 ASSERT_EQ(extension_id, extension->id()); 709 ASSERT_EQ(extension_id, extension->id());
732 EXPECT_TRUE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id)); 710 EXPECT_TRUE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
733 EXPECT_TRUE(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS); 711 EXPECT_TRUE(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS);
734 } 712 }
735 } 713 }
736 714
737 } // namespace extensions 715 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/experimental.crx » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698