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/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
11 #include "ash/common/shelf/app_list_button.h" | 11 #include "ash/common/shelf/app_list_button.h" |
12 #include "ash/common/shelf/shelf.h" | |
13 #include "ash/common/shelf/shelf_button.h" | 12 #include "ash/common/shelf/shelf_button.h" |
14 #include "ash/common/shelf/shelf_constants.h" | 13 #include "ash/common/shelf/shelf_constants.h" |
15 #include "ash/common/shelf/shelf_model.h" | 14 #include "ash/common/shelf/shelf_model.h" |
16 #include "ash/common/shelf/shelf_view.h" | 15 #include "ash/common/shelf/shelf_view.h" |
17 #include "ash/common/shelf/shelf_widget.h" | 16 #include "ash/common/shelf/shelf_widget.h" |
17 #include "ash/common/shelf/wm_shelf.h" | |
18 #include "ash/common/wm/window_state.h" | 18 #include "ash/common/wm/window_state.h" |
19 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
20 #include "ash/shelf/shelf_util.h" | 20 #include "ash/shelf/shelf_util.h" |
21 #include "ash/shell.h" | 21 #include "ash/shell.h" |
22 #include "ash/test/shelf_test_api.h" | 22 #include "ash/test/shelf_test_api.h" |
23 #include "ash/test/shelf_view_test_api.h" | 23 #include "ash/test/shelf_view_test_api.h" |
24 #include "ash/wm/window_state_aura.h" | 24 #include "ash/wm/window_state_aura.h" |
25 #include "ash/wm/window_util.h" | 25 #include "ash/wm/window_util.h" |
26 #include "base/macros.h" | 26 #include "base/macros.h" |
27 #include "base/run_loop.h" | 27 #include "base/run_loop.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 #include "ui/events/event.h" | 80 #include "ui/events/event.h" |
81 #include "ui/events/event_constants.h" | 81 #include "ui/events/event_constants.h" |
82 #include "ui/events/test/event_generator.h" | 82 #include "ui/events/test/event_generator.h" |
83 | 83 |
84 using extensions::AppWindow; | 84 using extensions::AppWindow; |
85 using extensions::Extension; | 85 using extensions::Extension; |
86 using content::WebContents; | 86 using content::WebContents; |
87 | 87 |
88 namespace { | 88 namespace { |
89 | 89 |
90 // Make the call sites cleaner. C++ "using" doesn't work on methods. | |
msw
2016/08/25 00:22:24
optional nit: I'd just inline 'ash::WmShelf::'.
James Cook
2016/08/25 02:29:13
Done.
| |
91 void ActivateShelfItem(int index) { | |
92 ash::WmShelf::ActivateShelfItem(index); | |
93 } | |
94 | |
90 ChromeLauncherControllerImpl* GetChromeLauncherControllerImpl() { | 95 ChromeLauncherControllerImpl* GetChromeLauncherControllerImpl() { |
91 return static_cast<ChromeLauncherControllerImpl*>( | 96 return static_cast<ChromeLauncherControllerImpl*>( |
92 ChromeLauncherController::instance()); | 97 ChromeLauncherController::instance()); |
93 } | 98 } |
94 | 99 |
95 class TestEvent : public ui::Event { | 100 class TestEvent : public ui::Event { |
96 public: | 101 public: |
97 explicit TestEvent(ui::EventType type) | 102 explicit TestEvent(ui::EventType type) |
98 : ui::Event(type, base::TimeTicks(), 0) {} | 103 : ui::Event(type, base::TimeTicks(), 0) {} |
99 ~TestEvent() override {} | 104 ~TestEvent() override {} |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 // Note that event_flag is never used inside function ExecuteCommand. | 188 // Note that event_flag is never used inside function ExecuteCommand. |
184 menu->ExecuteCommand(close_command, ui::EventFlags::EF_NONE); | 189 menu->ExecuteCommand(close_command, ui::EventFlags::EF_NONE); |
185 close_observer.Wait(); | 190 close_observer.Wait(); |
186 } | 191 } |
187 | 192 |
188 } // namespace | 193 } // namespace |
189 | 194 |
190 class LauncherPlatformAppBrowserTest | 195 class LauncherPlatformAppBrowserTest |
191 : public extensions::PlatformAppBrowserTest { | 196 : public extensions::PlatformAppBrowserTest { |
192 protected: | 197 protected: |
193 LauncherPlatformAppBrowserTest() : shelf_(NULL), controller_(NULL) { | 198 LauncherPlatformAppBrowserTest() : controller_(nullptr) {} |
194 } | |
195 | 199 |
196 ~LauncherPlatformAppBrowserTest() override {} | 200 ~LauncherPlatformAppBrowserTest() override {} |
197 | 201 |
198 void RunTestOnMainThreadLoop() override { | 202 void RunTestOnMainThreadLoop() override { |
199 shelf_ = ash::Shelf::ForPrimaryDisplay(); | |
200 controller_ = GetChromeLauncherControllerImpl(); | 203 controller_ = GetChromeLauncherControllerImpl(); |
201 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); | 204 return extensions::PlatformAppBrowserTest::RunTestOnMainThreadLoop(); |
202 } | 205 } |
203 | 206 |
204 ash::ShelfModel* shelf_model() { return ash::WmShell::Get()->shelf_model(); } | 207 ash::ShelfModel* shelf_model() { return ash::WmShell::Get()->shelf_model(); } |
205 | 208 |
206 ash::ShelfID CreateAppShortcutLauncherItem(const std::string& name) { | 209 ash::ShelfID CreateAppShortcutLauncherItem(const std::string& name) { |
207 return controller_->CreateAppShortcutLauncherItem( | 210 return controller_->CreateAppShortcutLauncherItem( |
208 name, shelf_model()->item_count()); | 211 name, shelf_model()->item_count()); |
209 } | 212 } |
(...skipping 21 matching lines...) Expand all Loading... | |
231 new LauncherApplicationMenuItemModel( | 234 new LauncherApplicationMenuItemModel( |
232 controller_->GetApplicationList(item, event_flags))); | 235 controller_->GetApplicationList(item, event_flags))); |
233 int num_items = 0; | 236 int num_items = 0; |
234 for (int i = 0; i < menu->GetItemCount(); ++i) { | 237 for (int i = 0; i < menu->GetItemCount(); ++i) { |
235 if (menu->GetTypeAt(i) != ui::MenuModel::TYPE_SEPARATOR) | 238 if (menu->GetTypeAt(i) != ui::MenuModel::TYPE_SEPARATOR) |
236 ++num_items; | 239 ++num_items; |
237 } | 240 } |
238 return num_items; | 241 return num_items; |
239 } | 242 } |
240 | 243 |
241 // Activate the shelf item with the given |id|. | |
242 void ActivateShelfItem(int id) { | |
243 shelf_->ActivateShelfItem(id); | |
244 } | |
245 | |
246 ash::Shelf* shelf_; | |
247 ChromeLauncherControllerImpl* controller_; | 244 ChromeLauncherControllerImpl* controller_; |
248 | 245 |
249 private: | 246 private: |
250 | |
251 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest); | 247 DISALLOW_COPY_AND_ASSIGN(LauncherPlatformAppBrowserTest); |
252 }; | 248 }; |
253 | 249 |
254 enum RipOffCommand { | 250 enum RipOffCommand { |
255 // Drag the item off the shelf and let the mouse go. | 251 // Drag the item off the shelf and let the mouse go. |
256 RIP_OFF_ITEM, | 252 RIP_OFF_ITEM, |
257 // Drag the item off the shelf, move the mouse back and then let go. | 253 // Drag the item off the shelf, move the mouse back and then let go. |
258 RIP_OFF_ITEM_AND_RETURN, | 254 RIP_OFF_ITEM_AND_RETURN, |
259 // Drag the item off the shelf and then issue a cancel command. | 255 // Drag the item off the shelf and then issue a cancel command. |
260 RIP_OFF_ITEM_AND_CANCEL, | 256 RIP_OFF_ITEM_AND_CANCEL, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 EXPECT_EQ(++item_count, model_->item_count()); | 317 EXPECT_EQ(++item_count, model_->item_count()); |
322 const ash::ShelfItem& item = *model_->ItemByID(shortcut_id); | 318 const ash::ShelfItem& item = *model_->ItemByID(shortcut_id); |
323 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); | 319 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, item.type); |
324 return item.id; | 320 return item.id; |
325 } | 321 } |
326 | 322 |
327 void RemoveShortcut(ash::ShelfID id) { | 323 void RemoveShortcut(ash::ShelfID id) { |
328 controller_->Unpin(id); | 324 controller_->Unpin(id); |
329 } | 325 } |
330 | 326 |
331 // Activate the shelf item with the given |id|. | |
332 void ActivateShelfItem(int id) { | |
333 shelf_->ActivateShelfItem(id); | |
334 } | |
335 | |
336 ash::ShelfID PinFakeApp(const std::string& name) { | 327 ash::ShelfID PinFakeApp(const std::string& name) { |
337 return controller_->CreateAppShortcutLauncherItem( | 328 return controller_->CreateAppShortcutLauncherItem( |
338 name, model_->item_count()); | 329 name, model_->item_count()); |
339 } | 330 } |
340 | 331 |
341 // Get the index of an item which has the given type. | 332 // Get the index of an item which has the given type. |
342 int GetIndexOfShelfItemType(ash::ShelfItemType type) { | 333 int GetIndexOfShelfItemType(ash::ShelfItemType type) { |
343 return model_->GetItemIndexForType(type); | 334 return model_->GetItemIndexForType(type); |
344 } | 335 } |
345 | 336 |
(...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1643 // would decrease | 1634 // would decrease |
1644 EXPECT_EQ(item_count, shelf_model->item_count()); | 1635 EXPECT_EQ(item_count, shelf_model->item_count()); |
1645 } | 1636 } |
1646 | 1637 |
1647 // Checks that the browser Alt "tabbing" is properly done. | 1638 // Checks that the browser Alt "tabbing" is properly done. |
1648 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTestNoDefaultBrowser, | 1639 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTestNoDefaultBrowser, |
1649 AltNumberBrowserTabbing) { | 1640 AltNumberBrowserTabbing) { |
1650 // Get the number of items in the browser menu. | 1641 // Get the number of items in the browser menu. |
1651 EXPECT_EQ(0u, chrome::GetTotalBrowserCount()); | 1642 EXPECT_EQ(0u, chrome::GetTotalBrowserCount()); |
1652 // The first activation should create a browser at index 1 (App List @ 0). | 1643 // The first activation should create a browser at index 1 (App List @ 0). |
1653 shelf_->ActivateShelfItem(1); | 1644 ActivateShelfItem(1); |
1654 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 1645 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
1655 // A second activation should not create a new instance. | 1646 // A second activation should not create a new instance. |
1656 shelf_->ActivateShelfItem(1); | 1647 ActivateShelfItem(1); |
1657 Browser* browser1 = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); | 1648 Browser* browser1 = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); |
1658 EXPECT_TRUE(browser1); | 1649 EXPECT_TRUE(browser1); |
1659 aura::Window* window1 = browser1->window()->GetNativeWindow(); | 1650 aura::Window* window1 = browser1->window()->GetNativeWindow(); |
1660 Browser* browser2 = CreateBrowser(profile()); | 1651 Browser* browser2 = CreateBrowser(profile()); |
1661 aura::Window* window2 = browser2->window()->GetNativeWindow(); | 1652 aura::Window* window2 = browser2->window()->GetNativeWindow(); |
1662 | 1653 |
1663 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); | 1654 EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); |
1664 EXPECT_NE(window1, window2); | 1655 EXPECT_NE(window1, window2); |
1665 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); | 1656 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); |
1666 | 1657 |
1667 // Activate multiple times the switcher to see that the windows get activated. | 1658 // Activate multiple times the switcher to see that the windows get activated. |
1668 shelf_->ActivateShelfItem(1); | 1659 ActivateShelfItem(1); |
1669 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | 1660 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); |
1670 shelf_->ActivateShelfItem(1); | 1661 ActivateShelfItem(1); |
1671 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); | 1662 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); |
1672 | 1663 |
1673 // Create a third browser - make sure that we do not toggle simply between | 1664 // Create a third browser - make sure that we do not toggle simply between |
1674 // two windows. | 1665 // two windows. |
1675 Browser* browser3 = CreateBrowser(profile()); | 1666 Browser* browser3 = CreateBrowser(profile()); |
1676 aura::Window* window3 = browser3->window()->GetNativeWindow(); | 1667 aura::Window* window3 = browser3->window()->GetNativeWindow(); |
1677 | 1668 |
1678 EXPECT_EQ(3u, chrome::GetTotalBrowserCount()); | 1669 EXPECT_EQ(3u, chrome::GetTotalBrowserCount()); |
1679 EXPECT_NE(window1, window3); | 1670 EXPECT_NE(window1, window3); |
1680 EXPECT_NE(window2, window3); | 1671 EXPECT_NE(window2, window3); |
1681 EXPECT_EQ(window3, ash::wm::GetActiveWindow()); | 1672 EXPECT_EQ(window3, ash::wm::GetActiveWindow()); |
1682 | 1673 |
1683 shelf_->ActivateShelfItem(1); | 1674 ActivateShelfItem(1); |
1684 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | 1675 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); |
1685 shelf_->ActivateShelfItem(1); | 1676 ActivateShelfItem(1); |
1686 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); | 1677 EXPECT_EQ(window2, ash::wm::GetActiveWindow()); |
1687 shelf_->ActivateShelfItem(1); | 1678 ActivateShelfItem(1); |
1688 EXPECT_EQ(window3, ash::wm::GetActiveWindow()); | 1679 EXPECT_EQ(window3, ash::wm::GetActiveWindow()); |
1689 shelf_->ActivateShelfItem(1); | 1680 ActivateShelfItem(1); |
1690 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | 1681 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); |
1691 | 1682 |
1692 // Create anther app and make sure that none of our browsers is active. | 1683 // Create anther app and make sure that none of our browsers is active. |
1693 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, NEW_WINDOW); | 1684 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, NEW_WINDOW); |
1694 EXPECT_NE(window1, ash::wm::GetActiveWindow()); | 1685 EXPECT_NE(window1, ash::wm::GetActiveWindow()); |
1695 EXPECT_NE(window2, ash::wm::GetActiveWindow()); | 1686 EXPECT_NE(window2, ash::wm::GetActiveWindow()); |
1696 | 1687 |
1697 // After activation our browser should be active again. | 1688 // After activation our browser should be active again. |
1698 shelf_->ActivateShelfItem(1); | 1689 ActivateShelfItem(1); |
1699 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); | 1690 EXPECT_EQ(window1, ash::wm::GetActiveWindow()); |
1700 } | 1691 } |
1701 | 1692 |
1702 // Checks that after a session restore, we do not start applications on an | 1693 // Checks that after a session restore, we do not start applications on an |
1703 // activation. | 1694 // activation. |
1704 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, ActivateAfterSessionRestore) { | 1695 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, ActivateAfterSessionRestore) { |
1705 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 1696 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
1706 | 1697 |
1707 // Create a known application. | 1698 // Create a known application. |
1708 ash::ShelfID shortcut_id = CreateShortcut("app1"); | 1699 ash::ShelfID shortcut_id = CreateShortcut("app1"); |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2404 | 2395 |
2405 // Close all windows via the menu item. | 2396 // Close all windows via the menu item. |
2406 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); | 2397 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); |
2407 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); | 2398 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); |
2408 | 2399 |
2409 // Check if "Close" is removed from the context menu. | 2400 // Check if "Close" is removed from the context menu. |
2410 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); | 2401 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); |
2411 ASSERT_FALSE( | 2402 ASSERT_FALSE( |
2412 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); | 2403 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); |
2413 } | 2404 } |
OLD | NEW |