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