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