| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "chrome/browser/sessions/session_service_factory.h" | 26 #include "chrome/browser/sessions/session_service_factory.h" |
| 27 #include "chrome/browser/translate/translate_tab_helper.h" | 27 #include "chrome/browser/translate/translate_tab_helper.h" |
| 28 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" | 28 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" |
| 29 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" | 29 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" |
| 30 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | 30 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
| 31 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
| 32 #include "chrome/browser/ui/browser_command_controller.h" | 32 #include "chrome/browser/ui/browser_command_controller.h" |
| 33 #include "chrome/browser/ui/browser_commands.h" | 33 #include "chrome/browser/ui/browser_commands.h" |
| 34 #include "chrome/browser/ui/browser_finder.h" | 34 #include "chrome/browser/ui/browser_finder.h" |
| 35 #include "chrome/browser/ui/browser_iterator.h" | 35 #include "chrome/browser/ui/browser_iterator.h" |
| 36 #include "chrome/browser/ui/browser_list.h" | |
| 37 #include "chrome/browser/ui/browser_navigator.h" | 36 #include "chrome/browser/ui/browser_navigator.h" |
| 38 #include "chrome/browser/ui/browser_tabstrip.h" | 37 #include "chrome/browser/ui/browser_tabstrip.h" |
| 39 #include "chrome/browser/ui/browser_ui_prefs.h" | 38 #include "chrome/browser/ui/browser_ui_prefs.h" |
| 40 #include "chrome/browser/ui/browser_window.h" | 39 #include "chrome/browser/ui/browser_window.h" |
| 41 #include "chrome/browser/ui/extensions/application_launch.h" | 40 #include "chrome/browser/ui/extensions/application_launch.h" |
| 42 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 41 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 43 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | 42 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
| 44 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" | 43 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" |
| 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 44 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 46 #include "chrome/common/chrome_notification_types.h" | 45 #include "chrome/common/chrome_notification_types.h" |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 457 |
| 459 // Run the application event loop to completion, which will cycle the | 458 // Run the application event loop to completion, which will cycle the |
| 460 // native MessagePump on all platforms. | 459 // native MessagePump on all platforms. |
| 461 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 460 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 462 MessageLoop::current()->Run(); | 461 MessageLoop::current()->Run(); |
| 463 | 462 |
| 464 // Take care of any remaining Cocoa work. | 463 // Take care of any remaining Cocoa work. |
| 465 CycleRunLoops(); | 464 CycleRunLoops(); |
| 466 | 465 |
| 467 // At this point, quit should be for real now. | 466 // At this point, quit should be for real now. |
| 468 ASSERT_EQ(0u, BrowserList::size()); | 467 ASSERT_EQ(0u, chrome::GetTotalBrowserCount()); |
| 469 } | 468 } |
| 470 | 469 |
| 471 // A helper function that cycles the MessageLoop, and on Mac, the Cocoa run | 470 // A helper function that cycles the MessageLoop, and on Mac, the Cocoa run |
| 472 // loop. It also drains the NSAutoreleasePool. | 471 // loop. It also drains the NSAutoreleasePool. |
| 473 void CycleRunLoops() { | 472 void CycleRunLoops() { |
| 474 content::RunAllPendingInMessageLoop(); | 473 content::RunAllPendingInMessageLoop(); |
| 475 #if defined(OS_MACOSX) | 474 #if defined(OS_MACOSX) |
| 476 chrome::testing::NSRunLoopRunAllPending(); | 475 chrome::testing::NSRunLoopRunAllPending(); |
| 477 AutoreleasePool()->Recycle(); | 476 AutoreleasePool()->Recycle(); |
| 478 #endif | 477 #endif |
| (...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1707 | 1706 |
| 1708 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 1707 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 1709 command_line->AppendSwitch(switches::kKeepAliveForTest); | 1708 command_line->AppendSwitch(switches::kKeepAliveForTest); |
| 1710 } | 1709 } |
| 1711 }; | 1710 }; |
| 1712 | 1711 |
| 1713 IN_PROC_BROWSER_TEST_F(RunInBackgroundTest, RunInBackgroundBasicTest) { | 1712 IN_PROC_BROWSER_TEST_F(RunInBackgroundTest, RunInBackgroundBasicTest) { |
| 1714 // Close the browser window, then open a new one - the browser should keep | 1713 // Close the browser window, then open a new one - the browser should keep |
| 1715 // running. | 1714 // running. |
| 1716 Profile* profile = browser()->profile(); | 1715 Profile* profile = browser()->profile(); |
| 1717 EXPECT_EQ(1u, BrowserList::size()); | 1716 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 1718 content::WindowedNotificationObserver observer( | 1717 content::WindowedNotificationObserver observer( |
| 1719 chrome::NOTIFICATION_BROWSER_CLOSED, | 1718 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 1720 content::Source<Browser>(browser())); | 1719 content::Source<Browser>(browser())); |
| 1721 chrome::CloseWindow(browser()); | 1720 chrome::CloseWindow(browser()); |
| 1722 observer.Wait(); | 1721 observer.Wait(); |
| 1723 EXPECT_EQ(0u, BrowserList::size()); | 1722 EXPECT_EQ(0u, chrome::GetTotalBrowserCount()); |
| 1724 | 1723 |
| 1725 ui_test_utils::BrowserAddedObserver browser_added_observer; | 1724 ui_test_utils::BrowserAddedObserver browser_added_observer; |
| 1726 chrome::NewEmptyWindow(profile); | 1725 chrome::NewEmptyWindow(profile); |
| 1727 browser_added_observer.WaitForSingleNewBrowser(); | 1726 browser_added_observer.WaitForSingleNewBrowser(); |
| 1728 | 1727 |
| 1729 EXPECT_EQ(1u, BrowserList::size()); | 1728 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 1730 } | 1729 } |
| 1731 | 1730 |
| 1732 // Tests to ensure that the browser continues running in the background after | 1731 // Tests to ensure that the browser continues running in the background after |
| 1733 // the last window closes. | 1732 // the last window closes. |
| 1734 class NoStartupWindowTest : public BrowserTest { | 1733 class NoStartupWindowTest : public BrowserTest { |
| 1735 public: | 1734 public: |
| 1736 NoStartupWindowTest() {} | 1735 NoStartupWindowTest() {} |
| 1737 | 1736 |
| 1738 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 1737 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 1739 command_line->AppendSwitch(switches::kNoStartupWindow); | 1738 command_line->AppendSwitch(switches::kNoStartupWindow); |
| 1740 command_line->AppendSwitch(switches::kKeepAliveForTest); | 1739 command_line->AppendSwitch(switches::kKeepAliveForTest); |
| 1741 } | 1740 } |
| 1742 }; | 1741 }; |
| 1743 | 1742 |
| 1744 IN_PROC_BROWSER_TEST_F(NoStartupWindowTest, NoStartupWindowBasicTest) { | 1743 IN_PROC_BROWSER_TEST_F(NoStartupWindowTest, NoStartupWindowBasicTest) { |
| 1745 // No browser window should be started by default. | 1744 // No browser window should be started by default. |
| 1746 EXPECT_EQ(0u, BrowserList::size()); | 1745 EXPECT_EQ(0u, chrome::GetTotalBrowserCount()); |
| 1747 | 1746 |
| 1748 // Starting a browser window should work just fine. | 1747 // Starting a browser window should work just fine. |
| 1749 ui_test_utils::BrowserAddedObserver browser_added_observer; | 1748 ui_test_utils::BrowserAddedObserver browser_added_observer; |
| 1750 CreateBrowser(ProfileManager::GetDefaultProfile()); | 1749 CreateBrowser(ProfileManager::GetDefaultProfile()); |
| 1751 browser_added_observer.WaitForSingleNewBrowser(); | 1750 browser_added_observer.WaitForSingleNewBrowser(); |
| 1752 | 1751 |
| 1753 EXPECT_EQ(1u, BrowserList::size()); | 1752 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 1754 } | 1753 } |
| 1755 | 1754 |
| 1756 // Chromeos needs to track app windows because it considers them to be part of | 1755 // Chromeos needs to track app windows because it considers them to be part of |
| 1757 // session state. | 1756 // session state. |
| 1758 #if !defined(OS_CHROMEOS) | 1757 #if !defined(OS_CHROMEOS) |
| 1759 IN_PROC_BROWSER_TEST_F(NoStartupWindowTest, DontInitSessionServiceForApps) { | 1758 IN_PROC_BROWSER_TEST_F(NoStartupWindowTest, DontInitSessionServiceForApps) { |
| 1760 Profile* profile = ProfileManager::GetDefaultProfile(); | 1759 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 1761 | 1760 |
| 1762 SessionService* session_service = | 1761 SessionService* session_service = |
| 1763 SessionServiceFactory::GetForProfile(profile); | 1762 SessionServiceFactory::GetForProfile(profile); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2020 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); | 2019 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); |
| 2021 } | 2020 } |
| 2022 | 2021 |
| 2023 // Shift-middle-clicks open in a foreground tab. | 2022 // Shift-middle-clicks open in a foreground tab. |
| 2024 IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefShiftMiddleClickTest) { | 2023 IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefShiftMiddleClickTest) { |
| 2025 int modifiers = WebKit::WebInputEvent::ShiftKey; | 2024 int modifiers = WebKit::WebInputEvent::ShiftKey; |
| 2026 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle; | 2025 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle; |
| 2027 WindowOpenDisposition disposition = NEW_FOREGROUND_TAB; | 2026 WindowOpenDisposition disposition = NEW_FOREGROUND_TAB; |
| 2028 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); | 2027 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); |
| 2029 } | 2028 } |
| OLD | NEW |