| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/cocoa/apps/quit_with_apps_controller_mac.h" | 5 #include "chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #import "base/mac/foundation_util.h" | 8 #import "base/mac/foundation_util.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // On the first quit, show notification. | 88 // On the first quit, show notification. |
| 89 EXPECT_FALSE(controller->ShouldQuit()); | 89 EXPECT_FALSE(controller->ShouldQuit()); |
| 90 EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)); | 90 EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)); |
| 91 notification = g_browser_process->notification_ui_manager()->FindById( | 91 notification = g_browser_process->notification_ui_manager()->FindById( |
| 92 QuitWithAppsController::kQuitWithAppsNotificationID, | 92 QuitWithAppsController::kQuitWithAppsNotificationID, |
| 93 NotificationUIManager::GetProfileID(profiles[0])); | 93 NotificationUIManager::GetProfileID(profiles[0])); |
| 94 ASSERT_TRUE(notification); | 94 ASSERT_TRUE(notification); |
| 95 | 95 |
| 96 // If notification was dismissed by click, show again on next quit. | 96 // If notification was dismissed by click, show again on next quit. |
| 97 notification->delegate()->Click(); | 97 notification->delegate()->Click(); |
| 98 message_center->RemoveAllNotifications(false); | 98 message_center->RemoveAllNotifications( |
| 99 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); |
| 99 EXPECT_FALSE(controller->ShouldQuit()); | 100 EXPECT_FALSE(controller->ShouldQuit()); |
| 100 EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)); | 101 EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)); |
| 101 notification = g_browser_process->notification_ui_manager()->FindById( | 102 notification = g_browser_process->notification_ui_manager()->FindById( |
| 102 QuitWithAppsController::kQuitWithAppsNotificationID, | 103 QuitWithAppsController::kQuitWithAppsNotificationID, |
| 103 NotificationUIManager::GetProfileID(profiles[0])); | 104 NotificationUIManager::GetProfileID(profiles[0])); |
| 104 ASSERT_TRUE(notification); | 105 ASSERT_TRUE(notification); |
| 105 | 106 |
| 106 EXPECT_FALSE(BrowserList::GetInstance()->empty()); | 107 EXPECT_FALSE(BrowserList::GetInstance()->empty()); |
| 107 EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)); | 108 EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)); |
| 108 | 109 |
| 109 // If notification is closed by user, don't show it next time. | 110 // If notification is closed by user, don't show it next time. |
| 110 notification->delegate()->Close(true); | 111 notification->delegate()->Close(true); |
| 111 message_center->RemoveAllNotifications(false); | 112 message_center->RemoveAllNotifications( |
| 113 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); |
| 112 EXPECT_FALSE(controller->ShouldQuit()); | 114 EXPECT_FALSE(controller->ShouldQuit()); |
| 113 EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)); | 115 EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)); |
| 114 notification = g_browser_process->notification_ui_manager()->FindById( | 116 notification = g_browser_process->notification_ui_manager()->FindById( |
| 115 QuitWithAppsController::kQuitWithAppsNotificationID, | 117 QuitWithAppsController::kQuitWithAppsNotificationID, |
| 116 NotificationUIManager::GetProfileID(profiles[0])); | 118 NotificationUIManager::GetProfileID(profiles[0])); |
| 117 EXPECT_EQ(NULL, notification); | 119 EXPECT_EQ(NULL, notification); |
| 118 | 120 |
| 119 EXPECT_FALSE(BrowserList::GetInstance()->empty()); | 121 EXPECT_FALSE(BrowserList::GetInstance()->empty()); |
| 120 EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)); | 122 EXPECT_TRUE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)); |
| 121 | 123 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 143 // open, this should also quit Chrome. | 145 // open, this should also quit Chrome. |
| 144 content::WindowedNotificationObserver quit_observer( | 146 content::WindowedNotificationObserver quit_observer( |
| 145 chrome::NOTIFICATION_APP_TERMINATING, | 147 chrome::NOTIFICATION_APP_TERMINATING, |
| 146 content::NotificationService::AllSources()); | 148 content::NotificationService::AllSources()); |
| 147 | 149 |
| 148 // Since closing app windows may be an async operation, use a watcher. | 150 // Since closing app windows may be an async operation, use a watcher. |
| 149 content::WebContentsDestroyedWatcher destroyed_watcher( | 151 content::WebContentsDestroyedWatcher destroyed_watcher( |
| 150 app_window->web_contents()); | 152 app_window->web_contents()); |
| 151 notification->delegate()->ButtonClick(0); | 153 notification->delegate()->ButtonClick(0); |
| 152 destroyed_watcher.Wait(); | 154 destroyed_watcher.Wait(); |
| 153 message_center->RemoveAllNotifications(false); | 155 message_center->RemoveAllNotifications( |
| 156 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); |
| 154 EXPECT_FALSE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)); | 157 EXPECT_FALSE(AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0)); |
| 155 quit_observer.Wait(); | 158 quit_observer.Wait(); |
| 156 } | 159 } |
| 157 | 160 |
| 158 // Test that, when powering off, Chrome will quit even if there are apps open. | 161 // Test that, when powering off, Chrome will quit even if there are apps open. |
| 159 IN_PROC_BROWSER_TEST_P(QuitWithAppsControllerInteractiveTest, QuitOnPowerOff) { | 162 IN_PROC_BROWSER_TEST_P(QuitWithAppsControllerInteractiveTest, QuitOnPowerOff) { |
| 160 // Open an app window. | 163 // Open an app window. |
| 161 app_ = LoadAndLaunchPlatformApp("minimal_id", "Launched"); | 164 app_ = LoadAndLaunchPlatformApp("minimal_id", "Launched"); |
| 162 | 165 |
| 163 // First try to terminate with a packaged app running. Chrome should stay | 166 // First try to terminate with a packaged app running. Chrome should stay |
| (...skipping 10 matching lines...) Expand all Loading... |
| 174 [NSNotification notificationWithName:NSWorkspaceWillPowerOffNotification | 177 [NSNotification notificationWithName:NSWorkspaceWillPowerOffNotification |
| 175 object:nil]; | 178 object:nil]; |
| 176 [app_controller willPowerOff:notification]; | 179 [app_controller willPowerOff:notification]; |
| 177 [NSApp terminate:nil]; | 180 [NSApp terminate:nil]; |
| 178 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); | 181 EXPECT_TRUE(browser_shutdown::IsTryingToQuit()); |
| 179 } | 182 } |
| 180 | 183 |
| 181 INSTANTIATE_TEST_CASE_P(QuitWithAppsControllerInteractiveTestInstance, | 184 INSTANTIATE_TEST_CASE_P(QuitWithAppsControllerInteractiveTestInstance, |
| 182 QuitWithAppsControllerInteractiveTest, | 185 QuitWithAppsControllerInteractiveTest, |
| 183 ::testing::Bool()); | 186 ::testing::Bool()); |
| OLD | NEW |