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

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

Issue 2293183002: ash: Remove ash::Shelf in favor of ash::WmShelf (Closed)
Patch Set: rebase again Created 4 years, 3 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/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_button.h" 12 #include "ash/common/shelf/shelf_button.h"
13 #include "ash/common/shelf/shelf_constants.h" 13 #include "ash/common/shelf/shelf_constants.h"
14 #include "ash/common/shelf/shelf_model.h" 14 #include "ash/common/shelf/shelf_model.h"
15 #include "ash/common/shelf/shelf_view.h" 15 #include "ash/common/shelf/shelf_view.h"
16 #include "ash/common/shelf/shelf_widget.h" 16 #include "ash/common/shelf/shelf_widget.h"
17 #include "ash/common/shelf/wm_shelf.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"
23 #include "ash/test/shelf_view_test_api.h" 22 #include "ash/test/shelf_view_test_api.h"
24 #include "ash/wm/window_state_aura.h" 23 #include "ash/wm/window_state_aura.h"
25 #include "ash/wm/window_util.h" 24 #include "ash/wm/window_util.h"
26 #include "base/macros.h" 25 #include "base/macros.h"
27 #include "base/run_loop.h" 26 #include "base/run_loop.h"
28 #include "base/strings/stringprintf.h" 27 #include "base/strings/stringprintf.h"
29 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
30 #include "build/build_config.h" 29 #include "build/build_config.h"
31 #include "chrome/browser/apps/app_browsertest_util.h" 30 #include "chrome/browser/apps/app_browsertest_util.h"
32 #include "chrome/browser/chrome_notification_types.h" 31 #include "chrome/browser/chrome_notification_types.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 }; 254 };
256 255
257 class ShelfAppBrowserTest : public ExtensionBrowserTest { 256 class ShelfAppBrowserTest : public ExtensionBrowserTest {
258 protected: 257 protected:
259 ShelfAppBrowserTest() : shelf_(NULL), model_(NULL), controller_(NULL) { 258 ShelfAppBrowserTest() : shelf_(NULL), model_(NULL), controller_(NULL) {
260 } 259 }
261 260
262 ~ShelfAppBrowserTest() override {} 261 ~ShelfAppBrowserTest() override {}
263 262
264 void RunTestOnMainThreadLoop() override { 263 void RunTestOnMainThreadLoop() override {
265 shelf_ = ash::Shelf::ForPrimaryDisplay(); 264 shelf_ =
265 ash::WmShelf::ForWindow(ash::WmShell::Get()->GetPrimaryRootWindow());
266 model_ = ash::WmShell::Get()->shelf_model(); 266 model_ = ash::WmShell::Get()->shelf_model();
267 controller_ = GetChromeLauncherControllerImpl(); 267 controller_ = GetChromeLauncherControllerImpl();
268 return ExtensionBrowserTest::RunTestOnMainThreadLoop(); 268 return ExtensionBrowserTest::RunTestOnMainThreadLoop();
269 } 269 }
270 270
271 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) { 271 size_t NumberOfDetectedLauncherBrowsers(bool show_all_tabs) {
272 LauncherItemController* item_controller = 272 LauncherItemController* item_controller =
273 controller_->GetBrowserShortcutLauncherItemController(); 273 controller_->GetBrowserShortcutLauncherItemController();
274 int items = item_controller->GetApplicationList( 274 int items = item_controller->GetApplicationList(
275 show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size(); 275 show_all_tabs ? ui::EF_SHIFT_DOWN : 0).size();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 base::RunLoop().RunUntilIdle(); 358 base::RunLoop().RunUntilIdle();
359 test->RunMessageLoopUntilAnimationsDone(); 359 test->RunMessageLoopUntilAnimationsDone();
360 } 360 }
361 } 361 }
362 362
363 // Creates a context menu for the existing browser shortcut item. 363 // Creates a context menu for the existing browser shortcut item.
364 std::unique_ptr<LauncherContextMenu> CreateBrowserItemContextMenu() { 364 std::unique_ptr<LauncherContextMenu> CreateBrowserItemContextMenu() {
365 int index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); 365 int index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT);
366 DCHECK_GE(index, 0); 366 DCHECK_GE(index, 0);
367 ash::ShelfItem item = model_->items()[index]; 367 ash::ShelfItem item = model_->items()[index];
368 ash::Shelf* shelf = 368 ash::WmShelf* shelf =
369 ash::Shelf::ForWindow(ash::WmWindowAura::Get(CurrentContext())); 369 ash::WmShelf::ForWindow(ash::WmWindowAura::Get(CurrentContext()));
370 std::unique_ptr<LauncherContextMenu> menu(LauncherContextMenu::Create( 370 std::unique_ptr<LauncherContextMenu> menu(
371 controller_, &item, ash::test::ShelfTestAPI(shelf).wm_shelf())); 371 LauncherContextMenu::Create(controller_, &item, shelf));
372 return menu; 372 return menu;
373 } 373 }
374 374
375 aura::Window* CurrentContext() { 375 aura::Window* CurrentContext() {
376 aura::Window* root_window = ash::Shell::GetTargetRootWindow(); 376 aura::Window* root_window = ash::Shell::GetTargetRootWindow();
377 DCHECK(root_window); 377 DCHECK(root_window);
378 return root_window; 378 return root_window;
379 } 379 }
380 380
381 bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { 381 bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) {
382 return menu->GetIndexOfCommandId(command_id) != -1; 382 return menu->GetIndexOfCommandId(command_id) != -1;
383 } 383 }
384 384
385 ash::Shelf* shelf_; 385 ash::WmShelf* shelf_;
386 ash::ShelfModel* model_; 386 ash::ShelfModel* model_;
387 ChromeLauncherControllerImpl* controller_; 387 ChromeLauncherControllerImpl* controller_;
388 388
389 private: 389 private:
390 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserTest); 390 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserTest);
391 }; 391 };
392 392
393 class ShelfAppBrowserTestNoDefaultBrowser : public ShelfAppBrowserTest { 393 class ShelfAppBrowserTestNoDefaultBrowser : public ShelfAppBrowserTest {
394 protected: 394 protected:
395 ShelfAppBrowserTestNoDefaultBrowser() {} 395 ShelfAppBrowserTestNoDefaultBrowser() {}
396 ~ShelfAppBrowserTestNoDefaultBrowser() override {} 396 ~ShelfAppBrowserTestNoDefaultBrowser() override {}
397 397
398 void SetUpCommandLine(base::CommandLine* command_line) override { 398 void SetUpCommandLine(base::CommandLine* command_line) override {
399 ShelfAppBrowserTest::SetUpCommandLine(command_line); 399 ShelfAppBrowserTest::SetUpCommandLine(command_line);
400 command_line->AppendSwitch(switches::kNoStartupWindow); 400 command_line->AppendSwitch(switches::kNoStartupWindow);
401 } 401 }
402 402
403 private: 403 private:
404
405 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserTestNoDefaultBrowser); 404 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserTestNoDefaultBrowser);
406 }; 405 };
407 406
408 // Test that we can launch a platform app and get a running item. 407 // Test that we can launch a platform app and get a running item.
409 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) { 408 IN_PROC_BROWSER_TEST_F(LauncherPlatformAppBrowserTest, LaunchUnpinned) {
410 int item_count = shelf_model()->item_count(); 409 int item_count = shelf_model()->item_count();
411 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched"); 410 const Extension* extension = LoadAndLaunchPlatformApp("launch", "Launched");
412 AppWindow* window = CreateAppWindow(browser()->profile(), extension); 411 AppWindow* window = CreateAppWindow(browser()->profile(), extension);
413 ++item_count; 412 ++item_count;
414 ASSERT_EQ(item_count, shelf_model()->item_count()); 413 ASSERT_EQ(item_count, shelf_model()->item_count());
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 browser2); 1739 browser2);
1741 } 1740 }
1742 1741
1743 // Do various drag and drop interaction tests between the application list and 1742 // Do various drag and drop interaction tests between the application list and
1744 // the launcher. 1743 // the launcher.
1745 // TODO(skuhne): Test is flaky with a real compositor: crbug.com/331924 1744 // TODO(skuhne): Test is flaky with a real compositor: crbug.com/331924
1746 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, DISABLED_DragAndDrop) { 1745 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, DISABLED_DragAndDrop) {
1747 // Get a number of interfaces we need. 1746 // Get a number of interfaces we need.
1748 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(), 1747 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(),
1749 gfx::Point()); 1748 gfx::Point());
1750 ash::test::ShelfViewTestAPI test( 1749 ash::test::ShelfViewTestAPI test(shelf_->GetShelfViewForTesting());
1751 ash::test::ShelfTestAPI(shelf_).shelf_view());
1752 AppListService* service = AppListService::Get(); 1750 AppListService* service = AppListService::Get();
1753 1751
1754 // There should be two items in our launcher by this time. 1752 // There should be two items in our launcher by this time.
1755 EXPECT_EQ(2, model_->item_count()); 1753 EXPECT_EQ(2, model_->item_count());
1756 EXPECT_FALSE(service->IsAppListVisible()); 1754 EXPECT_FALSE(service->IsAppListVisible());
1757 1755
1758 // Open the app list menu and check that the drag and drop host was set. 1756 // Open the app list menu and check that the drag and drop host was set.
1759 gfx::Rect app_list_bounds = 1757 gfx::Rect app_list_bounds =
1760 test.shelf_view()->GetAppListButton()->GetBoundsInScreen(); 1758 test.shelf_view()->GetAppListButton()->GetBoundsInScreen();
1761 generator.MoveMouseTo(app_list_bounds.CenterPoint().x(), 1759 generator.MoveMouseTo(app_list_bounds.CenterPoint().x(),
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserTestWithMultiMonitor); 1879 DISALLOW_COPY_AND_ASSIGN(ShelfAppBrowserTestWithMultiMonitor);
1882 }; 1880 };
1883 1881
1884 // Do basic drag and drop interaction tests between the application list and 1882 // Do basic drag and drop interaction tests between the application list and
1885 // the launcher in the secondary monitor. 1883 // the launcher in the secondary monitor.
1886 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTestWithMultiMonitor, 1884 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTestWithMultiMonitor,
1887 BasicDragAndDrop) { 1885 BasicDragAndDrop) {
1888 // Get a number of interfaces we need. 1886 // Get a number of interfaces we need.
1889 DCHECK_EQ(ash::Shell::GetAllRootWindows().size(), 2U); 1887 DCHECK_EQ(ash::Shell::GetAllRootWindows().size(), 2U);
1890 aura::Window* secondary_root_window = ash::Shell::GetAllRootWindows()[1]; 1888 aura::Window* secondary_root_window = ash::Shell::GetAllRootWindows()[1];
1891 ash::Shelf* secondary_shelf = 1889 ash::WmShelf* secondary_shelf =
1892 ash::Shelf::ForWindow(ash::WmWindowAura::Get(secondary_root_window)); 1890 ash::WmShelf::ForWindow(ash::WmWindowAura::Get(secondary_root_window));
1893 1891
1894 ui::test::EventGenerator generator(secondary_root_window, gfx::Point()); 1892 ui::test::EventGenerator generator(secondary_root_window, gfx::Point());
1895 ash::test::ShelfViewTestAPI test( 1893 ash::test::ShelfViewTestAPI test(secondary_shelf->GetShelfViewForTesting());
1896 ash::test::ShelfTestAPI(secondary_shelf).shelf_view());
1897 AppListService* service = AppListService::Get(); 1894 AppListService* service = AppListService::Get();
1898 1895
1899 // There should be two items in our shelf by this time. 1896 // There should be two items in our shelf by this time.
1900 EXPECT_EQ(2, model_->item_count()); 1897 EXPECT_EQ(2, model_->item_count());
1901 EXPECT_FALSE(service->IsAppListVisible()); 1898 EXPECT_FALSE(service->IsAppListVisible());
1902 1899
1903 // Open the app list menu and check that the drag and drop host was set. 1900 // Open the app list menu and check that the drag and drop host was set.
1904 gfx::Rect app_list_bounds = 1901 gfx::Rect app_list_bounds =
1905 test.shelf_view()->GetAppListButton()->GetBoundsInScreen(); 1902 test.shelf_view()->GetAppListButton()->GetBoundsInScreen();
1906 display::Display display = 1903 display::Display display =
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 generator.ReleaseLeftButton(); 1967 generator.ReleaseLeftButton();
1971 base::RunLoop().RunUntilIdle(); 1968 base::RunLoop().RunUntilIdle();
1972 EXPECT_EQ(2, model_->item_count()); 1969 EXPECT_EQ(2, model_->item_count());
1973 } 1970 }
1974 1971
1975 // Do tests for removal of items from the shelf by dragging. 1972 // Do tests for removal of items from the shelf by dragging.
1976 // Disabled due to flake: http://crbug.com/448482 1973 // Disabled due to flake: http://crbug.com/448482
1977 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, DISABLED_DragOffShelf) { 1974 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, DISABLED_DragOffShelf) {
1978 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(), 1975 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(),
1979 gfx::Point()); 1976 gfx::Point());
1980 ash::test::ShelfViewTestAPI test( 1977 ash::test::ShelfViewTestAPI test(shelf_->GetShelfViewForTesting());
1981 ash::test::ShelfTestAPI(shelf_).shelf_view());
1982 test.SetAnimationDuration(1); // Speed up animations for test. 1978 test.SetAnimationDuration(1); // Speed up animations for test.
1983 // Create a known application and check that we have 3 items in the shelf. 1979 // Create a known application and check that we have 3 items in the shelf.
1984 CreateShortcut("app1"); 1980 CreateShortcut("app1");
1985 test.RunMessageLoopUntilAnimationsDone(); 1981 test.RunMessageLoopUntilAnimationsDone();
1986 EXPECT_EQ(3, model_->item_count()); 1982 EXPECT_EQ(3, model_->item_count());
1987 1983
1988 // Test #1: Ripping out the browser item should not change anything. 1984 // Test #1: Ripping out the browser item should not change anything.
1989 int browser_index = GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT); 1985 int browser_index = GetIndexOfShelfItemType(ash::TYPE_BROWSER_SHORTCUT);
1990 EXPECT_LE(0, browser_index); 1986 EXPECT_LE(0, browser_index);
1991 RipOffItemIndex(browser_index, &generator, &test, RIP_OFF_ITEM); 1987 RipOffItemIndex(browser_index, &generator, &test, RIP_OFF_ITEM);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 RipOffItemIndex(app_index, &generator, &test, RIP_OFF_ITEM); 2069 RipOffItemIndex(app_index, &generator, &test, RIP_OFF_ITEM);
2074 EXPECT_EQ(total_count - 2, model_->item_count()); 2070 EXPECT_EQ(total_count - 2, model_->item_count());
2075 EXPECT_FALSE(test.IsOverflowButtonVisible()); 2071 EXPECT_FALSE(test.IsOverflowButtonVisible());
2076 } 2072 }
2077 2073
2078 // Check that clicking on an app shelf item launches a new browser. 2074 // Check that clicking on an app shelf item launches a new browser.
2079 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, ClickItem) { 2075 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, ClickItem) {
2080 // Get a number of interfaces we need. 2076 // Get a number of interfaces we need.
2081 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(), 2077 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(),
2082 gfx::Point()); 2078 gfx::Point());
2083 ash::test::ShelfViewTestAPI test( 2079 ash::test::ShelfViewTestAPI test(shelf_->GetShelfViewForTesting());
2084 ash::test::ShelfTestAPI(shelf_).shelf_view());
2085 AppListService* service = AppListService::Get(); 2080 AppListService* service = AppListService::Get();
2086 // There should be two items in our shelf by this time. 2081 // There should be two items in our shelf by this time.
2087 EXPECT_EQ(2, model_->item_count()); 2082 EXPECT_EQ(2, model_->item_count());
2088 EXPECT_FALSE(service->IsAppListVisible()); 2083 EXPECT_FALSE(service->IsAppListVisible());
2089 2084
2090 // Open the app list menu and check that the drag and drop host was set. 2085 // Open the app list menu and check that the drag and drop host was set.
2091 gfx::Rect app_list_bounds = 2086 gfx::Rect app_list_bounds =
2092 test.shelf_view()->GetAppListButton()->GetBoundsInScreen(); 2087 test.shelf_view()->GetAppListButton()->GetBoundsInScreen();
2093 generator.MoveMouseTo(app_list_bounds.CenterPoint().x(), 2088 generator.MoveMouseTo(app_list_bounds.CenterPoint().x(),
2094 app_list_bounds.CenterPoint().y()); 2089 app_list_bounds.CenterPoint().y());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 EXPECT_EQ(browser_id, ash::GetShelfIDForWindow(window)); 2175 EXPECT_EQ(browser_id, ash::GetShelfIDForWindow(window));
2181 } 2176 }
2182 2177
2183 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, OverflowBubble) { 2178 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, OverflowBubble) {
2184 // Make sure to have a browser window 2179 // Make sure to have a browser window
2185 chrome::NewTab(browser()); 2180 chrome::NewTab(browser());
2186 2181
2187 // No overflow yet. 2182 // No overflow yet.
2188 EXPECT_FALSE(shelf_->shelf_widget()->IsShowingOverflowBubble()); 2183 EXPECT_FALSE(shelf_->shelf_widget()->IsShowingOverflowBubble());
2189 2184
2190 ash::test::ShelfViewTestAPI test( 2185 ash::test::ShelfViewTestAPI test(shelf_->GetShelfViewForTesting());
2191 ash::test::ShelfTestAPI(shelf_).shelf_view());
2192 2186
2193 int items_added = 0; 2187 int items_added = 0;
2194 while (!test.IsOverflowButtonVisible()) { 2188 while (!test.IsOverflowButtonVisible()) {
2195 std::string fake_app_id = base::StringPrintf("fake_app_%d", items_added); 2189 std::string fake_app_id = base::StringPrintf("fake_app_%d", items_added);
2196 PinFakeApp(fake_app_id); 2190 PinFakeApp(fake_app_id);
2197 2191
2198 ++items_added; 2192 ++items_added;
2199 ASSERT_LT(items_added, 10000); 2193 ASSERT_LT(items_added, 10000);
2200 } 2194 }
2201 2195
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
2391 2385
2392 // Close all windows via the menu item. 2386 // Close all windows via the menu item.
2393 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); 2387 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE);
2394 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); 2388 EXPECT_EQ(0u, BrowserList::GetInstance()->size());
2395 2389
2396 // Check if "Close" is removed from the context menu. 2390 // Check if "Close" is removed from the context menu.
2397 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); 2391 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu();
2398 ASSERT_FALSE( 2392 ASSERT_FALSE(
2399 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); 2393 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE));
2400 } 2394 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698