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

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

Issue 1527043002: [Extensions] Don't use ExtensionInstallPrompt subclasses for auto-confirmation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years 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
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/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/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 25 matching lines...) Expand all
36 #include "chrome/common/chrome_paths.h" 36 #include "chrome/common/chrome_paths.h"
37 #include "chrome/common/chrome_switches.h" 37 #include "chrome/common/chrome_switches.h"
38 #include "components/version_info/version_info.h" 38 #include "components/version_info/version_info.h"
39 #include "content/public/browser/navigation_controller.h" 39 #include "content/public/browser/navigation_controller.h"
40 #include "content/public/browser/navigation_entry.h" 40 #include "content/public/browser/navigation_entry.h"
41 #include "content/public/browser/notification_registrar.h" 41 #include "content/public/browser/notification_registrar.h"
42 #include "content/public/browser/notification_service.h" 42 #include "content/public/browser/notification_service.h"
43 #include "content/public/browser/render_view_host.h" 43 #include "content/public/browser/render_view_host.h"
44 #include "content/public/test/browser_test_utils.h" 44 #include "content/public/test/browser_test_utils.h"
45 #include "content/public/test/test_utils.h" 45 #include "content/public/test/test_utils.h"
46 #include "extensions/browser/extension_dialog_auto_confirm.h"
46 #include "extensions/browser/extension_host.h" 47 #include "extensions/browser/extension_host.h"
47 #include "extensions/browser/extension_prefs.h" 48 #include "extensions/browser/extension_prefs.h"
48 #include "extensions/browser/extension_registry.h" 49 #include "extensions/browser/extension_registry.h"
49 #include "extensions/browser/extension_system.h" 50 #include "extensions/browser/extension_system.h"
50 #include "extensions/browser/notification_types.h" 51 #include "extensions/browser/notification_types.h"
51 #include "extensions/browser/uninstall_reason.h" 52 #include "extensions/browser/uninstall_reason.h"
52 #include "extensions/common/constants.h" 53 #include "extensions/common/constants.h"
53 #include "extensions/common/extension_set.h" 54 #include "extensions/common/extension_set.h"
54 #include "sync/api/string_ordinal.h" 55 #include "sync/api/string_ordinal.h"
55 56
56 #if defined(OS_CHROMEOS) 57 #if defined(OS_CHROMEOS)
57 #include "chromeos/chromeos_switches.h" 58 #include "chromeos/chromeos_switches.h"
58 #endif 59 #endif
59 60
60 using extensions::Extension; 61 using extensions::Extension;
61 using extensions::ExtensionCreator; 62 using extensions::ExtensionCreator;
62 using extensions::ExtensionRegistry; 63 using extensions::ExtensionRegistry;
63 using extensions::FeatureSwitch; 64 using extensions::FeatureSwitch;
64 using extensions::Manifest; 65 using extensions::Manifest;
66 using extensions::ScopedTestDialogAutoConfirm;
65 67
66 ExtensionBrowserTest::ExtensionBrowserTest() 68 ExtensionBrowserTest::ExtensionBrowserTest()
67 : loaded_(false), 69 : loaded_(false),
68 installed_(false), 70 installed_(false),
69 #if defined(OS_CHROMEOS) 71 #if defined(OS_CHROMEOS)
70 set_chromeos_user_(true), 72 set_chromeos_user_(true),
71 #endif 73 #endif
72 // Default channel is STABLE but override with UNKNOWN so that unlaunched 74 // Default channel is STABLE but override with UNKNOWN so that unlaunched
73 // or incomplete APIs can write tests. 75 // or incomplete APIs can write tests.
74 current_channel_(version_info::Channel::UNKNOWN), 76 current_channel_(version_info::Channel::UNKNOWN),
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 return base::FilePath(); 373 return base::FilePath();
372 } 374 }
373 375
374 if (!base::PathExists(crx_path)) { 376 if (!base::PathExists(crx_path)) {
375 ADD_FAILURE() << crx_path.value() << " was not created."; 377 ADD_FAILURE() << crx_path.value() << " was not created.";
376 return base::FilePath(); 378 return base::FilePath();
377 } 379 }
378 return crx_path; 380 return crx_path;
379 } 381 }
380 382
381 // This class is used to simulate an installation abort by the user.
382 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt {
383 public:
384 MockAbortExtensionInstallPrompt() : ExtensionInstallPrompt(NULL) {
385 }
386
387 // Simulate a user abort on an extension installation.
388 void ShowDialog(Delegate* delegate,
389 const Extension* extension,
390 const SkBitmap* icon,
391 const ShowDialogCallback& show_dialog_callback) override {
392 delegate->InstallUIAbort(true);
393 base::MessageLoopForUI::current()->QuitWhenIdle();
394 }
395
396 void OnInstallSuccess(const Extension* extension, SkBitmap* icon) override {}
397
398 void OnInstallFailure(const extensions::CrxInstallError& error) override {}
399 };
400
401 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt {
402 public:
403 explicit MockAutoConfirmExtensionInstallPrompt(
404 content::WebContents* web_contents)
405 : ExtensionInstallPrompt(web_contents) {}
406
407 // Proceed without confirmation prompt.
408 void ShowDialog(Delegate* delegate,
409 const Extension* extension,
410 const SkBitmap* bitmap,
411 const ShowDialogCallback& show_dialog_callback) override {
412 delegate->InstallUIProceed();
413 }
414 };
415
416 const Extension* ExtensionBrowserTest::UpdateExtensionWaitForIdle( 383 const Extension* ExtensionBrowserTest::UpdateExtensionWaitForIdle(
417 const std::string& id, 384 const std::string& id,
418 const base::FilePath& path, 385 const base::FilePath& path,
419 int expected_change) { 386 int expected_change) {
420 return InstallOrUpdateExtension(id, 387 return InstallOrUpdateExtension(id,
421 path, 388 path,
422 INSTALL_UI_TYPE_NONE, 389 INSTALL_UI_TYPE_NONE,
423 expected_change, 390 expected_change,
424 Manifest::INTERNAL, 391 Manifest::INTERNAL,
425 browser(), 392 browser(),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 Browser* browser, 459 Browser* browser,
493 Extension::InitFromValueFlags creation_flags, 460 Extension::InitFromValueFlags creation_flags,
494 bool install_immediately) { 461 bool install_immediately) {
495 ExtensionService* service = 462 ExtensionService* service =
496 extensions::ExtensionSystem::Get(profile())->extension_service(); 463 extensions::ExtensionSystem::Get(profile())->extension_service();
497 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); 464 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
498 service->set_show_extensions_prompts(false); 465 service->set_show_extensions_prompts(false);
499 size_t num_before = registry->enabled_extensions().size(); 466 size_t num_before = registry->enabled_extensions().size();
500 467
501 { 468 {
502 scoped_ptr<ExtensionInstallPrompt> install_ui; 469 scoped_ptr<ScopedTestDialogAutoConfirm> prompt_auto_confirm;
503 if (ui_type == INSTALL_UI_TYPE_CANCEL) { 470 if (ui_type == INSTALL_UI_TYPE_CANCEL) {
504 install_ui.reset(new MockAbortExtensionInstallPrompt()); 471 prompt_auto_confirm.reset(new ScopedTestDialogAutoConfirm(
472 ScopedTestDialogAutoConfirm::CANCEL));
505 } else if (ui_type == INSTALL_UI_TYPE_NORMAL) { 473 } else if (ui_type == INSTALL_UI_TYPE_NORMAL) {
506 install_ui.reset(new ExtensionInstallPrompt( 474 prompt_auto_confirm.reset(new ScopedTestDialogAutoConfirm(
507 browser->tab_strip_model()->GetActiveWebContents())); 475 ScopedTestDialogAutoConfirm::NONE));
508 } else if (ui_type == INSTALL_UI_TYPE_AUTO_CONFIRM) { 476 } else if (ui_type == INSTALL_UI_TYPE_AUTO_CONFIRM) {
509 install_ui.reset(new MockAutoConfirmExtensionInstallPrompt( 477 prompt_auto_confirm.reset(new ScopedTestDialogAutoConfirm(
510 browser->tab_strip_model()->GetActiveWebContents())); 478 ScopedTestDialogAutoConfirm::ACCEPT));
511 } 479 }
512 480
513 // TODO(tessamac): Update callers to always pass an unpacked extension 481 // TODO(tessamac): Update callers to always pass an unpacked extension
514 // and then always pack the extension here. 482 // and then always pack the extension here.
515 base::FilePath crx_path = path; 483 base::FilePath crx_path = path;
516 if (crx_path.Extension() != FILE_PATH_LITERAL(".crx")) { 484 if (crx_path.Extension() != FILE_PATH_LITERAL(".crx")) {
517 crx_path = PackExtension(path); 485 crx_path = PackExtension(path);
518 } 486 }
519 if (crx_path.empty()) 487 if (crx_path.empty())
520 return NULL; 488 return NULL;
521 489
490 scoped_ptr<ExtensionInstallPrompt> install_ui;
491 if (prompt_auto_confirm) {
492 install_ui.reset(new ExtensionInstallPrompt(
493 browser->tab_strip_model()->GetActiveWebContents()));
494 }
522 scoped_refptr<extensions::CrxInstaller> installer( 495 scoped_refptr<extensions::CrxInstaller> installer(
523 extensions::CrxInstaller::Create(service, install_ui.Pass())); 496 extensions::CrxInstaller::Create(service, install_ui.Pass()));
524 installer->set_expected_id(id); 497 installer->set_expected_id(id);
525 installer->set_creation_flags(creation_flags); 498 installer->set_creation_flags(creation_flags);
526 installer->set_install_source(install_source); 499 installer->set_install_source(install_source);
527 installer->set_install_immediately(install_immediately); 500 installer->set_install_immediately(install_immediately);
528 if (!installer->is_gallery_install()) { 501 if (!installer->is_gallery_install()) {
529 installer->set_off_store_install_allow_reason( 502 installer->set_off_store_install_allow_reason(
530 extensions::CrxInstaller::OffStoreInstallAllowedInTest); 503 extensions::CrxInstaller::OffStoreInstallAllowedInTest);
531 } 504 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( 651 return extensions::browsertest_util::ExecuteScriptInBackgroundPage(
679 profile(), extension_id, script); 652 profile(), extension_id, script);
680 } 653 }
681 654
682 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait( 655 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait(
683 const std::string& extension_id, 656 const std::string& extension_id,
684 const std::string& script) { 657 const std::string& script) {
685 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait( 658 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait(
686 profile(), extension_id, script); 659 profile(), extension_id, script);
687 } 660 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer_browsertest.cc ('k') | chrome/browser/extensions/extension_install_prompt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698