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 "apps/app_window_registry.h" | |
8 #include "base/command_line.h" | 7 #include "base/command_line.h" |
9 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
10 #include "chrome/browser/apps/app_browsertest_util.h" | 9 #include "chrome/browser/apps/app_browsertest_util.h" |
11 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chrome_browser_application_mac.h" | 11 #include "chrome/browser/chrome_browser_application_mac.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_test_message_listener.h" | 13 #include "chrome/browser/extensions/extension_test_message_listener.h" |
15 #include "chrome/browser/lifetime/application_lifetime.h" | 14 #include "chrome/browser/lifetime/application_lifetime.h" |
16 #include "chrome/browser/notifications/message_center_notification_manager.h" | 15 #include "chrome/browser/notifications/message_center_notification_manager.h" |
17 #include "chrome/browser/notifications/notification_ui_manager.h" | 16 #include "chrome/browser/notifications/notification_ui_manager.h" |
18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser_iterator.h" | 18 #include "chrome/browser/ui/browser_iterator.h" |
20 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
22 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
23 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
| 23 #include "extensions/browser/app_window/app_window_registry.h" |
24 #include "extensions/browser/app_window/native_app_window.h" | 24 #include "extensions/browser/app_window/native_app_window.h" |
25 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
26 #include "ui/message_center/message_center.h" | 26 #include "ui/message_center/message_center.h" |
27 | 27 |
28 typedef apps::AppWindowRegistry::AppWindowList AppWindowList; | 28 using extensions::AppWindowRegistry; |
| 29 typedef AppWindowRegistry::AppWindowList AppWindowList; |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 class QuitWithAppsControllerInteractiveTest | 33 class QuitWithAppsControllerInteractiveTest |
33 : public extensions::PlatformAppBrowserTest { | 34 : public extensions::PlatformAppBrowserTest { |
34 protected: | 35 protected: |
35 QuitWithAppsControllerInteractiveTest() : app_(NULL) {} | 36 QuitWithAppsControllerInteractiveTest() : app_(NULL) {} |
36 | 37 |
37 virtual ~QuitWithAppsControllerInteractiveTest() {} | 38 virtual ~QuitWithAppsControllerInteractiveTest() {} |
38 | 39 |
(...skipping 24 matching lines...) Expand all Loading... |
63 QuitWithAppsController::kQuitWithAppsNotificationID); | 64 QuitWithAppsController::kQuitWithAppsNotificationID); |
64 EXPECT_EQ(NULL, notification); | 65 EXPECT_EQ(NULL, notification); |
65 | 66 |
66 // Open an app window. | 67 // Open an app window. |
67 ExtensionTestMessageListener listener("Launched", false); | 68 ExtensionTestMessageListener listener("Launched", false); |
68 app_ = InstallAndLaunchPlatformApp("minimal_id"); | 69 app_ = InstallAndLaunchPlatformApp("minimal_id"); |
69 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 70 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
70 | 71 |
71 // One browser and one app window at this point. | 72 // One browser and one app window at this point. |
72 EXPECT_FALSE(chrome::BrowserIterator().done()); | 73 EXPECT_FALSE(chrome::BrowserIterator().done()); |
73 EXPECT_TRUE(apps::AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); | 74 EXPECT_TRUE(AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); |
74 | 75 |
75 // On the first quit, show notification. | 76 // On the first quit, show notification. |
76 EXPECT_FALSE(controller->ShouldQuit()); | 77 EXPECT_FALSE(controller->ShouldQuit()); |
77 EXPECT_TRUE(apps::AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); | 78 EXPECT_TRUE(AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); |
78 notification = g_browser_process->notification_ui_manager()->FindById( | 79 notification = g_browser_process->notification_ui_manager()->FindById( |
79 QuitWithAppsController::kQuitWithAppsNotificationID); | 80 QuitWithAppsController::kQuitWithAppsNotificationID); |
80 ASSERT_TRUE(notification); | 81 ASSERT_TRUE(notification); |
81 | 82 |
82 // If notification was dismissed by click, show again on next quit. | 83 // If notification was dismissed by click, show again on next quit. |
83 notification->delegate()->Click(); | 84 notification->delegate()->Click(); |
84 message_center->RemoveAllNotifications(false); | 85 message_center->RemoveAllNotifications(false); |
85 EXPECT_FALSE(controller->ShouldQuit()); | 86 EXPECT_FALSE(controller->ShouldQuit()); |
86 EXPECT_TRUE(apps::AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); | 87 EXPECT_TRUE(AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); |
87 notification = g_browser_process->notification_ui_manager()->FindById( | 88 notification = g_browser_process->notification_ui_manager()->FindById( |
88 QuitWithAppsController::kQuitWithAppsNotificationID); | 89 QuitWithAppsController::kQuitWithAppsNotificationID); |
89 ASSERT_TRUE(notification); | 90 ASSERT_TRUE(notification); |
90 | 91 |
91 EXPECT_FALSE(chrome::BrowserIterator().done()); | 92 EXPECT_FALSE(chrome::BrowserIterator().done()); |
92 EXPECT_TRUE(apps::AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); | 93 EXPECT_TRUE(AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); |
93 | 94 |
94 // If notification is closed by user, don't show it next time. | 95 // If notification is closed by user, don't show it next time. |
95 notification->delegate()->Close(true); | 96 notification->delegate()->Close(true); |
96 message_center->RemoveAllNotifications(false); | 97 message_center->RemoveAllNotifications(false); |
97 EXPECT_FALSE(controller->ShouldQuit()); | 98 EXPECT_FALSE(controller->ShouldQuit()); |
98 EXPECT_TRUE(apps::AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); | 99 EXPECT_TRUE(AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); |
99 notification = g_browser_process->notification_ui_manager()->FindById( | 100 notification = g_browser_process->notification_ui_manager()->FindById( |
100 QuitWithAppsController::kQuitWithAppsNotificationID); | 101 QuitWithAppsController::kQuitWithAppsNotificationID); |
101 EXPECT_EQ(NULL, notification); | 102 EXPECT_EQ(NULL, notification); |
102 | 103 |
103 EXPECT_FALSE(chrome::BrowserIterator().done()); | 104 EXPECT_FALSE(chrome::BrowserIterator().done()); |
104 EXPECT_TRUE(apps::AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); | 105 EXPECT_TRUE(AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); |
105 | 106 |
106 // Quitting should not quit but close all browsers | 107 // Quitting should not quit but close all browsers |
107 content::WindowedNotificationObserver observer( | 108 content::WindowedNotificationObserver observer( |
108 chrome::NOTIFICATION_BROWSER_CLOSED, | 109 chrome::NOTIFICATION_BROWSER_CLOSED, |
109 content::NotificationService::AllSources()); | 110 content::NotificationService::AllSources()); |
110 chrome_browser_application_mac::Terminate(); | 111 chrome_browser_application_mac::Terminate(); |
111 observer.Wait(); | 112 observer.Wait(); |
112 | 113 |
113 EXPECT_TRUE(chrome::BrowserIterator().done()); | 114 EXPECT_TRUE(chrome::BrowserIterator().done()); |
114 EXPECT_TRUE(apps::AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); | 115 EXPECT_TRUE(AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); |
115 | 116 |
116 // Trying to quit while there are no browsers always shows notification. | 117 // Trying to quit while there are no browsers always shows notification. |
117 EXPECT_FALSE(controller->ShouldQuit()); | 118 EXPECT_FALSE(controller->ShouldQuit()); |
118 notification = g_browser_process->notification_ui_manager()->FindById( | 119 notification = g_browser_process->notification_ui_manager()->FindById( |
119 QuitWithAppsController::kQuitWithAppsNotificationID); | 120 QuitWithAppsController::kQuitWithAppsNotificationID); |
120 ASSERT_TRUE(notification); | 121 ASSERT_TRUE(notification); |
121 | 122 |
122 // Clicking "Quit All Apps." button closes all app windows. With no browsers | 123 // Clicking "Quit All Apps." button closes all app windows. With no browsers |
123 // open, this should also quit Chrome. | 124 // open, this should also quit Chrome. |
124 content::WindowedNotificationObserver quit_observer( | 125 content::WindowedNotificationObserver quit_observer( |
125 chrome::NOTIFICATION_APP_TERMINATING, | 126 chrome::NOTIFICATION_APP_TERMINATING, |
126 content::NotificationService::AllSources()); | 127 content::NotificationService::AllSources()); |
127 notification->delegate()->ButtonClick(0); | 128 notification->delegate()->ButtonClick(0); |
128 message_center->RemoveAllNotifications(false); | 129 message_center->RemoveAllNotifications(false); |
129 EXPECT_FALSE(apps::AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); | 130 EXPECT_FALSE(AppWindowRegistry::IsAppWindowRegisteredInAnyProfile(0)); |
130 quit_observer.Wait(); | 131 quit_observer.Wait(); |
131 } | 132 } |
OLD | NEW |