Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(645)

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_browsertest.cc

Issue 2718563008: mash: Use mojo for ShelfItemDelegate and [app] MenuItem. (Closed)
Patch Set: Address comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/shelf/app_list_button.h" 9 #include "ash/common/shelf/app_list_button.h"
10 #include "ash/common/shelf/shelf_button.h" 10 #include "ash/common/shelf/shelf_button.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 #include "testing/gtest/include/gtest/gtest.h" 71 #include "testing/gtest/include/gtest/gtest.h"
72 #include "ui/app_list/app_list_switches.h" 72 #include "ui/app_list/app_list_switches.h"
73 #include "ui/app_list/views/app_list_item_view.h" 73 #include "ui/app_list/views/app_list_item_view.h"
74 #include "ui/app_list/views/apps_grid_view.h" 74 #include "ui/app_list/views/apps_grid_view.h"
75 #include "ui/app_list/views/start_page_view.h" 75 #include "ui/app_list/views/start_page_view.h"
76 #include "ui/app_list/views/tile_item_view.h" 76 #include "ui/app_list/views/tile_item_view.h"
77 #include "ui/aura/client/aura_constants.h" 77 #include "ui/aura/client/aura_constants.h"
78 #include "ui/aura/window.h" 78 #include "ui/aura/window.h"
79 #include "ui/base/window_open_disposition.h" 79 #include "ui/base/window_open_disposition.h"
80 #include "ui/display/test/display_manager_test_api.h" 80 #include "ui/display/test/display_manager_test_api.h"
81 #include "ui/events/base_event_utils.h"
81 #include "ui/events/event.h" 82 #include "ui/events/event.h"
82 #include "ui/events/event_constants.h" 83 #include "ui/events/event_constants.h"
83 #include "ui/events/test/event_generator.h" 84 #include "ui/events/test/event_generator.h"
84 85
85 using ash::WmShelf; 86 using ash::WmShelf;
86 using extensions::AppWindow; 87 using extensions::AppWindow;
87 using extensions::Extension; 88 using extensions::Extension;
88 using content::WebContents; 89 using content::WebContents;
89 90
90 namespace { 91 namespace {
91 92
92 ChromeLauncherControllerImpl* GetChromeLauncherControllerImpl() { 93 ChromeLauncherControllerImpl* GetChromeLauncherControllerImpl() {
93 return static_cast<ChromeLauncherControllerImpl*>( 94 return static_cast<ChromeLauncherControllerImpl*>(
94 ChromeLauncherController::instance()); 95 ChromeLauncherController::instance());
95 } 96 }
96 97
98 // A callback that records the action taken when a shelf item is selected.
99 void SelectItemCallback(ash::ShelfAction* action_taken,
100 base::RunLoop* run_loop,
101 ash::ShelfAction action,
102 std::vector<ash::mojom::MenuItemPtr>) {
103 *action_taken = action;
104 run_loop->Quit();
105 }
106
97 // Calls ShelfItemDelegate::SelectItem with an event type and default arguments. 107 // Calls ShelfItemDelegate::SelectItem with an event type and default arguments.
98 ash::ShelfAction SelectItem(ash::ShelfItemDelegate* delegate, 108 ash::ShelfAction SelectItem(ash::mojom::ShelfItemDelegate* delegate,
99 ui::EventType event_type) { 109 ui::EventType event_type) {
100 return delegate->ItemSelected(event_type, ui::EF_NONE, 110 std::unique_ptr<ui::Event> event;
101 display::kInvalidDisplayId, 111 if (event_type == ui::ET_MOUSE_PRESSED) {
102 ash::LAUNCH_FROM_UNKNOWN); 112 event =
113 base::MakeUnique<ui::MouseEvent>(event_type, gfx::Point(), gfx::Point(),
114 ui::EventTimeForNow(), ui::EF_NONE, 0);
115 } else if (event_type == ui::ET_KEY_RELEASED) {
116 event = base::MakeUnique<ui::KeyEvent>(event_type, ui::VKEY_UNKNOWN,
117 ui::EF_NONE);
118 }
119
120 base::RunLoop run_loop;
121 ash::ShelfAction action = ash::SHELF_ACTION_NONE;
122 delegate->ItemSelected(std::move(event), display::kInvalidDisplayId,
123 ash::LAUNCH_FROM_UNKNOWN,
124 base::Bind(&SelectItemCallback, &action, &run_loop));
125 run_loop.Run();
126 return action;
103 } 127 }
104 128
105 class TestEvent : public ui::Event { 129 class TestEvent : public ui::Event {
106 public: 130 public:
107 explicit TestEvent(ui::EventType type) 131 explicit TestEvent(ui::EventType type)
108 : ui::Event(type, base::TimeTicks(), 0) {} 132 : ui::Event(type, base::TimeTicks(), 0) {}
109 ~TestEvent() override {} 133 ~TestEvent() override {}
110 134
111 private: 135 private:
112 DISALLOW_COPY_AND_ASSIGN(TestEvent); 136 DISALLOW_COPY_AND_ASSIGN(TestEvent);
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 AppWindow* panel = 789 AppWindow* panel =
766 CreateAppWindowFromParams(browser()->profile(), extension1, params); 790 CreateAppWindowFromParams(browser()->profile(), extension1, params);
767 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); 791 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible());
768 // Panels should not be active by default. 792 // Panels should not be active by default.
769 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); 793 EXPECT_FALSE(panel->GetBaseWindow()->IsActive());
770 // Confirm that an item delegate was created and is in the correct state. 794 // Confirm that an item delegate was created and is in the correct state.
771 const ash::ShelfItem& item1 = GetLastLauncherPanelItem(); 795 const ash::ShelfItem& item1 = GetLastLauncherPanelItem();
772 EXPECT_EQ(ash::TYPE_APP_PANEL, item1.type); 796 EXPECT_EQ(ash::TYPE_APP_PANEL, item1.type);
773 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); 797 EXPECT_EQ(ash::STATUS_RUNNING, item1.status);
774 EXPECT_EQ(nullptr, GetItemController(item1.id)); 798 EXPECT_EQ(nullptr, GetItemController(item1.id));
775 ash::ShelfItemDelegate* item1_delegate = 799 ash::mojom::ShelfItemDelegate* item1_delegate =
776 shelf_model()->GetShelfItemDelegate(item1.id); 800 shelf_model()->GetShelfItemDelegate(item1.id);
777 EXPECT_EQ(ash::TYPE_APP_PANEL, 801 EXPECT_EQ(ash::TYPE_APP_PANEL,
778 panel->GetNativeWindow()->GetProperty(ash::kShelfItemTypeKey)); 802 panel->GetNativeWindow()->GetProperty(ash::kShelfItemTypeKey));
779 // Click the item and confirm that the panel is activated. 803 // Click the item and confirm that the panel is activated.
780 SelectItem(item1_delegate, ui::ET_MOUSE_PRESSED); 804 SelectItem(item1_delegate, ui::ET_MOUSE_PRESSED);
781 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); 805 EXPECT_TRUE(panel->GetBaseWindow()->IsActive());
782 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 806 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
783 // Click the item again and confirm that the panel is minimized. 807 // Click the item again and confirm that the panel is minimized.
784 SelectItem(item1_delegate, ui::ET_MOUSE_PRESSED); 808 SelectItem(item1_delegate, ui::ET_MOUSE_PRESSED);
785 EXPECT_TRUE(panel->GetBaseWindow()->IsMinimized()); 809 EXPECT_TRUE(panel->GetBaseWindow()->IsMinimized());
(...skipping 19 matching lines...) Expand all
805 AppWindow* panel = 829 AppWindow* panel =
806 CreateAppWindowFromParams(browser()->profile(), extension1, params); 830 CreateAppWindowFromParams(browser()->profile(), extension1, params);
807 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); 831 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible());
808 // Panels should not be active by default. 832 // Panels should not be active by default.
809 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); 833 EXPECT_FALSE(panel->GetBaseWindow()->IsActive());
810 // Confirm that an item delegate was created and is in the correct state. 834 // Confirm that an item delegate was created and is in the correct state.
811 const ash::ShelfItem& item1 = GetLastLauncherPanelItem(); 835 const ash::ShelfItem& item1 = GetLastLauncherPanelItem();
812 EXPECT_EQ(ash::TYPE_APP_PANEL, item1.type); 836 EXPECT_EQ(ash::TYPE_APP_PANEL, item1.type);
813 EXPECT_EQ(ash::STATUS_RUNNING, item1.status); 837 EXPECT_EQ(ash::STATUS_RUNNING, item1.status);
814 EXPECT_EQ(nullptr, GetItemController(item1.id)); 838 EXPECT_EQ(nullptr, GetItemController(item1.id));
815 ash::ShelfItemDelegate* item1_delegate = 839 ash::mojom::ShelfItemDelegate* item1_delegate =
816 shelf_model()->GetShelfItemDelegate(item1.id); 840 shelf_model()->GetShelfItemDelegate(item1.id);
817 EXPECT_EQ(ash::TYPE_APP_PANEL, 841 EXPECT_EQ(ash::TYPE_APP_PANEL,
818 panel->GetNativeWindow()->GetProperty(ash::kShelfItemTypeKey)); 842 panel->GetNativeWindow()->GetProperty(ash::kShelfItemTypeKey));
819 // Click the item and confirm that the panel is activated. 843 // Click the item and confirm that the panel is activated.
820 SelectItem(item1_delegate, ui::ET_MOUSE_PRESSED); 844 SelectItem(item1_delegate, ui::ET_MOUSE_PRESSED);
821 EXPECT_TRUE(panel->GetBaseWindow()->IsActive()); 845 EXPECT_TRUE(panel->GetBaseWindow()->IsActive());
822 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status); 846 EXPECT_EQ(ash::STATUS_ACTIVE, item1.status);
823 // Click the item again and confirm that the panel is minimized. 847 // Click the item again and confirm that the panel is minimized.
824 SelectItem(item1_delegate, ui::ET_MOUSE_PRESSED); 848 SelectItem(item1_delegate, ui::ET_MOUSE_PRESSED);
825 EXPECT_TRUE(panel->GetBaseWindow()->IsMinimized()); 849 EXPECT_TRUE(panel->GetBaseWindow()->IsMinimized());
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 params.focused = false; 1537 params.focused = false;
1514 AppWindow* panel = 1538 AppWindow* panel =
1515 CreateAppWindowFromParams(browser()->profile(), extension, params); 1539 CreateAppWindowFromParams(browser()->profile(), extension, params);
1516 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible()); 1540 EXPECT_TRUE(panel->GetNativeWindow()->IsVisible());
1517 // Panels should not be active by default. 1541 // Panels should not be active by default.
1518 EXPECT_FALSE(panel->GetBaseWindow()->IsActive()); 1542 EXPECT_FALSE(panel->GetBaseWindow()->IsActive());
1519 // Confirm that a shelf item was created and is the correct state. 1543 // Confirm that a shelf item was created and is the correct state.
1520 const ash::ShelfItem& item = GetLastLauncherPanelItem(); 1544 const ash::ShelfItem& item = GetLastLauncherPanelItem();
1521 // Panels are handled by ShelfWindowWatcher, not ChromeLauncherController. 1545 // Panels are handled by ShelfWindowWatcher, not ChromeLauncherController.
1522 EXPECT_EQ(nullptr, GetItemController(item.id)); 1546 EXPECT_EQ(nullptr, GetItemController(item.id));
1523 ash::ShelfItemDelegate* shelf_item_delegate = 1547 ash::mojom::ShelfItemDelegate* shelf_item_delegate =
1524 shelf_model()->GetShelfItemDelegate(item.id); 1548 shelf_model()->GetShelfItemDelegate(item.id);
1525 EXPECT_NE(nullptr, shelf_item_delegate); 1549 EXPECT_NE(nullptr, shelf_item_delegate);
1526 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type); 1550 EXPECT_EQ(ash::TYPE_APP_PANEL, item.type);
1527 EXPECT_EQ(ash::STATUS_RUNNING, item.status); 1551 EXPECT_EQ(ash::STATUS_RUNNING, item.status);
1528 1552
1529 // App windows should go to attention state. 1553 // App windows should go to attention state.
1530 panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true); 1554 panel->GetNativeWindow()->SetProperty(aura::client::kDrawAttentionKey, true);
1531 EXPECT_EQ(ash::STATUS_ATTENTION, item.status); 1555 EXPECT_EQ(ash::STATUS_ATTENTION, item.status);
1532 1556
1533 // Click the item and confirm that the panel is activated. 1557 // Click the item and confirm that the panel is activated.
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
2392 2416
2393 // Close all windows via the menu item. 2417 // Close all windows via the menu item.
2394 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); 2418 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE);
2395 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); 2419 EXPECT_EQ(0u, BrowserList::GetInstance()->size());
2396 2420
2397 // Check if "Close" is removed from the context menu. 2421 // Check if "Close" is removed from the context menu.
2398 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); 2422 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu();
2399 ASSERT_FALSE( 2423 ASSERT_FALSE(
2400 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); 2424 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE));
2401 } 2425 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698