OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ash/launcher/chrome_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/display/display_controller.h" | 8 #include "ash/display/display_controller.h" |
9 #include "ash/shelf/shelf.h" | 9 #include "ash/shelf/shelf.h" |
10 #include "ash/shelf/shelf_button.h" | 10 #include "ash/shelf/shelf_button.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "chrome/browser/extensions/extension_service.h" | 29 #include "chrome/browser/extensions/extension_service.h" |
30 #include "chrome/browser/extensions/launch_util.h" | 30 #include "chrome/browser/extensions/launch_util.h" |
31 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
32 #include "chrome/browser/ui/app_list/app_list_service.h" | 32 #include "chrome/browser/ui/app_list/app_list_service.h" |
33 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" | 33 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
34 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" | 34 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" |
35 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 35 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
36 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
37 #include "chrome/browser/ui/browser_commands.h" | 37 #include "chrome/browser/ui/browser_commands.h" |
38 #include "chrome/browser/ui/browser_finder.h" | 38 #include "chrome/browser/ui/browser_finder.h" |
| 39 #include "chrome/browser/ui/browser_iterator.h" |
39 #include "chrome/browser/ui/browser_list.h" | 40 #include "chrome/browser/ui/browser_list.h" |
40 #include "chrome/browser/ui/browser_window.h" | 41 #include "chrome/browser/ui/browser_window.h" |
41 #include "chrome/browser/ui/chrome_pages.h" | 42 #include "chrome/browser/ui/chrome_pages.h" |
42 #include "chrome/browser/ui/extensions/app_launch_params.h" | 43 #include "chrome/browser/ui/extensions/app_launch_params.h" |
43 #include "chrome/browser/ui/extensions/application_launch.h" | 44 #include "chrome/browser/ui/extensions/application_launch.h" |
44 #include "chrome/browser/ui/host_desktop.h" | 45 #include "chrome/browser/ui/host_desktop.h" |
45 #include "chrome/browser/ui/settings_window_manager.h" | 46 #include "chrome/browser/ui/settings_window_manager.h" |
46 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 47 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 48 #include "chrome/browser/web_applications/web_app.h" |
47 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
48 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 50 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
49 #include "chrome/test/base/ui_test_utils.h" | 51 #include "chrome/test/base/ui_test_utils.h" |
50 #include "content/public/browser/notification_service.h" | 52 #include "content/public/browser/notification_service.h" |
51 #include "content/public/browser/notification_source.h" | 53 #include "content/public/browser/notification_source.h" |
52 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
53 #include "content/public/test/browser_test_utils.h" | 55 #include "content/public/test/browser_test_utils.h" |
54 #include "extensions/browser/app_window/app_window.h" | 56 #include "extensions/browser/app_window/app_window.h" |
55 #include "extensions/browser/app_window/app_window_registry.h" | 57 #include "extensions/browser/app_window/app_window_registry.h" |
56 #include "extensions/browser/app_window/native_app_window.h" | 58 #include "extensions/browser/app_window/native_app_window.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 gfx::Rect all_apps_rect = all_apps_button->GetBoundsInScreen(); | 135 gfx::Rect all_apps_rect = all_apps_button->GetBoundsInScreen(); |
134 all_apps_rect.Offset(-display_origin.x(), -display_origin.y()); | 136 all_apps_rect.Offset(-display_origin.x(), -display_origin.y()); |
135 generator->MoveMouseTo(all_apps_rect.CenterPoint().x(), | 137 generator->MoveMouseTo(all_apps_rect.CenterPoint().x(), |
136 all_apps_rect.CenterPoint().y()); | 138 all_apps_rect.CenterPoint().y()); |
137 generator->ClickLeftButton(); | 139 generator->ClickLeftButton(); |
138 base::MessageLoop::current()->RunUntilIdle(); | 140 base::MessageLoop::current()->RunUntilIdle(); |
139 // Run Layout() to effectively complete the animation to the apps page. | 141 // Run Layout() to effectively complete the animation to the apps page. |
140 controller_test.LayoutContentsView(); | 142 controller_test.LayoutContentsView(); |
141 } | 143 } |
142 | 144 |
| 145 // Find the browser that associated with |app_name|. |
| 146 Browser* FindBrowserForApp(const std::string& app_name) { |
| 147 Browser* browser = nullptr; |
| 148 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 149 std::string browser_app_name = |
| 150 web_app::GetExtensionIdFromApplicationName((*it)->app_name()); |
| 151 if (browser_app_name == app_name) { |
| 152 browser = *it; |
| 153 break; |
| 154 } |
| 155 } |
| 156 return browser; |
| 157 } |
| 158 |
| 159 // Close |app_browser| and wait until it's closed. |
| 160 void CloseAppBrowserWindow(Browser* app_browser) { |
| 161 content::WindowedNotificationObserver close_observer( |
| 162 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 163 content::Source<Browser>(app_browser)); |
| 164 app_browser->window()->Close(); |
| 165 close_observer.Wait(); |
| 166 } |
| 167 |
143 } // namespace | 168 } // namespace |
144 | 169 |
145 class LauncherPlatformAppBrowserTest | 170 class LauncherPlatformAppBrowserTest |
146 : public extensions::PlatformAppBrowserTest { | 171 : public extensions::PlatformAppBrowserTest { |
147 protected: | 172 protected: |
148 LauncherPlatformAppBrowserTest() : shelf_(NULL), controller_(NULL) { | 173 LauncherPlatformAppBrowserTest() : shelf_(NULL), controller_(NULL) { |
149 } | 174 } |
150 | 175 |
151 ~LauncherPlatformAppBrowserTest() override {} | 176 ~LauncherPlatformAppBrowserTest() override {} |
152 | 177 |
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 // has to be active. | 1317 // has to be active. |
1293 tab_strip->ActivateTabAt(1, false); | 1318 tab_strip->ActivateTabAt(1, false); |
1294 EXPECT_EQ(1, tab_strip->active_index()); | 1319 EXPECT_EQ(1, tab_strip->active_index()); |
1295 | 1320 |
1296 // Close the web contents. | 1321 // Close the web contents. |
1297 tab_strip->CloseWebContentsAt(1, TabStripModel::CLOSE_NONE); | 1322 tab_strip->CloseWebContentsAt(1, TabStripModel::CLOSE_NONE); |
1298 // The status should now be set to closed. | 1323 // The status should now be set to closed. |
1299 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); | 1324 EXPECT_EQ(ash::STATUS_CLOSED, model_->ItemByID(shortcut_id)->status); |
1300 } | 1325 } |
1301 | 1326 |
| 1327 // Test that the App window could restore to its previous window state from |
| 1328 // before it was closed. |
| 1329 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, AppWindowRestoreBehaviorTest) { |
| 1330 // Open an App, maximized its window, and close it. |
| 1331 const Extension* extension = LoadAndLaunchExtension( |
| 1332 "app1", extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW); |
| 1333 Browser* app_browser = FindBrowserForApp(extension->id()); |
| 1334 ASSERT_TRUE(app_browser); |
| 1335 aura::Window* window = app_browser->window()->GetNativeWindow(); |
| 1336 EXPECT_FALSE(ash::wm::GetWindowState(window)->IsMaximized()); |
| 1337 ash::wm::GetWindowState(window)->Maximize(); |
| 1338 EXPECT_TRUE(ash::wm::GetWindowState(window)->IsMaximized()); |
| 1339 CloseAppBrowserWindow(app_browser); |
| 1340 |
| 1341 // Reopen the App. It should start maximized. Un-maximize it and close it. |
| 1342 extension = LoadAndLaunchExtension( |
| 1343 "app1", extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW); |
| 1344 app_browser = FindBrowserForApp(extension->id()); |
| 1345 ASSERT_TRUE(app_browser); |
| 1346 window = app_browser->window()->GetNativeWindow(); |
| 1347 EXPECT_TRUE(ash::wm::GetWindowState(window)->IsMaximized()); |
| 1348 |
| 1349 ash::wm::GetWindowState(window)->Restore(); |
| 1350 EXPECT_FALSE(ash::wm::GetWindowState(window)->IsMaximized()); |
| 1351 app_browser->window()->Close(); |
| 1352 CloseAppBrowserWindow(app_browser); |
| 1353 |
| 1354 // Reopen the App. It should start un-maximized. |
| 1355 extension = LoadAndLaunchExtension( |
| 1356 "app1", extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW); |
| 1357 app_browser = FindBrowserForApp(extension->id()); |
| 1358 ASSERT_TRUE(app_browser); |
| 1359 window = app_browser->window()->GetNativeWindow(); |
| 1360 EXPECT_FALSE(ash::wm::GetWindowState(window)->IsMaximized()); |
| 1361 } |
| 1362 |
1302 // Checks that a windowed application does not add an item to the browser list. | 1363 // Checks that a windowed application does not add an item to the browser list. |
1303 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTestNoDefaultBrowser, | 1364 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTestNoDefaultBrowser, |
1304 WindowedAppDoesNotAddToBrowser) { | 1365 WindowedAppDoesNotAddToBrowser) { |
1305 // Get the number of items in the browser menu. | 1366 // Get the number of items in the browser menu. |
1306 size_t items = NumberOfDetectedLauncherBrowsers(false); | 1367 size_t items = NumberOfDetectedLauncherBrowsers(false); |
1307 size_t running_browser = chrome::GetTotalBrowserCount(); | 1368 size_t running_browser = chrome::GetTotalBrowserCount(); |
1308 EXPECT_EQ(0u, items); | 1369 EXPECT_EQ(0u, items); |
1309 EXPECT_EQ(0u, running_browser); | 1370 EXPECT_EQ(0u, running_browser); |
1310 | 1371 |
1311 LoadAndLaunchExtension( | 1372 LoadAndLaunchExtension( |
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2269 controller_->ActivateApp(bookmark_app->id(), ash::LAUNCH_FROM_APP_LIST, 0); | 2330 controller_->ActivateApp(bookmark_app->id(), ash::LAUNCH_FROM_APP_LIST, 0); |
2270 | 2331 |
2271 // There should be two new browsers. | 2332 // There should be two new browsers. |
2272 EXPECT_EQ(3u, chrome::GetTotalBrowserCountForProfile(browser()->profile())); | 2333 EXPECT_EQ(3u, chrome::GetTotalBrowserCountForProfile(browser()->profile())); |
2273 | 2334 |
2274 // The apps should now be running, with the last opened app active. | 2335 // The apps should now be running, with the last opened app active. |
2275 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(hosted_app_shelf_id)->status); | 2336 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(hosted_app_shelf_id)->status); |
2276 EXPECT_EQ(ash::STATUS_ACTIVE, | 2337 EXPECT_EQ(ash::STATUS_ACTIVE, |
2277 model_->ItemByID(bookmark_app_shelf_id)->status); | 2338 model_->ItemByID(bookmark_app_shelf_id)->status); |
2278 } | 2339 } |
OLD | NEW |