| 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 = browser()->profile()->GetExtensionService(); | 89 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 83 { | 90 { |
| 84 content::NotificationRegistrar registrar; | 91 content::NotificationRegistrar registrar; |
| 85 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 92 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 86 content::NotificationService::AllSources()); | 93 content::NotificationService::AllSources()); |
| 87 scoped_refptr<extensions::UnpackedInstaller> installer( | 94 scoped_refptr<extensions::UnpackedInstaller> installer( |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 535 } |
| 529 | 536 |
| 530 bool ExtensionBrowserTest::WaitForCrxInstallerDone() { | 537 bool ExtensionBrowserTest::WaitForCrxInstallerDone() { |
| 531 int before = crx_installers_done_observed_; | 538 int before = crx_installers_done_observed_; |
| 532 ui_test_utils::RegisterAndWait(this, | 539 ui_test_utils::RegisterAndWait(this, |
| 533 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 540 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 534 content::NotificationService::AllSources()); | 541 content::NotificationService::AllSources()); |
| 535 return crx_installers_done_observed_ == (before + 1); | 542 return crx_installers_done_observed_ == (before + 1); |
| 536 } | 543 } |
| 537 | 544 |
| 545 void ExtensionBrowserTest::CloseShellWindow(ShellWindow* window) { |
| 546 content::WindowedNotificationObserver destroyed_observer( |
| 547 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 548 content::NotificationService::AllSources()); |
| 549 window->GetBaseWindow()->Close(); |
| 550 destroyed_observer.Wait(); |
| 551 } |
| 552 |
| 553 void ExtensionBrowserTest::CloseShellWindowsAndWaitForAppToExit() { |
| 554 content::WindowedNotificationObserver destroyed_observer( |
| 555 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 556 content::NotificationService::AllSources()); |
| 557 |
| 558 // Close all the windows. |
| 559 ShellWindowRegistry* app_registry = |
| 560 ShellWindowRegistry::Get(browser()->profile()); |
| 561 ShellWindowRegistry::const_iterator iter; |
| 562 ShellWindowRegistry::ShellWindowSet shell_windows = |
| 563 app_registry->shell_windows(); |
| 564 for (iter = shell_windows.begin(); iter != shell_windows.end(); ++iter) |
| 565 CloseShellWindow(*iter); |
| 566 |
| 567 // Now wait for the lazy background page of the platform app to be unloaded. |
| 568 destroyed_observer.Wait(); |
| 569 } |
| 570 |
| 538 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents, | 571 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents, |
| 539 const GURL& url, | 572 const GURL& url, |
| 540 bool newtab_process_should_equal_opener, | 573 bool newtab_process_should_equal_opener, |
| 541 content::WebContents** newtab_result) { | 574 content::WebContents** newtab_result) { |
| 542 content::WindowedNotificationObserver observer( | 575 content::WindowedNotificationObserver observer( |
| 543 content::NOTIFICATION_LOAD_STOP, | 576 content::NOTIFICATION_LOAD_STOP, |
| 544 content::NotificationService::AllSources()); | 577 content::NotificationService::AllSources()); |
| 545 ASSERT_TRUE(content::ExecuteJavaScript( | 578 ASSERT_TRUE(content::ExecuteJavaScript( |
| 546 contents->GetRenderViewHost(), L"", | 579 contents->GetRenderViewHost(), L"", |
| 547 L"window.open('" + UTF8ToWide(url.spec()) + L"');")); | 580 L"window.open('" + UTF8ToWide(url.spec()) + L"');")); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 case content::NOTIFICATION_LOAD_STOP: | 713 case content::NOTIFICATION_LOAD_STOP: |
| 681 VLOG(1) << "Got LOAD_STOP notification."; | 714 VLOG(1) << "Got LOAD_STOP notification."; |
| 682 MessageLoopForUI::current()->Quit(); | 715 MessageLoopForUI::current()->Quit(); |
| 683 break; | 716 break; |
| 684 | 717 |
| 685 default: | 718 default: |
| 686 NOTREACHED(); | 719 NOTREACHED(); |
| 687 break; | 720 break; |
| 688 } | 721 } |
| 689 } | 722 } |
| OLD | NEW |