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_impl.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "ash/aura/wm_window_aura.h" | 9 #include "ash/aura/wm_window_aura.h" |
10 #include "ash/common/shelf/app_list_button.h" | 10 #include "ash/common/shelf/app_list_button.h" |
11 #include "ash/common/shelf/shelf_button.h" | 11 #include "ash/common/shelf/shelf_button.h" |
12 #include "ash/common/shelf/shelf_constants.h" | 12 #include "ash/common/shelf/shelf_constants.h" |
13 #include "ash/common/shelf/shelf_model.h" | 13 #include "ash/common/shelf/shelf_model.h" |
14 #include "ash/common/shelf/shelf_view.h" | 14 #include "ash/common/shelf/shelf_view.h" |
15 #include "ash/common/shelf/shelf_widget.h" | 15 #include "ash/common/shelf/shelf_widget.h" |
16 #include "ash/common/shelf/wm_shelf.h" | 16 #include "ash/common/shelf/wm_shelf.h" |
17 #include "ash/common/wm/window_state.h" | 17 #include "ash/common/wm/window_state.h" |
18 #include "ash/common/wm_shell.h" | 18 #include "ash/common/wm_shell.h" |
19 #include "ash/common/wm_window_property.h" | 19 #include "ash/common/wm_window_property.h" |
20 #include "ash/shell.h" | 20 #include "ash/shell.h" |
21 #include "ash/test/shelf_view_test_api.h" | 21 #include "ash/test/shelf_view_test_api.h" |
| 22 #include "ash/wm/window_properties.h" |
22 #include "ash/wm/window_state_aura.h" | 23 #include "ash/wm/window_state_aura.h" |
23 #include "ash/wm/window_util.h" | 24 #include "ash/wm/window_util.h" |
24 #include "base/macros.h" | 25 #include "base/macros.h" |
25 #include "base/run_loop.h" | 26 #include "base/run_loop.h" |
26 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
27 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
28 #include "build/build_config.h" | 29 #include "build/build_config.h" |
29 #include "chrome/browser/apps/app_browsertest_util.h" | 30 #include "chrome/browser/apps/app_browsertest_util.h" |
30 #include "chrome/browser/chrome_notification_types.h" | 31 #include "chrome/browser/chrome_notification_types.h" |
31 #include "chrome/browser/extensions/extension_apitest.h" | 32 #include "chrome/browser/extensions/extension_apitest.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 return shelf_model()->items()[shelf_model()->item_count() - 1]; | 209 return shelf_model()->items()[shelf_model()->item_count() - 1]; |
209 } | 210 } |
210 | 211 |
211 const ash::ShelfItem& GetLastLauncherPanelItem() { | 212 const ash::ShelfItem& GetLastLauncherPanelItem() { |
212 // Panels show up on the right side of the shelf, so the desired item | 213 // Panels show up on the right side of the shelf, so the desired item |
213 // will be the last one. | 214 // will be the last one. |
214 return shelf_model()->items()[shelf_model()->item_count() - 1]; | 215 return shelf_model()->items()[shelf_model()->item_count() - 1]; |
215 } | 216 } |
216 | 217 |
217 LauncherItemController* GetItemController(ash::ShelfID id) { | 218 LauncherItemController* GetItemController(ash::ShelfID id) { |
218 return controller_->id_to_item_controller_map_[id]; | 219 return controller_->GetLauncherItemController(id); |
219 } | 220 } |
220 | 221 |
221 // Returns the number of menu items, ignoring separators. | 222 // Returns the number of menu items, ignoring separators. |
222 int GetNumApplicationMenuItems(const ash::ShelfItem& item) { | 223 int GetNumApplicationMenuItems(const ash::ShelfItem& item) { |
223 const int event_flags = 0; | 224 const int event_flags = 0; |
224 std::unique_ptr<ash::ShelfMenuModel> menu( | 225 std::unique_ptr<ash::ShelfMenuModel> menu( |
225 new LauncherApplicationMenuItemModel( | 226 new LauncherApplicationMenuItemModel( |
226 controller_->GetApplicationList(item, event_flags))); | 227 controller_->GetApplicationList(item, event_flags))); |
227 int num_items = 0; | 228 int num_items = 0; |
228 for (int i = 0; i < menu->GetItemCount(); ++i) { | 229 for (int i = 0; i < menu->GetItemCount(); ++i) { |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | 749 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); |
749 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive()); | 750 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive()); |
750 // The second neither. | 751 // The second neither. |
751 item1_controller->ItemSelected(click_event); | 752 item1_controller->ItemSelected(click_event); |
752 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); | 753 EXPECT_TRUE(window1->GetNativeWindow()->IsVisible()); |
753 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible()); | 754 EXPECT_TRUE(window1a->GetNativeWindow()->IsVisible()); |
754 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); | 755 EXPECT_TRUE(window1->GetBaseWindow()->IsActive()); |
755 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive()); | 756 EXPECT_FALSE(window1a->GetBaseWindow()->IsActive()); |
756 } | 757 } |
757 | 758 |
| 759 // Confirm that ash::ShelfWindowWatcher correctly handles app panels. |
| 760 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, AppPanel) { |
| 761 // Enable experimental APIs to allow panel creation. |
| 762 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 763 extensions::switches::kEnableExperimentalExtensionApis); |
| 764 // Launch a platform app and create a panel window for it. |
| 765 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); |
| 766 AppWindow::CreateParams params; |
| 767 params.window_type = AppWindow::WINDOW_TYPE_PANEL; |
| 768 params.focused = false; |
| 769 AppWindow* panel = |
| 770 CreateAppWindowFromParams(browser()->profile(), extension1, params); |
| 771 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); |
| 772 // Panels should not be active by default. |
| 773 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); |
| 774 // Confirm that an item delegate was created and is in the correct state. |
| 775 const ash::ShelfItem& item1 = GetLastLauncherPanelItem(); |
| 776 EXPECT_EQ(ash::TYPE_APP_PANEL, item1.type); |
| 777 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); |
| 778 EXPECT_EQ(nullptr, GetItemController(item1.id)); |
| 779 ash::ShelfItemDelegate* item1_delegate = |
| 780 shelf_model()->GetShelfItemDelegate(item1.id); |
| 781 EXPECT_EQ(ash::TYPE_APP_PANEL, |
| 782 panel->GetNativeWindow()->GetProperty(ash::kShelfItemTypeKey)); |
| 783 // Click the item and confirm that the panel is activated. |
| 784 TestEvent click_event(ui::ET_MOUSE_PRESSED); |
| 785 item1_delegate->ItemSelected(click_event); |
| 786 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); |
| 787 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 788 // Click the item again and confirm that the panel is minimized. |
| 789 item1_delegate->ItemSelected(click_event); |
| 790 EXPECT_TRUE(panel->GetBaseWindow()->IsMinimized()); |
| 791 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); |
| 792 // Click the item again and confirm that the panel is activated. |
| 793 item1_delegate->ItemSelected(click_event); |
| 794 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); |
| 795 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); |
| 796 EXPECT_FALSE(panel->GetBaseWindow()->IsMinimized()); |
| 797 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
| 798 } |
| 799 |
758 // Confirm that click behavior for app panels is correct. | 800 // Confirm that click behavior for app panels is correct. |
759 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, AppPanelClickBehavior) { | 801 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, AppPanelClickBehavior) { |
760 // Enable experimental APIs to allow panel creation. | 802 // Enable experimental APIs to allow panel creation. |
761 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 803 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
762 extensions::switches::kEnableExperimentalExtensionApis); | 804 extensions::switches::kEnableExperimentalExtensionApis); |
763 // Launch a platform app and create a panel window for it. | 805 // Launch a platform app and create a panel window for it. |
764 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); | 806 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); |
765 AppWindow::CreateParams params; | 807 AppWindow::CreateParams params; |
766 params.window_type = AppWindow::WINDOW_TYPE_PANEL; | 808 params.window_type = AppWindow::WINDOW_TYPE_PANEL; |
767 params.focused = false; | 809 params.focused = false; |
768 AppWindow* panel = | 810 AppWindow* panel = |
769 CreateAppWindowFromParams(browser()->profile(), extension1, params); | 811 CreateAppWindowFromParams(browser()->profile(), extension1, params); |
770 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); | 812 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); |
771 // Panels should not be active by default. | 813 // Panels should not be active by default. |
772 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); | 814 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); |
773 // Confirm that a controller item was created and is the correct state. | 815 // Confirm that an item delegate was created and is in the correct state. |
774 const ash::ShelfItem& item1 = GetLastLauncherPanelItem(); | 816 const ash::ShelfItem& item1 = GetLastLauncherPanelItem(); |
775 LauncherItemController* item1_controller = GetItemController(item1.id); | |
776 EXPECT_EQ(ash::TYPE_APP_PANEL, item1.type); | 817 EXPECT_EQ(ash::TYPE_APP_PANEL, item1.type); |
777 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); | 818 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); |
778 EXPECT_EQ(LauncherItemController::TYPE_APP_PANEL, item1_controller->type()); | 819 EXPECT_EQ(nullptr, GetItemController(item1.id)); |
| 820 ash::ShelfItemDelegate* item1_delegate = |
| 821 shelf_model()->GetShelfItemDelegate(item1.id); |
| 822 EXPECT_EQ(ash::TYPE_APP_PANEL, |
| 823 panel->GetNativeWindow()->GetProperty(ash::kShelfItemTypeKey)); |
779 // Click the item and confirm that the panel is activated. | 824 // Click the item and confirm that the panel is activated. |
780 TestEvent click_event(ui::ET_MOUSE_PRESSED); | 825 TestEvent click_event(ui::ET_MOUSE_PRESSED); |
781 item1_controller->ItemSelected(click_event); | 826 item1_delegate->ItemSelected(click_event); |
782 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); | 827 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); |
783 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 828 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
784 // Click the item again and confirm that the panel is minimized. | 829 // Click the item again and confirm that the panel is minimized. |
785 item1_controller->ItemSelected(click_event); | 830 item1_delegate->ItemSelected(click_event); |
786 EXPECT_TRUE(panel->GetBaseWindow()->IsMinimized()); | 831 EXPECT_TRUE(panel->GetBaseWindow()->IsMinimized()); |
787 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); | 832 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); |
788 // Click the item again and confirm that the panel is activated. | 833 // Click the item again and confirm that the panel is activated. |
789 item1_controller->ItemSelected(click_event); | 834 item1_delegate->ItemSelected(click_event); |
790 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); | 835 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); |
791 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); | 836 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); |
792 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); | 837 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); |
793 } | 838 } |
794 | 839 |
795 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) { | 840 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, BrowserActivation) { |
796 int item_count = shelf_model()->item_count(); | 841 int item_count = shelf_model()->item_count(); |
797 | 842 |
798 // First run app. | 843 // First run app. |
799 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); | 844 const Extension* extension1 = LoadAndLaunchPlatformApp("launch", "Launched"); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 } | 876 } |
832 | 877 |
833 // This test creates one app window and one panel window. | 878 // This test creates one app window and one panel window. |
834 int shelf_item_count = shelf_model()->item_count(); | 879 int shelf_item_count = shelf_model()->item_count(); |
835 ASSERT_EQ(base_shelf_item_count + 2, shelf_item_count); | 880 ASSERT_EQ(base_shelf_item_count + 2, shelf_item_count); |
836 // The Panel will be the last item, the app second-to-last. | 881 // The Panel will be the last item, the app second-to-last. |
837 const ash::ShelfItem& app_item = | 882 const ash::ShelfItem& app_item = |
838 shelf_model()->items()[shelf_item_count - 2]; | 883 shelf_model()->items()[shelf_item_count - 2]; |
839 const ash::ShelfItem& panel_item = | 884 const ash::ShelfItem& panel_item = |
840 shelf_model()->items()[shelf_item_count - 1]; | 885 shelf_model()->items()[shelf_item_count - 1]; |
| 886 // Icons for Apps are set by the AppWindowLauncherController, so |
| 887 // image_set_by_controller() should be set. |
841 const LauncherItemController* app_item_controller = | 888 const LauncherItemController* app_item_controller = |
842 GetItemController(app_item.id); | 889 GetItemController(app_item.id); |
843 const LauncherItemController* panel_item_controller = | |
844 GetItemController(panel_item.id); | |
845 // Icons for Apps are set by the AppWindowLauncherController, so | |
846 // image_set_by_controller() should be set. | |
847 EXPECT_TRUE(app_item_controller->image_set_by_controller()); | 890 EXPECT_TRUE(app_item_controller->image_set_by_controller()); |
848 EXPECT_TRUE(panel_item_controller->image_set_by_controller()); | 891 // Panels are handled by ShelfWindowWatcher, not ChromeLauncherController. |
| 892 EXPECT_EQ(nullptr, GetItemController(panel_item.id)); |
849 // Ensure icon heights are correct (see test.js in app_icon/ test directory) | 893 // Ensure icon heights are correct (see test.js in app_icon/ test directory) |
850 EXPECT_EQ(ash::GetShelfConstant(ash::SHELF_SIZE), app_item.image.height()); | 894 EXPECT_EQ(ash::GetShelfConstant(ash::SHELF_SIZE), app_item.image.height()); |
851 EXPECT_EQ(64, panel_item.image.height()); | 895 EXPECT_EQ(64, panel_item.image.height()); |
852 } | 896 } |
853 | 897 |
854 // Test that we can launch an app with a shortcut. | 898 // Test that we can launch an app with a shortcut. |
855 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchPinned) { | 899 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchPinned) { |
856 TabStripModel* tab_strip = browser()->tab_strip_model(); | 900 TabStripModel* tab_strip = browser()->tab_strip_model(); |
857 int tab_count = tab_strip->count(); | 901 int tab_count = tab_strip->count(); |
858 ash::ShelfID shortcut_id = CreateShortcut("app1"); | 902 ash::ShelfID shortcut_id = CreateShortcut("app1"); |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowAttentionStatus) { | 1516 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, WindowAttentionStatus) { |
1473 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); | 1517 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); |
1474 AppWindow::CreateParams params; | 1518 AppWindow::CreateParams params; |
1475 params.window_type = AppWindow::WINDOW_TYPE_PANEL; | 1519 params.window_type = AppWindow::WINDOW_TYPE_PANEL; |
1476 params.focused = false; | 1520 params.focused = false; |
1477 AppWindow* panel = | 1521 AppWindow* panel = |
1478 CreateAppWindowFromParams(browser()->profile(), extension, params); | 1522 CreateAppWindowFromParams(browser()->profile(), extension, params); |
1479 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); | 1523 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); |
1480 // Panels should not be active by default. | 1524 // Panels should not be active by default. |
1481 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); | 1525 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); |
1482 // Confirm that a controller item was created and is the correct state. | 1526 // Confirm that a shelf item was created and is the correct state. |
1483 const ash::ShelfItem& item = GetLastLauncherPanelItem(); | 1527 const ash::ShelfItem& item = GetLastLauncherPanelItem(); |
1484 LauncherItemController* item_controller = GetItemController(item.id); | 1528 // Panels are handled by ShelfWindowWatcher, not ChromeLauncherController. |
| 1529 EXPECT_EQ(nullptr, GetItemController(item.id)); |
| 1530 ash::ShelfItemDelegate* shelf_item_delegate = |
| 1531 shelf_model()->GetShelfItemDelegate(item.id); |
| 1532 EXPECT_NE(nullptr, shelf_item_delegate); |
1485 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); | 1533 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); |
1486 EXPECT_EQ(ash::STATUS_RUNNING, item.status); | 1534 EXPECT_EQ(ash::STATUS_RUNNING, item.status); |
1487 EXPECT_EQ(LauncherItemController::TYPE_APP_PANEL, item_controller->type()); | |
1488 | 1535 |
1489 // App windows should go to attention state. | 1536 // App windows should go to attention state. |
1490 panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true); | 1537 panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true); |
1491 EXPECT_EQ(ash::STATUS_ATTENTION, item.status); | 1538 EXPECT_EQ(ash::STATUS_ATTENTION, item.status); |
1492 | 1539 |
1493 // Click the item and confirm that the panel is activated. | 1540 // Click the item and confirm that the panel is activated. |
1494 TestEvent click_event(ui::ET_MOUSE_PRESSED); | 1541 TestEvent click_event(ui::ET_MOUSE_PRESSED); |
1495 item_controller->ItemSelected(click_event); | 1542 EXPECT_EQ(ash::ShelfItemDelegate::kExistingWindowActivated, |
| 1543 shelf_item_delegate->ItemSelected(click_event)); |
1496 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); | 1544 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); |
1497 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 1545 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
1498 | 1546 |
1499 // Active windows don't show attention. | 1547 // Active windows don't show attention. |
1500 panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true); | 1548 panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true); |
1501 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); | 1549 EXPECT_EQ(ash::STATUS_ACTIVE, item.status); |
1502 } | 1550 } |
1503 | 1551 |
1504 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, | 1552 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, |
1505 ShowInShelfWindowsWithWindowKeySet) { | 1553 ShowInShelfWindowsWithWindowKeySet) { |
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2370 | 2418 |
2371 // Close all windows via the menu item. | 2419 // Close all windows via the menu item. |
2372 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); | 2420 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); |
2373 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); | 2421 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); |
2374 | 2422 |
2375 // Check if "Close" is removed from the context menu. | 2423 // Check if "Close" is removed from the context menu. |
2376 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); | 2424 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); |
2377 ASSERT_FALSE( | 2425 ASSERT_FALSE( |
2378 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); | 2426 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); |
2379 } | 2427 } |
OLD | NEW |