From 70593e50a3bb6b26e57080b93b55a3baeedd5db2 Mon Sep 17 00:00:00 2001 From: "jackhou@chromium.org" Date: Thu, 15 May 2014 08:30:23 +0000 Subject: [Mac] Close browsers when quitting is prevented by QuitWithAppsController. Follow-up to https://codereview.chromium.org/220373003/ This closes all browser windows when quitting, even if Chrome is kept alive by QuitWithAppsController. TEST=Enable --apps-keep-chrome-alive in chrome://flags. Enable session restore in settings ("Continue where you left off"). Start Chrome and open an extra tab and browser window. Open an app from chrome://apps. Quit Chrome. i.e. via Dock->Quit, Menu->Quit, or Cmd+Q. Chrome and the app should stay running but browser windows should close. TEST=Repeat the first test and then: Close the app window, Chrome should quit. TEST=Repeat the first test and then: Click on the Chrome dock icon, the previous session should be restored. BUG=333429 Review URL: https://codereview.chromium.org/253383004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270638 0039d316-1c4b-4281-b951-d872f2087c98 --- ..._with_apps_controller_mac_interactive_uitest.cc | 40 ++++++++++++---------- .../ui/cocoa/confirm_quit_panel_controller.mm | 6 +++- 2 files changed, 27 insertions(+), 19 deletions(-) (limited to 'chrome/browser/ui/cocoa') diff --git a/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac_interactive_uitest.cc b/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac_interactive_uitest.cc index 51a8acb..18eb721 100644 --- a/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac_interactive_uitest.cc +++ b/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac_interactive_uitest.cc @@ -7,8 +7,10 @@ #include "apps/app_window_registry.h" #include "apps/ui/native_app_window.h" #include "base/command_line.h" +#include "base/run_loop.h" #include "chrome/browser/apps/app_browsertest_util.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_browser_application_mac.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_test_message_listener.h" #include "chrome/browser/lifetime/application_lifetime.h" @@ -39,14 +41,6 @@ class QuitWithAppsControllerInteractiveTest command_line->AppendSwitch(switches::kAppsKeepChromeAlive); } - virtual void SetUpOnMainThread() OVERRIDE { - ExtensionBrowserTest::SetUpOnMainThread(); - - ExtensionTestMessageListener listener("Launched", false); - app_ = InstallAndLaunchPlatformApp("minimal_id"); - ASSERT_TRUE(listener.WaitUntilSatisfied()); - } - const extensions::Extension* app_; private: @@ -62,6 +56,18 @@ IN_PROC_BROWSER_TEST_F(QuitWithAppsControllerInteractiveTest, QuitBehavior) { const Notification* notification; message_center::MessageCenter* message_center = message_center::MessageCenter::Get(); + + // With no app windows open, ShouldQuit returns true. + EXPECT_TRUE(controller->ShouldQuit()); + notification = g_browser_process->notification_ui_manager()->FindById( + QuitWithAppsController::kQuitWithAppsNotificationID); + EXPECT_EQ(NULL, notification); + + // Open an app window. + ExtensionTestMessageListener listener("Launched", false); + app_ = InstallAndLaunchPlatformApp("minimal_id"); + ASSERT_TRUE(listener.WaitUntilSatisfied()); + // One browser and one app window at this point. EXPECT_FALSE(chrome::BrowserIterator().done()); EXPECT_TRUE(apps::AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); @@ -97,12 +103,11 @@ IN_PROC_BROWSER_TEST_F(QuitWithAppsControllerInteractiveTest, QuitBehavior) { EXPECT_FALSE(chrome::BrowserIterator().done()); EXPECT_TRUE(apps::AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); - // Normally, quitting would close all browsers, but since we're just - // simulating a quit, close it here. + // Quitting should not quit but close all browsers content::WindowedNotificationObserver observer( chrome::NOTIFICATION_BROWSER_CLOSED, content::NotificationService::AllSources()); - chrome::BrowserIterator()->window()->Close(); + chrome_browser_application_mac::Terminate(); observer.Wait(); EXPECT_TRUE(chrome::BrowserIterator().done()); @@ -114,14 +119,13 @@ IN_PROC_BROWSER_TEST_F(QuitWithAppsControllerInteractiveTest, QuitBehavior) { QuitWithAppsController::kQuitWithAppsNotificationID); ASSERT_TRUE(notification); - // Clicking "Quit All Apps." button closes all app windows. + // Clicking "Quit All Apps." button closes all app windows. With no browsers + // open, this should also quit Chrome. + content::WindowedNotificationObserver quit_observer( + chrome::NOTIFICATION_APP_TERMINATING, + content::NotificationService::AllSources()); notification->delegate()->ButtonClick(0); message_center->RemoveAllNotifications(false); EXPECT_FALSE(apps::AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); - - // With no app windows open, ShouldQuit returns true. - EXPECT_TRUE(controller->ShouldQuit()); - notification = g_browser_process->notification_ui_manager()->FindById( - QuitWithAppsController::kQuitWithAppsNotificationID); - EXPECT_EQ(NULL, notification); + quit_observer.Wait(); } diff --git a/chrome/browser/ui/cocoa/confirm_quit_panel_controller.mm b/chrome/browser/ui/cocoa/confirm_quit_panel_controller.mm index 499dc93..ad2c835 100644 --- a/chrome/browser/ui/cocoa/confirm_quit_panel_controller.mm +++ b/chrome/browser/ui/cocoa/confirm_quit_panel_controller.mm @@ -15,6 +15,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" +#import "chrome/browser/ui/cocoa/browser_window_controller.h" #include "chrome/browser/ui/cocoa/confirm_quit.h" #include "chrome/common/pref_names.h" #include "grit/generated_resources.h" @@ -154,7 +155,10 @@ void RegisterLocalState(PrefRegistrySimple* registry) { - (void)setCurrentProgress:(NSAnimationProgress)progress { for (NSWindow* window in [application_ windows]) { - [window setAlphaValue:1.0 - progress]; + if ([[window windowController] + isKindOfClass:[BrowserWindowController class]]) { + [window setAlphaValue:1.0 - progress]; + } } } -- cgit v1.1