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

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

Issue 11299326: Revert 170660 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | 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/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/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/extensions/app_shortcut_manager.h" 17 #include "chrome/browser/extensions/app_shortcut_manager.h"
18 #include "chrome/browser/extensions/component_loader.h" 18 #include "chrome/browser/extensions/component_loader.h"
19 #include "chrome/browser/extensions/crx_installer.h" 19 #include "chrome/browser/extensions/crx_installer.h"
20 #include "chrome/browser/extensions/extension_creator.h" 20 #include "chrome/browser/extensions/extension_creator.h"
21 #include "chrome/browser/extensions/extension_error_reporter.h" 21 #include "chrome/browser/extensions/extension_error_reporter.h"
22 #include "chrome/browser/extensions/extension_host.h" 22 #include "chrome/browser/extensions/extension_host.h"
23 #include "chrome/browser/extensions/extension_install_prompt.h" 23 #include "chrome/browser/extensions/extension_install_prompt.h"
24 #include "chrome/browser/extensions/extension_service.h" 24 #include "chrome/browser/extensions/extension_service.h"
25 #include "chrome/browser/extensions/extension_system.h" 25 #include "chrome/browser/extensions/extension_system.h"
26 #include "chrome/browser/extensions/shell_window_registry.h"
27 #include "chrome/browser/extensions/unpacked_installer.h" 26 #include "chrome/browser/extensions/unpacked_installer.h"
28 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
30 #include "chrome/browser/ui/browser_window.h" 29 #include "chrome/browser/ui/browser_window.h"
31 #include "chrome/browser/ui/extensions/native_app_window.h" 30 #include "chrome/browser/ui/extensions/native_app_window.h"
32 #include "chrome/browser/ui/extensions/shell_window.h" 31 #include "chrome/browser/ui/extensions/shell_window.h"
33 #include "chrome/browser/ui/omnibox/location_bar.h" 32 #include "chrome/browser/ui/omnibox/location_bar.h"
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" 33 #include "chrome/browser/ui/tabs/tab_strip_model.h"
35 #include "chrome/common/chrome_notification_types.h" 34 #include "chrome/common/chrome_notification_types.h"
36 #include "chrome/common/chrome_paths.h" 35 #include "chrome/common/chrome_paths.h"
37 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
38 #include "chrome/common/chrome_version_info.h" 37 #include "chrome/common/chrome_version_info.h"
39 #include "chrome/test/base/ui_test_utils.h" 38 #include "chrome/test/base/ui_test_utils.h"
40 #include "content/public/browser/navigation_controller.h" 39 #include "content/public/browser/navigation_controller.h"
41 #include "content/public/browser/navigation_entry.h" 40 #include "content/public/browser/navigation_entry.h"
42 #include "content/public/browser/notification_registrar.h" 41 #include "content/public/browser/notification_registrar.h"
43 #include "content/public/browser/notification_service.h" 42 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/render_view_host.h" 43 #include "content/public/browser/render_view_host.h"
45 #include "content/public/test/browser_test_utils.h" 44 #include "content/public/test/browser_test_utils.h"
46 #include "sync/api/string_ordinal.h" 45 #include "sync/api/string_ordinal.h"
47 46
48 using extensions::Extension; 47 using extensions::Extension;
49 using extensions::ExtensionCreator; 48 using extensions::ExtensionCreator;
50 using extensions::FeatureSwitch; 49 using extensions::FeatureSwitch;
51 using extensions::ShellWindowRegistry;
52 50
53 ExtensionBrowserTest::ExtensionBrowserTest() 51 ExtensionBrowserTest::ExtensionBrowserTest()
54 : loaded_(false), 52 : loaded_(false),
55 installed_(false), 53 installed_(false),
56 extension_installs_observed_(0), 54 extension_installs_observed_(0),
57 extension_load_errors_observed_(0), 55 extension_load_errors_observed_(0),
58 target_page_action_count_(-1), 56 target_page_action_count_(-1),
59 target_visible_page_action_count_(-1), 57 target_visible_page_action_count_(-1),
60 current_channel_(chrome::VersionInfo::CHANNEL_DEV), 58 current_channel_(chrome::VersionInfo::CHANNEL_DEV),
61 override_prompt_for_external_extensions_( 59 override_prompt_for_external_extensions_(
(...skipping 10 matching lines...) Expand all
72 test_data_dir_ = test_data_dir_.AppendASCII("extensions"); 70 test_data_dir_ = test_data_dir_.AppendASCII("extensions");
73 71
74 #if defined(OS_CHROMEOS) 72 #if defined(OS_CHROMEOS)
75 // This makes sure that we create the Default profile first, with no 73 // This makes sure that we create the Default profile first, with no
76 // ExtensionService and then the real profile with one, as we do when 74 // ExtensionService and then the real profile with one, as we do when
77 // running on chromeos. 75 // running on chromeos.
78 command_line->AppendSwitchASCII(switches::kLoginUser, 76 command_line->AppendSwitchASCII(switches::kLoginUser,
79 "TestUser@gmail.com"); 77 "TestUser@gmail.com");
80 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 78 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
81 #endif 79 #endif
82
83 // Make event pages get suspended quicker.
84 command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1");
85 command_line->AppendSwitchASCII(switches::kEventPageUnloadingTime, "1");
86 } 80 }
87 81
88 const Extension* ExtensionBrowserTest::LoadExtensionWithFlags( 82 const Extension* ExtensionBrowserTest::LoadExtensionWithFlags(
89 const FilePath& path, int flags) { 83 const FilePath& path, int flags) {
90 ExtensionService* service = extensions::ExtensionSystem::Get( 84 ExtensionService* service = extensions::ExtensionSystem::Get(
91 browser()->profile())->extension_service(); 85 browser()->profile())->extension_service();
92 { 86 {
93 content::NotificationRegistrar registrar; 87 content::NotificationRegistrar registrar;
94 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 88 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
95 content::NotificationService::AllSources()); 89 content::NotificationService::AllSources());
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 } 538 }
545 539
546 bool ExtensionBrowserTest::WaitForCrxInstallerDone() { 540 bool ExtensionBrowserTest::WaitForCrxInstallerDone() {
547 int before = crx_installers_done_observed_; 541 int before = crx_installers_done_observed_;
548 ui_test_utils::RegisterAndWait(this, 542 ui_test_utils::RegisterAndWait(this,
549 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 543 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
550 content::NotificationService::AllSources()); 544 content::NotificationService::AllSources());
551 return crx_installers_done_observed_ == (before + 1); 545 return crx_installers_done_observed_ == (before + 1);
552 } 546 }
553 547
554 void ExtensionBrowserTest::CloseShellWindow(ShellWindow* window) {
555 content::WindowedNotificationObserver destroyed_observer(
556 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
557 content::NotificationService::AllSources());
558 window->GetBaseWindow()->Close();
559 destroyed_observer.Wait();
560 }
561
562 void ExtensionBrowserTest::CloseShellWindowsAndWaitForAppToExit() {
563 ExtensionProcessManager* manager =
564 extensions::ExtensionSystem::Get(browser()->profile())->process_manager();
565 // If there are no background hosts active, the app must have already exited.
566 // This can happen if no windows were opened.
567 if (manager->background_hosts().empty())
568 return;
569
570 content::WindowedNotificationObserver destroyed_observer(
571 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
572 content::NotificationService::AllSources());
573
574 // Close all the windows.
575 ShellWindowRegistry* app_registry =
576 ShellWindowRegistry::Get(browser()->profile());
577 ShellWindowRegistry::const_iterator iter;
578 ShellWindowRegistry::ShellWindowSet shell_windows =
579 app_registry->shell_windows();
580 for (iter = shell_windows.begin(); iter != shell_windows.end(); ++iter)
581 CloseShellWindow(*iter);
582
583 // Now wait for the lazy background page of the platform app to be unloaded.
584 destroyed_observer.Wait();
585 }
586
587 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents, 548 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents,
588 const GURL& url, 549 const GURL& url,
589 bool newtab_process_should_equal_opener, 550 bool newtab_process_should_equal_opener,
590 content::WebContents** newtab_result) { 551 content::WebContents** newtab_result) {
591 content::WindowedNotificationObserver observer( 552 content::WindowedNotificationObserver observer(
592 content::NOTIFICATION_LOAD_STOP, 553 content::NOTIFICATION_LOAD_STOP,
593 content::NotificationService::AllSources()); 554 content::NotificationService::AllSources());
594 ASSERT_TRUE(content::ExecuteJavaScript( 555 ASSERT_TRUE(content::ExecuteJavaScript(
595 contents->GetRenderViewHost(), L"", 556 contents->GetRenderViewHost(), L"",
596 L"window.open('" + UTF8ToWide(url.spec()) + L"');")); 557 L"window.open('" + UTF8ToWide(url.spec()) + L"');"));
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 case content::NOTIFICATION_LOAD_STOP: 690 case content::NOTIFICATION_LOAD_STOP:
730 VLOG(1) << "Got LOAD_STOP notification."; 691 VLOG(1) << "Got LOAD_STOP notification.";
731 MessageLoopForUI::current()->Quit(); 692 MessageLoopForUI::current()->Quit();
732 break; 693 break;
733 694
734 default: 695 default:
735 NOTREACHED(); 696 NOTREACHED();
736 break; 697 break;
737 } 698 }
738 } 699 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.h ('k') | chrome/browser/extensions/extension_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698