| 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 "apps/native_app_window.h" | 7 #include "apps/native_app_window.h" |
| 8 #include "apps/shell_window.h" | 8 #include "apps/shell_window.h" |
| 9 #include "apps/shell_window_registry.h" | 9 #include "apps/shell_window_registry.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); | 124 return ash::test::ShellTestApi(ash::Shell::GetInstance()).launcher_model(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) { | 127 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& name) { |
| 128 return controller_->CreateAppShortcutLauncherItem( | 128 return controller_->CreateAppShortcutLauncherItem( |
| 129 name, controller_->model()->item_count()); | 129 name, controller_->model()->item_count()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 const ash::LauncherItem& GetLastLauncherItem() { | 132 const ash::LauncherItem& GetLastLauncherItem() { |
| 133 // Unless there are any panels, the item at index [count - 1] will be | 133 // Unless there are any panels, the item at index [count - 1] will be |
| 134 // the app list, and the item at [count - 2] will be the desired item. | 134 // the desired item. |
| 135 return launcher_model()->items()[launcher_model()->item_count() - 2]; | 135 return launcher_model()->items()[launcher_model()->item_count() - 1]; |
| 136 } | 136 } |
| 137 | 137 |
| 138 const ash::LauncherItem& GetLastLauncherPanelItem() { | 138 const ash::LauncherItem& GetLastLauncherPanelItem() { |
| 139 // Panels show up on the right side of the launcher, so the desired item | 139 // Panels show up on the right side of the launcher, so the desired item |
| 140 // will be the last one. | 140 // will be the last one. |
| 141 return launcher_model()->items()[launcher_model()->item_count() - 1]; | 141 return launcher_model()->items()[launcher_model()->item_count() - 1]; |
| 142 } | 142 } |
| 143 | 143 |
| 144 LauncherItemController* GetItemController(ash::LauncherID id) { | 144 LauncherItemController* GetItemController(ash::LauncherID id) { |
| 145 return controller_->id_to_item_controller_map_[id]; | 145 return controller_->id_to_item_controller_map_[id]; |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 // processed it. This needs to be in a loop since the renderer runs in a | 809 // processed it. This needs to be in a loop since the renderer runs in a |
| 810 // different process. | 810 // different process. |
| 811 while (test_observer.icon_updates() < 3) { | 811 while (test_observer.icon_updates() < 3) { |
| 812 base::RunLoop run_loop; | 812 base::RunLoop run_loop; |
| 813 run_loop.RunUntilIdle(); | 813 run_loop.RunUntilIdle(); |
| 814 } | 814 } |
| 815 | 815 |
| 816 // This test creates one shell window and one panel window. | 816 // This test creates one shell window and one panel window. |
| 817 int launcher_item_count = launcher_model()->item_count(); | 817 int launcher_item_count = launcher_model()->item_count(); |
| 818 ASSERT_EQ(base_launcher_item_count + 2, launcher_item_count); | 818 ASSERT_EQ(base_launcher_item_count + 2, launcher_item_count); |
| 819 // The Panel will be the last item, the app list second-to-last, the app | 819 // The Panel will be the last item, the app second-to-last. |
| 820 // third from last. | |
| 821 const ash::LauncherItem& app_item = | 820 const ash::LauncherItem& app_item = |
| 822 launcher_model()->items()[launcher_item_count - 3]; | 821 launcher_model()->items()[launcher_item_count - 2]; |
| 823 const ash::LauncherItem& panel_item = | 822 const ash::LauncherItem& panel_item = |
| 824 launcher_model()->items()[launcher_item_count - 1]; | 823 launcher_model()->items()[launcher_item_count - 1]; |
| 825 const LauncherItemController* app_item_controller = | 824 const LauncherItemController* app_item_controller = |
| 826 GetItemController(app_item.id); | 825 GetItemController(app_item.id); |
| 827 const LauncherItemController* panel_item_controller = | 826 const LauncherItemController* panel_item_controller = |
| 828 GetItemController(panel_item.id); | 827 GetItemController(panel_item.id); |
| 829 // Icons for Apps are set by the ShellWindowLauncherController, so | 828 // Icons for Apps are set by the ShellWindowLauncherController, so |
| 830 // image_set_by_controller() should be set. | 829 // image_set_by_controller() should be set. |
| 831 EXPECT_TRUE(app_item_controller->image_set_by_controller()); | 830 EXPECT_TRUE(app_item_controller->image_set_by_controller()); |
| 832 EXPECT_TRUE(panel_item_controller->image_set_by_controller()); | 831 EXPECT_TRUE(panel_item_controller->image_set_by_controller()); |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 // Active windows don't show attention. | 1369 // Active windows don't show attention. |
| 1371 panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true); | 1370 panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true); |
| 1372 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 1371 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
| 1373 } | 1372 } |
| 1374 | 1373 |
| 1375 // Checks that the browser Alt "tabbing" is properly done. | 1374 // Checks that the browser Alt "tabbing" is properly done. |
| 1376 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, | 1375 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTestNoDefaultBrowser, |
| 1377 AltNumberBrowserTabbing) { | 1376 AltNumberBrowserTabbing) { |
| 1378 // Get the number of items in the browser menu. | 1377 // Get the number of items in the browser menu. |
| 1379 EXPECT_EQ(0u, chrome::GetTotalBrowserCount()); | 1378 EXPECT_EQ(0u, chrome::GetTotalBrowserCount()); |
| 1380 // The first activation should create a browser. | 1379 // The first activation should create a browser at index 1 (App List @ 0). |
| 1381 launcher_->ActivateLauncherItem(0); | 1380 launcher_->ActivateLauncherItem(1); |
| 1382 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 1381 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 1383 // A second activation should not create a new instance. | 1382 // A second activation should not create a new instance. |
| 1384 launcher_->ActivateLauncherItem(0); | 1383 launcher_->ActivateLauncherItem(1); |
| 1385 Browser* browser1 = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); | 1384 Browser* browser1 = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); |
| 1386 EXPECT_TRUE(browser1); | 1385 EXPECT_TRUE(browser1); |
| 1387 aura::Window* window1 = browser1->window()->GetNativeWindow(); | 1386 aura::Window* window1 = browser1->window()->GetNativeWindow(); |
| 1388 Browser* browser2 = CreateBrowser(profile()); | 1387 Browser* browser2 = CreateBrowser(profile()); |
| 1389 aura::Window* window2 = browser2->window()->GetNativeWindow(); | 1388 aura::Window* window2 = browser2->window()->GetNativeWindow(); |
| 1390 | 1389 |
| 1391 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); | 1390 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); |
| 1392 EXPECT_NE(window1, window2); | 1391 EXPECT_NE(window1, window2); |
| 1393 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); | 1392 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); |
| 1394 | 1393 |
| 1395 // Activate multiple times the switcher to see that the windows get activated. | 1394 // Activate multiple times the switcher to see that the windows get activated. |
| 1396 launcher_->ActivateLauncherItem(0); | 1395 launcher_->ActivateLauncherItem(1); |
| 1397 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | 1396 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); |
| 1398 launcher_->ActivateLauncherItem(0); | 1397 launcher_->ActivateLauncherItem(1); |
| 1399 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); | 1398 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); |
| 1400 | 1399 |
| 1401 // Create a third browser - make sure that we do not toggle simply between | 1400 // Create a third browser - make sure that we do not toggle simply between |
| 1402 // two windows. | 1401 // two windows. |
| 1403 Browser* browser3 = CreateBrowser(profile()); | 1402 Browser* browser3 = CreateBrowser(profile()); |
| 1404 aura::Window* window3 = browser3->window()->GetNativeWindow(); | 1403 aura::Window* window3 = browser3->window()->GetNativeWindow(); |
| 1405 | 1404 |
| 1406 EXPECT_EQ(3u, chrome::GetTotalBrowserCount()); | 1405 EXPECT_EQ(3u, chrome::GetTotalBrowserCount()); |
| 1407 EXPECT_NE(window1, window3); | 1406 EXPECT_NE(window1, window3); |
| 1408 EXPECT_NE(window2, window3); | 1407 EXPECT_NE(window2, window3); |
| 1409 EXPECT_EQ(window3, ash::wm::GetActiveWindow()); | 1408 EXPECT_EQ(window3, ash::wm::GetActiveWindow()); |
| 1410 | 1409 |
| 1411 launcher_->ActivateLauncherItem(0); | 1410 launcher_->ActivateLauncherItem(1); |
| 1412 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | 1411 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); |
| 1413 launcher_->ActivateLauncherItem(0); | 1412 launcher_->ActivateLauncherItem(1); |
| 1414 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); | 1413 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); |
| 1415 launcher_->ActivateLauncherItem(0); | 1414 launcher_->ActivateLauncherItem(1); |
| 1416 EXPECT_EQ(window3, ash::wm::GetActiveWindow()); | 1415 EXPECT_EQ(window3, ash::wm::GetActiveWindow()); |
| 1417 launcher_->ActivateLauncherItem(0); | 1416 launcher_->ActivateLauncherItem(1); |
| 1418 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | 1417 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); |
| 1419 | 1418 |
| 1420 // Create anther app and make sure that none of our browsers is active. | 1419 // Create anther app and make sure that none of our browsers is active. |
| 1421 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW); | 1420 LoadAndLaunchExtension("app1", extension_misc::LAUNCH_TAB, NEW_WINDOW); |
| 1422 EXPECT_NE(window1, ash::wm::GetActiveWindow()); | 1421 EXPECT_NE(window1, ash::wm::GetActiveWindow()); |
| 1423 EXPECT_NE(window2, ash::wm::GetActiveWindow()); | 1422 EXPECT_NE(window2, ash::wm::GetActiveWindow()); |
| 1424 | 1423 |
| 1425 // After activation our browser should be active again. | 1424 // After activation our browser should be active again. |
| 1426 launcher_->ActivateLauncherItem(0); | 1425 launcher_->ActivateLauncherItem(1); |
| 1427 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | 1426 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); |
| 1428 } | 1427 } |
| 1429 | 1428 |
| 1430 // Checks that after a session restore, we do not start applications on an | 1429 // Checks that after a session restore, we do not start applications on an |
| 1431 // activation. | 1430 // activation. |
| 1432 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateAfterSessionRestore) { | 1431 IN_PROC_BROWSER_TEST_F(LauncherAppBrowserTest, ActivateAfterSessionRestore) { |
| 1433 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 1432 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 1434 | 1433 |
| 1435 // Create a known application. | 1434 // Create a known application. |
| 1436 ash::LauncherID shortcut_id = CreateShortcut("app1"); | 1435 ash::LauncherID shortcut_id = CreateShortcut("app1"); |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1775 // Now show overflow bubble. | 1774 // Now show overflow bubble. |
| 1776 test.ShowOverflowBubble(); | 1775 test.ShowOverflowBubble(); |
| 1777 EXPECT_TRUE(launcher_->IsShowingOverflowBubble()); | 1776 EXPECT_TRUE(launcher_->IsShowingOverflowBubble()); |
| 1778 | 1777 |
| 1779 // Unpin first pinned app and there should be no crash. | 1778 // Unpin first pinned app and there should be no crash. |
| 1780 controller_->UnpinAppWithID(std::string("fake_app_0")); | 1779 controller_->UnpinAppWithID(std::string("fake_app_0")); |
| 1781 | 1780 |
| 1782 test.RunMessageLoopUntilAnimationsDone(); | 1781 test.RunMessageLoopUntilAnimationsDone(); |
| 1783 EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); | 1782 EXPECT_FALSE(launcher_->IsShowingOverflowBubble()); |
| 1784 } | 1783 } |
| OLD | NEW |