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/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/shelf/shelf.h" | 10 #include "ash/shelf/shelf.h" |
11 #include "ash/shelf/shelf_button.h" | 11 #include "ash/shelf/shelf_button.h" |
12 #include "ash/shelf/shelf_constants.h" | 12 #include "ash/shelf/shelf_constants.h" |
13 #include "ash/shelf/shelf_model.h" | 13 #include "ash/shelf/shelf_model.h" |
14 #include "ash/shelf/shelf_util.h" | 14 #include "ash/shelf/shelf_util.h" |
15 #include "ash/shelf/shelf_view.h" | 15 #include "ash/shelf/shelf_view.h" |
16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
17 #include "ash/test/app_list_controller_test_api.h" | |
18 #include "ash/test/shelf_test_api.h" | 17 #include "ash/test/shelf_test_api.h" |
19 #include "ash/test/shelf_view_test_api.h" | 18 #include "ash/test/shelf_view_test_api.h" |
20 #include "ash/test/shell_test_api.h" | 19 #include "ash/test/shell_test_api.h" |
21 #include "ash/wm/window_state.h" | 20 #include "ash/wm/window_state.h" |
22 #include "ash/wm/window_util.h" | 21 #include "ash/wm/window_util.h" |
23 #include "base/macros.h" | 22 #include "base/macros.h" |
24 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
25 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
26 #include "build/build_config.h" | 25 #include "build/build_config.h" |
27 #include "chrome/browser/apps/app_browsertest_util.h" | 26 #include "chrome/browser/apps/app_browsertest_util.h" |
28 #include "chrome/browser/chrome_notification_types.h" | 27 #include "chrome/browser/chrome_notification_types.h" |
29 #include "chrome/browser/extensions/extension_apitest.h" | 28 #include "chrome/browser/extensions/extension_apitest.h" |
30 #include "chrome/browser/extensions/extension_browsertest.h" | 29 #include "chrome/browser/extensions/extension_browsertest.h" |
31 #include "chrome/browser/extensions/extension_function_test_utils.h" | 30 #include "chrome/browser/extensions/extension_function_test_utils.h" |
32 #include "chrome/browser/extensions/extension_service.h" | 31 #include "chrome/browser/extensions/extension_service.h" |
33 #include "chrome/browser/extensions/launch_util.h" | 32 #include "chrome/browser/extensions/launch_util.h" |
34 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
35 #include "chrome/browser/ui/app_list/app_list_service.h" | 34 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 35 #include "chrome/browser/ui/ash/app_list/test/app_list_service_ash_test_api.h" |
36 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" | 36 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
37 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" | 37 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" |
38 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 38 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
39 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
40 #include "chrome/browser/ui/browser_commands.h" | 40 #include "chrome/browser/ui/browser_commands.h" |
41 #include "chrome/browser/ui/browser_finder.h" | 41 #include "chrome/browser/ui/browser_finder.h" |
42 #include "chrome/browser/ui/browser_list.h" | 42 #include "chrome/browser/ui/browser_list.h" |
43 #include "chrome/browser/ui/browser_window.h" | 43 #include "chrome/browser/ui/browser_window.h" |
44 #include "chrome/browser/ui/chrome_pages.h" | 44 #include "chrome/browser/ui/chrome_pages.h" |
45 #include "chrome/browser/ui/extensions/app_launch_params.h" | 45 #include "chrome/browser/ui/extensions/app_launch_params.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // Click the "All Apps" button from the app launcher start page. Assumes that | 119 // Click the "All Apps" button from the app launcher start page. Assumes that |
120 // the app launcher is open to the start page. On the non-experimental launcher, | 120 // the app launcher is open to the start page. On the non-experimental launcher, |
121 // does nothing. | 121 // does nothing. |
122 // |display_origin| is the top-left corner of the active display, in screen | 122 // |display_origin| is the top-left corner of the active display, in screen |
123 // coordinates. | 123 // coordinates. |
124 void ClickAllAppsButtonFromStartPage(ui::test::EventGenerator* generator, | 124 void ClickAllAppsButtonFromStartPage(ui::test::EventGenerator* generator, |
125 const gfx::Point& display_origin) { | 125 const gfx::Point& display_origin) { |
126 if (!app_list::switches::IsExperimentalAppListEnabled()) | 126 if (!app_list::switches::IsExperimentalAppListEnabled()) |
127 return; | 127 return; |
128 | 128 |
129 ash::test::AppListControllerTestApi controller_test( | 129 AppListServiceAshTestApi service_test; |
130 ash::Shell::GetInstance()); | |
131 | 130 |
132 app_list::StartPageView* start_page_view = controller_test.GetStartPageView(); | 131 app_list::StartPageView* start_page_view = service_test.GetStartPageView(); |
133 DCHECK(start_page_view); | 132 DCHECK(start_page_view); |
134 | 133 |
135 app_list::TileItemView* all_apps_button = start_page_view->all_apps_button(); | 134 app_list::TileItemView* all_apps_button = start_page_view->all_apps_button(); |
136 gfx::Rect all_apps_rect = all_apps_button->GetBoundsInScreen(); | 135 gfx::Rect all_apps_rect = all_apps_button->GetBoundsInScreen(); |
137 all_apps_rect.Offset(-display_origin.x(), -display_origin.y()); | 136 all_apps_rect.Offset(-display_origin.x(), -display_origin.y()); |
138 generator->MoveMouseTo(all_apps_rect.CenterPoint().x(), | 137 generator->MoveMouseTo(all_apps_rect.CenterPoint().x(), |
139 all_apps_rect.CenterPoint().y()); | 138 all_apps_rect.CenterPoint().y()); |
140 generator->ClickLeftButton(); | 139 generator->ClickLeftButton(); |
141 base::MessageLoop::current()->RunUntilIdle(); | 140 base::MessageLoop::current()->RunUntilIdle(); |
142 // Run Layout() to effectively complete the animation to the apps page. | 141 // Run Layout() to effectively complete the animation to the apps page. |
143 controller_test.LayoutContentsView(); | 142 service_test.LayoutContentsView(); |
144 } | 143 } |
145 | 144 |
146 // Find the browser that associated with |app_name|. | 145 // Find the browser that associated with |app_name|. |
147 Browser* FindBrowserForApp(const std::string& app_name) { | 146 Browser* FindBrowserForApp(const std::string& app_name) { |
148 for (auto* browser : *BrowserList::GetInstance()) { | 147 for (auto* browser : *BrowserList::GetInstance()) { |
149 std::string browser_app_name = | 148 std::string browser_app_name = |
150 web_app::GetExtensionIdFromApplicationName(browser->app_name()); | 149 web_app::GetExtensionIdFromApplicationName(browser->app_name()); |
151 if (browser_app_name == app_name) | 150 if (browser_app_name == app_name) |
152 return browser; | 151 return browser; |
153 } | 152 } |
(...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 // Open the app list menu and check that the drag and drop host was set. | 1617 // Open the app list menu and check that the drag and drop host was set. |
1619 gfx::Rect app_list_bounds = | 1618 gfx::Rect app_list_bounds = |
1620 test.shelf_view()->GetAppListButtonView()->GetBoundsInScreen(); | 1619 test.shelf_view()->GetAppListButtonView()->GetBoundsInScreen(); |
1621 generator.MoveMouseTo(app_list_bounds.CenterPoint().x(), | 1620 generator.MoveMouseTo(app_list_bounds.CenterPoint().x(), |
1622 app_list_bounds.CenterPoint().y()); | 1621 app_list_bounds.CenterPoint().y()); |
1623 base::MessageLoop::current()->RunUntilIdle(); | 1622 base::MessageLoop::current()->RunUntilIdle(); |
1624 generator.ClickLeftButton(); | 1623 generator.ClickLeftButton(); |
1625 | 1624 |
1626 EXPECT_TRUE(service->IsAppListVisible()); | 1625 EXPECT_TRUE(service->IsAppListVisible()); |
1627 app_list::AppsGridView* grid_view = | 1626 app_list::AppsGridView* grid_view = |
1628 ash::test::AppListControllerTestApi(ash::Shell::GetInstance()). | 1627 AppListServiceAshTestApi().GetRootGridView(); |
1629 GetRootGridView(); | |
1630 ASSERT_TRUE(grid_view); | 1628 ASSERT_TRUE(grid_view); |
1631 ASSERT_TRUE(grid_view->has_drag_and_drop_host_for_test()); | 1629 ASSERT_TRUE(grid_view->has_drag_and_drop_host_for_test()); |
1632 | 1630 |
1633 // There should be 2 items in our application list. | 1631 // There should be 2 items in our application list. |
1634 const views::ViewModelT<app_list::AppListItemView>* vm_grid = | 1632 const views::ViewModelT<app_list::AppListItemView>* vm_grid = |
1635 grid_view->view_model_for_test(); | 1633 grid_view->view_model_for_test(); |
1636 EXPECT_EQ(2, vm_grid->view_size()); | 1634 EXPECT_EQ(2, vm_grid->view_size()); |
1637 | 1635 |
1638 // Test #1: Drag an app list which does not exist yet item into the | 1636 // Test #1: Drag an app list which does not exist yet item into the |
1639 // launcher. Keeping it dragged, see that a new item gets created. Continuing | 1637 // launcher. Keeping it dragged, see that a new item gets created. Continuing |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1773 app_list_bounds.CenterPoint().y()); | 1771 app_list_bounds.CenterPoint().y()); |
1774 generator.ClickLeftButton(); | 1772 generator.ClickLeftButton(); |
1775 base::MessageLoop::current()->RunUntilIdle(); | 1773 base::MessageLoop::current()->RunUntilIdle(); |
1776 EXPECT_TRUE(service->IsAppListVisible()); | 1774 EXPECT_TRUE(service->IsAppListVisible()); |
1777 | 1775 |
1778 // Click the "all apps" button on the start page. | 1776 // Click the "all apps" button on the start page. |
1779 ClickAllAppsButtonFromStartPage(&generator, origin); | 1777 ClickAllAppsButtonFromStartPage(&generator, origin); |
1780 EXPECT_TRUE(service->IsAppListVisible()); | 1778 EXPECT_TRUE(service->IsAppListVisible()); |
1781 | 1779 |
1782 app_list::AppsGridView* grid_view = | 1780 app_list::AppsGridView* grid_view = |
1783 ash::test::AppListControllerTestApi(ash::Shell::GetInstance()). | 1781 AppListServiceAshTestApi().GetRootGridView(); |
1784 GetRootGridView(); | |
1785 ASSERT_TRUE(grid_view); | 1782 ASSERT_TRUE(grid_view); |
1786 ASSERT_TRUE(grid_view->has_drag_and_drop_host_for_test()); | 1783 ASSERT_TRUE(grid_view->has_drag_and_drop_host_for_test()); |
1787 | 1784 |
1788 // There should be 2 items in our application list. | 1785 // There should be 2 items in our application list. |
1789 const views::ViewModelT<app_list::AppListItemView>* vm_grid = | 1786 const views::ViewModelT<app_list::AppListItemView>* vm_grid = |
1790 grid_view->view_model_for_test(); | 1787 grid_view->view_model_for_test(); |
1791 EXPECT_EQ(2, vm_grid->view_size()); | 1788 EXPECT_EQ(2, vm_grid->view_size()); |
1792 | 1789 |
1793 // Drag an app list item which does not exist yet in the shelf. | 1790 // Drag an app list item which does not exist yet in the shelf. |
1794 // Keeping it dragged, see that a new item gets created. | 1791 // Keeping it dragged, see that a new item gets created. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1957 generator.ClickLeftButton(); | 1954 generator.ClickLeftButton(); |
1958 base::MessageLoop::current()->RunUntilIdle(); | 1955 base::MessageLoop::current()->RunUntilIdle(); |
1959 EXPECT_TRUE(service->IsAppListVisible()); | 1956 EXPECT_TRUE(service->IsAppListVisible()); |
1960 | 1957 |
1961 // Click the "all apps" button on the start page. | 1958 // Click the "all apps" button on the start page. |
1962 ClickAllAppsButtonFromStartPage(&generator, gfx::Point()); | 1959 ClickAllAppsButtonFromStartPage(&generator, gfx::Point()); |
1963 EXPECT_TRUE(service->IsAppListVisible()); | 1960 EXPECT_TRUE(service->IsAppListVisible()); |
1964 | 1961 |
1965 // Click an app icon in the app grid view. | 1962 // Click an app icon in the app grid view. |
1966 app_list::AppsGridView* grid_view = | 1963 app_list::AppsGridView* grid_view = |
1967 ash::test::AppListControllerTestApi(ash::Shell::GetInstance()). | 1964 AppListServiceAshTestApi().GetRootGridView(); |
1968 GetRootGridView(); | |
1969 ASSERT_TRUE(grid_view); | 1965 ASSERT_TRUE(grid_view); |
1970 const views::ViewModelT<app_list::AppListItemView>* vm_grid = | 1966 const views::ViewModelT<app_list::AppListItemView>* vm_grid = |
1971 grid_view->view_model_for_test(); | 1967 grid_view->view_model_for_test(); |
1972 EXPECT_EQ(2, vm_grid->view_size()); | 1968 EXPECT_EQ(2, vm_grid->view_size()); |
1973 gfx::Rect bounds_grid_1 = vm_grid->view_at(1)->GetBoundsInScreen(); | 1969 gfx::Rect bounds_grid_1 = vm_grid->view_at(1)->GetBoundsInScreen(); |
1974 // Test now that a click does create a new application tab. | 1970 // Test now that a click does create a new application tab. |
1975 TabStripModel* tab_strip = browser()->tab_strip_model(); | 1971 TabStripModel* tab_strip = browser()->tab_strip_model(); |
1976 int tab_count = tab_strip->count(); | 1972 int tab_count = tab_strip->count(); |
1977 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(), | 1973 generator.MoveMouseTo(bounds_grid_1.CenterPoint().x(), |
1978 bounds_grid_1.CenterPoint().y()); | 1974 bounds_grid_1.CenterPoint().y()); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2234 controller_->ActivateApp(bookmark_app->id(), ash::LAUNCH_FROM_APP_LIST, 0); | 2230 controller_->ActivateApp(bookmark_app->id(), ash::LAUNCH_FROM_APP_LIST, 0); |
2235 | 2231 |
2236 // There should be two new browsers. | 2232 // There should be two new browsers. |
2237 EXPECT_EQ(3u, chrome::GetBrowserCount(browser()->profile())); | 2233 EXPECT_EQ(3u, chrome::GetBrowserCount(browser()->profile())); |
2238 | 2234 |
2239 // The apps should now be running, with the last opened app active. | 2235 // The apps should now be running, with the last opened app active. |
2240 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(hosted_app_shelf_id)->status); | 2236 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(hosted_app_shelf_id)->status); |
2241 EXPECT_EQ(ash::STATUS_ACTIVE, | 2237 EXPECT_EQ(ash::STATUS_ACTIVE, |
2242 model_->ItemByID(bookmark_app_shelf_id)->status); | 2238 model_->ItemByID(bookmark_app_shelf_id)->status); |
2243 } | 2239 } |
OLD | NEW |