Chromium Code Reviews| 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/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.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; |
| 49 using extensions::ShellWindowRegistry; | |
| 47 | 50 |
| 48 ExtensionBrowserTest::ExtensionBrowserTest() | 51 ExtensionBrowserTest::ExtensionBrowserTest() |
| 49 : loaded_(false), | 52 : loaded_(false), |
| 50 installed_(false), | 53 installed_(false), |
| 51 extension_installs_observed_(0), | 54 extension_installs_observed_(0), |
| 52 extension_load_errors_observed_(0), | 55 extension_load_errors_observed_(0), |
| 53 target_page_action_count_(-1), | 56 target_page_action_count_(-1), |
| 54 target_visible_page_action_count_(-1), | 57 target_visible_page_action_count_(-1), |
| 55 current_channel_(chrome::VersionInfo::CHANNEL_DEV), | 58 current_channel_(chrome::VersionInfo::CHANNEL_DEV), |
| 56 override_prompt_for_external_extensions_( | 59 override_prompt_for_external_extensions_( |
| 57 extensions::FeatureSwitch::prompt_for_external_extensions(), false) { | 60 extensions::FeatureSwitch::prompt_for_external_extensions(), false) { |
| 58 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 61 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 59 } | 62 } |
| 60 | 63 |
| 61 ExtensionBrowserTest::~ExtensionBrowserTest() {} | 64 ExtensionBrowserTest::~ExtensionBrowserTest() {} |
| 62 | 65 |
| 63 void ExtensionBrowserTest::SetUpCommandLine(CommandLine* command_line) { | 66 void ExtensionBrowserTest::SetUpCommandLine(CommandLine* command_line) { |
| 64 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 67 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| 65 test_data_dir_ = test_data_dir_.AppendASCII("extensions"); | 68 test_data_dir_ = test_data_dir_.AppendASCII("extensions"); |
| 66 | 69 |
| 67 #if defined(OS_CHROMEOS) | 70 #if defined(OS_CHROMEOS) |
| 68 // This makes sure that we create the Default profile first, with no | 71 // This makes sure that we create the Default profile first, with no |
| 69 // ExtensionService and then the real profile with one, as we do when | 72 // ExtensionService and then the real profile with one, as we do when |
| 70 // running on chromeos. | 73 // running on chromeos. |
| 71 command_line->AppendSwitchASCII(switches::kLoginUser, | 74 command_line->AppendSwitchASCII(switches::kLoginUser, |
| 72 "TestUser@gmail.com"); | 75 "TestUser@gmail.com"); |
| 73 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 76 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
| 74 command_line->AppendSwitch(switches::kNoFirstRun); | 77 command_line->AppendSwitch(switches::kNoFirstRun); |
| 75 #endif | 78 #endif |
| 79 | |
| 80 // Make event pages get suspended quicker. | |
| 81 command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1"); | |
| 82 command_line->AppendSwitchASCII(switches::kEventPageUnloadingTime, "1"); | |
| 76 } | 83 } |
| 77 | 84 |
| 78 const Extension* ExtensionBrowserTest::LoadExtensionWithFlags( | 85 const Extension* ExtensionBrowserTest::LoadExtensionWithFlags( |
| 79 const FilePath& path, int flags) { | 86 const FilePath& path, int flags) { |
| 80 ExtensionService* service = browser()->profile()->GetExtensionService(); | 87 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 81 { | 88 { |
| 82 content::NotificationRegistrar registrar; | 89 content::NotificationRegistrar registrar; |
| 83 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 90 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 84 content::NotificationService::AllSources()); | 91 content::NotificationService::AllSources()); |
| 85 scoped_refptr<extensions::UnpackedInstaller> installer( | 92 scoped_refptr<extensions::UnpackedInstaller> installer( |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 } | 533 } |
| 527 | 534 |
| 528 bool ExtensionBrowserTest::WaitForCrxInstallerDone() { | 535 bool ExtensionBrowserTest::WaitForCrxInstallerDone() { |
| 529 int before = crx_installers_done_observed_; | 536 int before = crx_installers_done_observed_; |
| 530 ui_test_utils::RegisterAndWait(this, | 537 ui_test_utils::RegisterAndWait(this, |
| 531 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 538 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 532 content::NotificationService::AllSources()); | 539 content::NotificationService::AllSources()); |
| 533 return crx_installers_done_observed_ == (before + 1); | 540 return crx_installers_done_observed_ == (before + 1); |
| 534 } | 541 } |
| 535 | 542 |
| 543 void ExtensionBrowserTest::CloseShellWindow(ShellWindow* window) { | |
| 544 content::WindowedNotificationObserver destroyed_observer( | |
| 545 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
| 546 content::NotificationService::AllSources()); | |
| 547 window->GetBaseWindow()->Close(); | |
| 548 destroyed_observer.Wait(); | |
| 549 } | |
| 550 | |
| 551 void ExtensionBrowserTest::CloseShellWindowsAndWaitForAppToExit() { | |
| 552 content::WindowedNotificationObserver destroyed_observer( | |
| 553 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | |
| 554 content::NotificationService::AllSources()); | |
| 555 | |
| 556 ShellWindowRegistry* app_registry = | |
| 557 ShellWindowRegistry::Get(browser()->profile()); | |
| 558 ShellWindowRegistry::const_iterator iter; | |
| 559 ShellWindowRegistry::ShellWindowSet shell_windows = | |
| 560 app_registry->shell_windows(); | |
| 561 for (iter = shell_windows.begin(); iter != shell_windows.end(); ++iter) | |
| 562 CloseShellWindow(*iter); | |
| 563 | |
| 564 destroyed_observer.Wait(); | |
|
Yoyo Zhou
2012/10/30 01:35:22
This looks like it's only going to wait for 1 shel
benwells
2012/10/30 02:55:23
It's waiting for the background page to exit. I'll
| |
| 565 } | |
| 566 | |
| 536 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents, | 567 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents, |
| 537 const GURL& url, | 568 const GURL& url, |
| 538 bool newtab_process_should_equal_opener, | 569 bool newtab_process_should_equal_opener, |
| 539 content::WebContents** newtab_result) { | 570 content::WebContents** newtab_result) { |
| 540 content::WindowedNotificationObserver observer( | 571 content::WindowedNotificationObserver observer( |
| 541 content::NOTIFICATION_LOAD_STOP, | 572 content::NOTIFICATION_LOAD_STOP, |
| 542 content::NotificationService::AllSources()); | 573 content::NotificationService::AllSources()); |
| 543 ASSERT_TRUE(content::ExecuteJavaScript( | 574 ASSERT_TRUE(content::ExecuteJavaScript( |
| 544 contents->GetRenderViewHost(), L"", | 575 contents->GetRenderViewHost(), L"", |
| 545 L"window.open('" + UTF8ToWide(url.spec()) + L"');")); | 576 L"window.open('" + UTF8ToWide(url.spec()) + L"');")); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 case content::NOTIFICATION_LOAD_STOP: | 709 case content::NOTIFICATION_LOAD_STOP: |
| 679 VLOG(1) << "Got LOAD_STOP notification."; | 710 VLOG(1) << "Got LOAD_STOP notification."; |
| 680 MessageLoopForUI::current()->Quit(); | 711 MessageLoopForUI::current()->Quit(); |
| 681 break; | 712 break; |
| 682 | 713 |
| 683 default: | 714 default: |
| 684 NOTREACHED(); | 715 NOTREACHED(); |
| 685 break; | 716 break; |
| 686 } | 717 } |
| 687 } | 718 } |
| OLD | NEW |