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

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

Issue 2894743002: Make launching apps from shelf more intuitive (Closed)
Patch Set: Affected by new revision, gclient sync and re-upload. Created 3 years, 6 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.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "ash/public/cpp/shelf_item_delegate.h" 9 #include "ash/public/cpp/shelf_item_delegate.h"
10 #include "ash/public/cpp/window_properties.h" 10 #include "ash/public/cpp/window_properties.h"
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 EXPECT_EQ(++tab_count, tab_strip->count()); 917 EXPECT_EQ(++tab_count, tab_strip->count());
918 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 918 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
919 WebContents* tab = tab_strip->GetActiveWebContents(); 919 WebContents* tab = tab_strip->GetActiveWebContents();
920 content::WebContentsDestroyedWatcher destroyed_watcher(tab); 920 content::WebContentsDestroyedWatcher destroyed_watcher(tab);
921 browser()->tab_strip_model()->CloseSelectedTabs(); 921 browser()->tab_strip_model()->CloseSelectedTabs();
922 destroyed_watcher.Wait(); 922 destroyed_watcher.Wait();
923 EXPECT_EQ(--tab_count, tab_strip->count()); 923 EXPECT_EQ(--tab_count, tab_strip->count());
924 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 924 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
925 } 925 }
926 926
927 // Tests behavior of launching app from shelf in the first display while the
928 // second display has the focus. Initially, Browsers exists in the first
929 // display.
930 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchAppFromDisplayWithoutFocus0) {
931 // Updates the display configuration to add a secondary display.
932 display::DisplayManager* display_manager =
933 ash::Shell::Get()->display_manager();
934 display::test::DisplayManagerTestApi(display_manager)
935 .UpdateDisplay("0+0-800x800,801+0-800x800");
936 display::Displays displays = display_manager->active_display_list();
937 aura::Window::Windows roots = ash::Shell::GetAllRootWindows();
938 EXPECT_EQ(displays.size(), 2U);
939 EXPECT_EQ(roots.size(), 2U);
940 EXPECT_EQ(
941 displays[0].id(),
942 display::Screen::GetScreen()->GetDisplayNearestWindow(roots[0]).id());
943 EXPECT_EQ(
944 displays[1].id(),
945 display::Screen::GetScreen()->GetDisplayNearestWindow(roots[1]).id());
946
947 // Ensures that display 0 has one browser with focus and display 1 has two
948 // browsers. Each browser only has one tab.
949 BrowserList* browser_list = BrowserList::GetInstance();
950 Browser* browser0 = browser();
951 Browser* browser1 = CreateBrowser(browser()->profile());
952 Browser* browser2 = CreateBrowser(browser()->profile());
953 browser0->window()->SetBounds(displays[0].work_area());
954 browser1->window()->SetBounds(displays[1].work_area());
955 browser2->window()->SetBounds(displays[1].work_area());
956 // Ensures browser 2 is above browser 1 in display 1.
957 browser_list->SetLastActive(browser2);
958 browser_list->SetLastActive(browser0);
959 EXPECT_EQ(browser_list->size(), 3U);
960 EXPECT_EQ(browser0->window()->GetNativeWindow()->GetRootWindow(), roots[0]);
961 EXPECT_EQ(browser1->window()->GetNativeWindow()->GetRootWindow(), roots[1]);
962 EXPECT_EQ(browser2->window()->GetNativeWindow()->GetRootWindow(), roots[1]);
963 EXPECT_EQ(browser0->tab_strip_model()->count(), 1);
964 EXPECT_EQ(browser1->tab_strip_model()->count(), 1);
965 EXPECT_EQ(browser2->tab_strip_model()->count(), 1);
966
967 // Launches an app from the shelf of display 0 and expects a new tab is opened
968 // in the uppermost browser in display 0.
969 ash::ShelfID shortcut_id = CreateShortcut("app1");
970 Shelf::ActivateShelfItemOnDisplay(model_->ItemIndexByID(shortcut_id),
971 displays[1].id());
972 EXPECT_EQ(browser0->tab_strip_model()->count(), 1);
973 EXPECT_EQ(browser1->tab_strip_model()->count(), 1);
974 EXPECT_EQ(browser2->tab_strip_model()->count(), 2);
975 }
976
977 // Tests behavior of launching app from shelf in the first display while the
978 // second display has the focus. Initially, No browser exists in the first
979 // display.
980 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchAppFromDisplayWithoutFocus1) {
981 // Updates the display configuration to add a secondary display.
982 display::DisplayManager* display_manager =
983 ash::Shell::Get()->display_manager();
984 display::test::DisplayManagerTestApi(display_manager)
985 .UpdateDisplay("800x800,801+0-800x800");
986 display::Displays displays = display_manager->active_display_list();
987 aura::Window::Windows roots = ash::Shell::GetAllRootWindows();
988 EXPECT_EQ(displays.size(), 2U);
989 EXPECT_EQ(roots.size(), 2U);
990 EXPECT_EQ(
991 displays[0].id(),
992 display::Screen::GetScreen()->GetDisplayNearestWindow(roots[0]).id());
993 EXPECT_EQ(
994 displays[1].id(),
995 display::Screen::GetScreen()->GetDisplayNearestWindow(roots[1]).id());
996
997 // Ensures that display 0 has one browser with focus and display 1 has no
998 // browser. The browser only has one tab.
999 BrowserList* browser_list = BrowserList::GetInstance();
1000 Browser* browser0 = browser();
1001 browser0->window()->SetBounds(displays[0].work_area());
1002 EXPECT_EQ(browser_list->size(), 1U);
1003 EXPECT_EQ(browser0->window()->GetNativeWindow()->GetRootWindow(), roots[0]);
1004 EXPECT_EQ(browser0->tab_strip_model()->count(), 1);
1005
1006 // Launches an app from the shelf of display 0 and expects a new browser with
1007 // one tab is opened in display 0.
1008 ash::ShelfID shortcut_id = CreateShortcut("app1");
1009 Shelf::ActivateShelfItemOnDisplay(model_->ItemIndexByID(shortcut_id),
1010 displays[1].id());
1011 Browser* browser1 = browser_list->GetLastActive();
1012 EXPECT_EQ(browser_list->size(), 2U);
1013 EXPECT_NE(browser1, browser0);
1014 EXPECT_EQ(browser0->tab_strip_model()->count(), 1);
1015 EXPECT_EQ(browser1->tab_strip_model()->count(), 1);
1016 }
1017
927 // Launch the app first and then create the shortcut. 1018 // Launch the app first and then create the shortcut.
928 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchUnpinned) { 1019 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchUnpinned) {
929 TabStripModel* tab_strip = browser()->tab_strip_model(); 1020 TabStripModel* tab_strip = browser()->tab_strip_model();
930 int tab_count = tab_strip->count(); 1021 int tab_count = tab_strip->count();
931 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, 1022 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB,
932 WindowOpenDisposition::NEW_FOREGROUND_TAB); 1023 WindowOpenDisposition::NEW_FOREGROUND_TAB);
933 EXPECT_EQ(++tab_count, tab_strip->count()); 1024 EXPECT_EQ(++tab_count, tab_strip->count());
934 ash::ShelfID shortcut_id = CreateShortcut("app1"); 1025 ash::ShelfID shortcut_id = CreateShortcut("app1");
935 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status); 1026 EXPECT_EQ(ash::STATUS_ACTIVE, (*model_->ItemByID(shortcut_id)).status);
936 WebContents* tab = tab_strip->GetActiveWebContents(); 1027 WebContents* tab = tab_strip->GetActiveWebContents();
937 content::WebContentsDestroyedWatcher destroyed_watcher(tab); 1028 content::WebContentsDestroyedWatcher destroyed_watcher(tab);
938 browser()->tab_strip_model()->CloseSelectedTabs(); 1029 browser()->tab_strip_model()->CloseSelectedTabs();
939 destroyed_watcher.Wait(); 1030 destroyed_watcher.Wait();
940 EXPECT_EQ(--tab_count, tab_strip->count()); 1031 EXPECT_EQ(--tab_count, tab_strip->count());
941 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status); 1032 EXPECT_EQ(ash::STATUS_CLOSED, (*model_->ItemByID(shortcut_id)).status);
942 } 1033 }
943 1034
944 // Launches an app in the background and then tries to open it. This is test for 1035 // Launches an app in the background and then tries to open it. This is test for
945 // a crash we had. 1036 // a crash we had.
946 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchInBackground) { 1037 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchInBackground) {
947 TabStripModel* tab_strip = browser()->tab_strip_model(); 1038 TabStripModel* tab_strip = browser()->tab_strip_model();
948 int tab_count = tab_strip->count(); 1039 int tab_count = tab_strip->count();
949 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB, 1040 LoadAndLaunchExtension("app1", extensions::LAUNCH_CONTAINER_TAB,
950 WindowOpenDisposition::NEW_BACKGROUND_TAB); 1041 WindowOpenDisposition::NEW_BACKGROUND_TAB);
951 EXPECT_EQ(++tab_count, tab_strip->count()); 1042 EXPECT_EQ(++tab_count, tab_strip->count());
952 controller_->LaunchApp(ash::ShelfID(last_loaded_extension_id()), 1043 controller_->LaunchApp(ash::ShelfID(last_loaded_extension_id()),
953 ash::LAUNCH_FROM_UNKNOWN, 0); 1044 ash::LAUNCH_FROM_UNKNOWN, 0,
1045 display::kInvalidDisplayId);
954 } 1046 }
955 1047
956 // Confirm that clicking a icon for an app running in one of 2 maxmized windows 1048 // Confirm that clicking a icon for an app running in one of 2 maxmized windows
957 // activates the right window. 1049 // activates the right window.
958 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchMaximized) { 1050 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchMaximized) {
959 aura::Window* window1 = browser()->window()->GetNativeWindow(); 1051 aura::Window* window1 = browser()->window()->GetNativeWindow();
960 ash::wm::WindowState* window1_state = ash::wm::GetWindowState(window1); 1052 ash::wm::WindowState* window1_state = ash::wm::GetWindowState(window1);
961 window1_state->Maximize(); 1053 window1_state->Maximize();
962 content::WindowedNotificationObserver open_observer( 1054 content::WindowedNotificationObserver open_observer(
963 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 1055 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
(...skipping 30 matching lines...) Expand all
994 EXPECT_EQ(++tab_count, tab_strip->count()); 1086 EXPECT_EQ(++tab_count, tab_strip->count());
995 controller_->ActivateApp(extension->id(), ash::LAUNCH_FROM_UNKNOWN, 0); 1087 controller_->ActivateApp(extension->id(), ash::LAUNCH_FROM_UNKNOWN, 0);
996 EXPECT_EQ(tab_count, tab_strip->count()); 1088 EXPECT_EQ(tab_count, tab_strip->count());
997 } 1089 }
998 1090
999 // Launching the same app multiple times should launch a copy for each call. 1091 // Launching the same app multiple times should launch a copy for each call.
1000 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchApp) { 1092 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, LaunchApp) {
1001 TabStripModel* tab_strip = browser()->tab_strip_model(); 1093 TabStripModel* tab_strip = browser()->tab_strip_model();
1002 int tab_count = tab_strip->count(); 1094 int tab_count = tab_strip->count();
1003 ash::ShelfID id(LoadExtension(test_data_dir_.AppendASCII("app1"))->id()); 1095 ash::ShelfID id(LoadExtension(test_data_dir_.AppendASCII("app1"))->id());
1004 controller_->LaunchApp(id, ash::LAUNCH_FROM_UNKNOWN, 0); 1096 controller_->LaunchApp(id, ash::LAUNCH_FROM_UNKNOWN, 0,
1097 display::kInvalidDisplayId);
1005 EXPECT_EQ(++tab_count, tab_strip->count()); 1098 EXPECT_EQ(++tab_count, tab_strip->count());
1006 controller_->LaunchApp(id, ash::LAUNCH_FROM_UNKNOWN, 0); 1099 controller_->LaunchApp(id, ash::LAUNCH_FROM_UNKNOWN, 0,
1100 display::kInvalidDisplayId);
1007 EXPECT_EQ(++tab_count, tab_strip->count()); 1101 EXPECT_EQ(++tab_count, tab_strip->count());
1008 } 1102 }
1009 1103
1010 // Launch 2 apps and toggle which is active. 1104 // Launch 2 apps and toggle which is active.
1011 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, MultipleApps) { 1105 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, MultipleApps) {
1012 int item_count = model_->item_count(); 1106 int item_count = model_->item_count();
1013 TabStripModel* tab_strip = browser()->tab_strip_model(); 1107 TabStripModel* tab_strip = browser()->tab_strip_model();
1014 int tab_count = tab_strip->count(); 1108 int tab_count = tab_strip->count();
1015 ash::ShelfID shortcut1 = CreateShortcut("app1"); 1109 ash::ShelfID shortcut1 = CreateShortcut("app1");
1016 EXPECT_EQ(++item_count, model_->item_count()); 1110 EXPECT_EQ(++item_count, model_->item_count());
(...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 2495
2402 // Close all windows via the menu item. 2496 // Close all windows via the menu item.
2403 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); 2497 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE);
2404 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); 2498 EXPECT_EQ(0u, BrowserList::GetInstance()->size());
2405 2499
2406 // Check if "Close" is removed from the context menu. 2500 // Check if "Close" is removed from the context menu.
2407 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); 2501 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu();
2408 ASSERT_FALSE( 2502 ASSERT_FALSE(
2409 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); 2503 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE));
2410 } 2504 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc ('k') | chrome/browser/ui/ash/launcher/launcher_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698