Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/apps/app_browsertest_util.h" | 10 #include "chrome/browser/apps/app_browsertest_util.h" |
| 11 #include "chrome/browser/ui/app_list/app_list_service.h" | 11 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 12 #include "chrome/browser/ui/app_list/app_list_service_views.h" | 12 #include "chrome/browser/ui/app_list/app_list_service_views.h" |
| 13 #include "chrome/browser/ui/app_list/app_list_shower_views.h" | 13 #include "chrome/browser/ui/app_list/app_list_shower_views.h" |
| 14 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 17 #include "extensions/common/switches.h" | 17 #include "extensions/common/switches.h" |
| 18 #include "extensions/test/extension_test_message_listener.h" | 18 #include "extensions/test/extension_test_message_listener.h" |
| 19 #include "ui/app_list/app_list_switches.h" | 19 #include "ui/app_list/app_list_switches.h" |
| 20 #include "ui/app_list/views/app_list_main_view.h" | 20 #include "ui/app_list/views/app_list_main_view.h" |
| 21 #include "ui/app_list/views/app_list_view.h" | 21 #include "ui/app_list/views/app_list_view.h" |
| 22 #include "ui/app_list/views/contents_view.h" | 22 #include "ui/app_list/views/contents_view.h" |
| 23 #include "ui/events/test/event_generator.h" | |
| 23 #include "ui/views/controls/webview/webview.h" | 24 #include "ui/views/controls/webview/webview.h" |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // The path of the test application within the "platform_apps" directory. | 28 // The path of the test application within the "platform_apps" directory. |
| 28 const char kCustomLauncherPagePath[] = "custom_launcher_page"; | 29 const char kCustomLauncherPagePath[] = "custom_launcher_page"; |
| 29 | 30 |
| 30 // The app ID of the test application. | 31 // The app ID of the test application. |
| 31 const char kCustomLauncherPageID[] = "lmadimbbgapmngbiclpjjngmdickadpl"; | 32 const char kCustomLauncherPageID[] = "lmadimbbgapmngbiclpjjngmdickadpl"; |
| 32 | 33 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 AppListServiceViews* service = static_cast<AppListServiceViews*>( | 76 AppListServiceViews* service = static_cast<AppListServiceViews*>( |
| 76 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)); | 77 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)); |
| 77 // The app list should have loaded instantly since the profile is already | 78 // The app list should have loaded instantly since the profile is already |
| 78 // loaded. | 79 // loaded. |
| 79 EXPECT_TRUE(service->IsAppListVisible()); | 80 EXPECT_TRUE(service->IsAppListVisible()); |
| 80 app_list_view = service->shower().app_list(); | 81 app_list_view = service->shower().app_list(); |
| 81 #endif | 82 #endif |
| 82 return app_list_view; | 83 return app_list_view; |
| 83 } | 84 } |
| 84 | 85 |
| 86 // Set the active page on the app list, according to |state|. Does not wait | |
| 87 // for any animation or custom page to complete. | |
| 88 void SetActivePageAndVerify(app_list::AppListModel::State state) { | |
| 89 app_list::ContentsView* contents_view = | |
| 90 GetAppListView()->app_list_main_view()->contents_view(); | |
| 91 contents_view->SetActivePage(contents_view->GetPageIndexForState(state)); | |
| 92 EXPECT_TRUE(contents_view->IsStateActive(state)); | |
| 93 } | |
| 94 | |
| 95 void SetCustomLauncherPageEnabled(bool enabled) { | |
| 96 const base::string16 kLauncherPageDisableScript = | |
| 97 base::ASCIIToUTF16("disableCustomLauncherPage();"); | |
| 98 const base::string16 kLauncherPageEnableScript = | |
| 99 base::ASCIIToUTF16("enableCustomLauncherPage();"); | |
| 100 | |
| 101 app_list::ContentsView* contents_view = | |
| 102 GetAppListView()->app_list_main_view()->contents_view(); | |
| 103 views::WebView* custom_page_view = | |
| 104 static_cast<views::WebView*>(contents_view->custom_page_view()); | |
| 105 content::RenderFrameHost* custom_page_frame = | |
| 106 custom_page_view->GetWebContents()->GetMainFrame(); | |
| 107 | |
| 108 const char* test_message = | |
| 109 enabled ? "launcherPageEnabled" : "launcherPageDisabled"; | |
| 110 | |
| 111 ExtensionTestMessageListener listener(test_message, false); | |
| 112 custom_page_frame->ExecuteJavaScript(enabled ? kLauncherPageEnableScript | |
| 113 : kLauncherPageDisableScript); | |
| 114 listener.WaitUntilSatisfied(); | |
| 115 } | |
| 116 | |
| 85 private: | 117 private: |
| 86 DISALLOW_COPY_AND_ASSIGN(CustomLauncherPageBrowserTest); | 118 DISALLOW_COPY_AND_ASSIGN(CustomLauncherPageBrowserTest); |
| 87 }; | 119 }; |
| 88 | 120 |
| 89 IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, | 121 IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, |
| 90 OpenLauncherAndSwitchToCustomPage) { | 122 OpenLauncherAndSwitchToCustomPage) { |
| 91 LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched"); | 123 LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched"); |
| 92 app_list::AppListView* app_list_view = GetAppListView(); | 124 app_list::AppListView* app_list_view = GetAppListView(); |
| 93 app_list::ContentsView* contents_view = | 125 app_list::ContentsView* contents_view = |
| 94 app_list_view->app_list_main_view()->contents_view(); | 126 app_list_view->app_list_main_view()->contents_view(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 105 } | 137 } |
| 106 { | 138 { |
| 107 ExtensionTestMessageListener listener("onPageProgressAt0", false); | 139 ExtensionTestMessageListener listener("onPageProgressAt0", false); |
| 108 contents_view->SetActivePage(contents_view->GetPageIndexForState( | 140 contents_view->SetActivePage(contents_view->GetPageIndexForState( |
| 109 app_list::AppListModel::STATE_START)); | 141 app_list::AppListModel::STATE_START)); |
| 110 | 142 |
| 111 listener.WaitUntilSatisfied(); | 143 listener.WaitUntilSatisfied(); |
| 112 } | 144 } |
| 113 } | 145 } |
| 114 | 146 |
| 147 // Test that the app list will switch to the custom launcher page by sending a | |
| 148 // click inside the clickzone, or a mouse scroll event. | |
| 149 IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, | |
| 150 EventsActivateSwitchToCustomPage) { | |
| 151 LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched"); | |
| 152 // Use an event generator to ensure targeting is correct. | |
| 153 app_list::AppListView* app_list_view = GetAppListView(); | |
| 154 app_list::ContentsView* contents_view = | |
| 155 app_list_view->app_list_main_view()->contents_view(); | |
| 156 gfx::NativeWindow window = app_list_view->GetWidget()->GetNativeWindow(); | |
| 157 ui::test::EventGenerator event_generator(window->GetRootWindow(), window); | |
| 158 EXPECT_TRUE( | |
| 159 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 160 | |
| 161 // Find the clickzone. | |
| 162 gfx::Rect bounds = contents_view->GetCustomPageCollapsedBounds(); | |
| 163 bounds.Intersect(contents_view->bounds()); | |
| 164 gfx::Point point_in_clickzone = bounds.CenterPoint(); | |
| 165 views::View::ConvertPointToWidget(contents_view, &point_in_clickzone); | |
| 166 | |
| 167 // First try clicking 10px above the clickzone. | |
| 168 gfx::Point point_above_clickzone = point_in_clickzone; | |
| 169 point_above_clickzone.set_y(bounds.y() - 10); | |
| 170 views::View::ConvertPointToWidget(contents_view, &point_above_clickzone); | |
| 171 | |
| 172 event_generator.MoveMouseRelativeTo(window, point_above_clickzone); | |
| 173 event_generator.ClickLeftButton(); | |
| 174 | |
| 175 // Should stay on the start page. | |
| 176 EXPECT_TRUE( | |
| 177 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 178 | |
| 179 // Now click in the clickzone. | |
| 180 event_generator.MoveMouseRelativeTo(window, point_in_clickzone); | |
| 181 // First, try disabling the custom page view. Click should do nothing. | |
| 182 SetCustomLauncherPageEnabled(false); | |
| 183 event_generator.ClickLeftButton(); | |
| 184 EXPECT_TRUE( | |
| 185 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 186 // Click again with it enabled. The active state should update immediately. | |
| 187 SetCustomLauncherPageEnabled(true); | |
| 188 event_generator.ClickLeftButton(); | |
| 189 EXPECT_TRUE(contents_view->IsStateActive( | |
| 190 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); | |
| 191 | |
| 192 // Back to the start page. And send a mouse wheel event. | |
| 193 SetActivePageAndVerify(app_list::AppListModel::STATE_START); | |
| 194 // Generate wheel events above the clickzone. | |
| 195 event_generator.MoveMouseRelativeTo(window, point_above_clickzone); | |
| 196 // Scrolling left, right or up should do nothing. | |
| 197 event_generator.MoveMouseWheel(-5, 0); | |
| 198 event_generator.MoveMouseWheel(5, 0); | |
| 199 event_generator.MoveMouseWheel(0, -5); | |
| 200 EXPECT_TRUE( | |
| 201 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 202 // Scroll down to open launcher page. | |
| 203 event_generator.MoveMouseWheel(0, 5); | |
| 204 EXPECT_TRUE(contents_view->IsStateActive( | |
| 205 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); | |
| 206 | |
| 207 // Constants for gesture/trackpad events. | |
| 208 const base::TimeDelta step_delay = base::TimeDelta::FromMilliseconds(300); | |
| 209 const int num_steps = 5; | |
| 210 const int num_fingers = 2; | |
| 211 | |
| 212 #if defined(OS_CHROMEOS) | |
|
tapted
2015/02/17 06:25:45
OK.. I'm pretty sure I've cracked these event gene
calamity
2015/02/17 07:13:56
Acknowledged.
| |
| 213 // Gesture events need to be in host coordinates. On Desktop platforms, the | |
| 214 // Widget is the host, so nothing needs to be done. On ChromeOS, the points | |
| 215 // need to be put into screen coordinates. This works because the root window | |
| 216 // assumes it fills the screen. | |
| 217 point_in_clickzone = bounds.CenterPoint(); | |
| 218 point_above_clickzone.SetPoint(point_in_clickzone.x(), bounds.y() - 10); | |
| 219 views::View::ConvertPointToScreen(contents_view, &point_above_clickzone); | |
| 220 views::View::ConvertPointToScreen(contents_view, &point_in_clickzone); | |
| 221 #endif | |
| 222 | |
| 223 // Back to the start page. And send a scroll gesture. | |
| 224 SetActivePageAndVerify(app_list::AppListModel::STATE_START); | |
| 225 // Going down should do nothing. | |
| 226 event_generator.GestureScrollSequence( | |
| 227 point_above_clickzone, point_in_clickzone, step_delay, num_steps); | |
| 228 EXPECT_TRUE( | |
| 229 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 230 // Now go up - should change state. | |
| 231 event_generator.GestureScrollSequence( | |
| 232 point_in_clickzone, point_above_clickzone, step_delay, num_steps); | |
| 233 EXPECT_TRUE(contents_view->IsStateActive( | |
| 234 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); | |
| 235 | |
| 236 // Back to the start page. And send a trackpad scroll event. | |
| 237 SetActivePageAndVerify(app_list::AppListModel::STATE_START); | |
| 238 // Going down left, right or up should do nothing. | |
| 239 event_generator.ScrollSequence(point_in_clickzone, step_delay, -5, 0, | |
| 240 num_steps, num_fingers); | |
| 241 event_generator.ScrollSequence(point_in_clickzone, step_delay, 5, 0, | |
| 242 num_steps, num_fingers); | |
| 243 event_generator.ScrollSequence(point_in_clickzone, step_delay, 0, -5, | |
| 244 num_steps, num_fingers); | |
| 245 EXPECT_TRUE( | |
| 246 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 247 // Scroll up to open launcher page. | |
| 248 event_generator.ScrollSequence(point_in_clickzone, step_delay, 0, 5, | |
| 249 num_steps, num_fingers); | |
| 250 EXPECT_TRUE(contents_view->IsStateActive( | |
| 251 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); | |
| 252 | |
| 253 // Back to the start page. And send a tap gesture. | |
| 254 SetActivePageAndVerify(app_list::AppListModel::STATE_START); | |
| 255 // Tapping outside the clickzone should do nothing. | |
| 256 event_generator.GestureTapAt(point_above_clickzone); | |
| 257 EXPECT_TRUE( | |
| 258 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 259 // Now tap in the clickzone. | |
| 260 event_generator.GestureTapAt(point_in_clickzone); | |
| 261 EXPECT_TRUE(contents_view->IsStateActive( | |
| 262 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); | |
| 263 } | |
| 264 | |
| 115 IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSubpages) { | 265 IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSubpages) { |
| 116 LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched"); | 266 LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched"); |
| 117 | 267 |
| 118 app_list::AppListView* app_list_view = GetAppListView(); | 268 app_list::AppListView* app_list_view = GetAppListView(); |
| 119 app_list::AppListModel* model = app_list_view->app_list_main_view()->model(); | 269 app_list::AppListModel* model = app_list_view->app_list_main_view()->model(); |
| 120 app_list::ContentsView* contents_view = | 270 app_list::ContentsView* contents_view = |
| 121 app_list_view->app_list_main_view()->contents_view(); | 271 app_list_view->app_list_main_view()->contents_view(); |
| 122 | 272 |
| 123 ASSERT_TRUE( | 273 ASSERT_TRUE( |
| 124 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | 274 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 | 354 |
| 205 // The app list view will have changed on ChromeOS. | 355 // The app list view will have changed on ChromeOS. |
| 206 app_list_view = GetAppListView(); | 356 app_list_view = GetAppListView(); |
| 207 contents_view = app_list_view->app_list_main_view()->contents_view(); | 357 contents_view = app_list_view->app_list_main_view()->contents_view(); |
| 208 EXPECT_TRUE(contents_view->IsStateActive( | 358 EXPECT_TRUE(contents_view->IsStateActive( |
| 209 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); | 359 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); |
| 210 } | 360 } |
| 211 } | 361 } |
| 212 | 362 |
| 213 IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSetEnabled) { | 363 IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSetEnabled) { |
| 214 const base::string16 kLauncherPageDisableScript = | |
| 215 base::ASCIIToUTF16("disableCustomLauncherPage();"); | |
| 216 const base::string16 kLauncherPageEnableScript = | |
| 217 base::ASCIIToUTF16("enableCustomLauncherPage();"); | |
| 218 | |
| 219 LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched"); | 364 LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched"); |
| 220 app_list::AppListView* app_list_view = GetAppListView(); | 365 app_list::AppListView* app_list_view = GetAppListView(); |
| 221 app_list::AppListModel* model = app_list_view->app_list_main_view()->model(); | 366 app_list::AppListModel* model = app_list_view->app_list_main_view()->model(); |
| 222 app_list::ContentsView* contents_view = | 367 app_list::ContentsView* contents_view = |
| 223 app_list_view->app_list_main_view()->contents_view(); | 368 app_list_view->app_list_main_view()->contents_view(); |
| 224 | 369 |
| 225 views::WebView* custom_page_view = | 370 views::WebView* custom_page_view = |
| 226 static_cast<views::WebView*>(contents_view->custom_page_view()); | 371 static_cast<views::WebView*>(contents_view->custom_page_view()); |
| 227 | |
| 228 content::RenderFrameHost* custom_page_frame = | |
| 229 custom_page_view->GetWebContents()->GetMainFrame(); | |
| 230 views::Widget* custom_page_click_zone = | |
| 231 app_list_view->app_list_main_view()->GetCustomPageClickzone(); | |
| 232 | |
| 233 ASSERT_TRUE( | 372 ASSERT_TRUE( |
| 234 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | 373 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); |
| 235 | 374 |
| 236 EXPECT_TRUE(custom_page_click_zone->GetLayer()->visible()); | |
| 237 EXPECT_TRUE(model->custom_launcher_page_enabled()); | 375 EXPECT_TRUE(model->custom_launcher_page_enabled()); |
| 238 EXPECT_TRUE(custom_page_view->visible()); | 376 EXPECT_TRUE(custom_page_view->visible()); |
| 239 { | |
| 240 ExtensionTestMessageListener listener("launcherPageDisabled", false); | |
| 241 custom_page_frame->ExecuteJavaScript(kLauncherPageDisableScript); | |
| 242 | 377 |
| 243 listener.WaitUntilSatisfied(); | 378 SetCustomLauncherPageEnabled(false); |
| 244 EXPECT_FALSE(custom_page_click_zone->GetLayer()->visible()); | 379 EXPECT_FALSE(model->custom_launcher_page_enabled()); |
| 245 EXPECT_FALSE(model->custom_launcher_page_enabled()); | 380 EXPECT_FALSE(custom_page_view->visible()); |
| 246 EXPECT_FALSE(custom_page_view->visible()); | |
| 247 } | |
| 248 | 381 |
| 249 { | 382 SetCustomLauncherPageEnabled(true); |
| 250 ExtensionTestMessageListener listener("launcherPageEnabled", false); | 383 EXPECT_TRUE(model->custom_launcher_page_enabled()); |
| 251 custom_page_frame->ExecuteJavaScript(kLauncherPageEnableScript); | 384 EXPECT_TRUE(custom_page_view->visible()); |
| 252 | |
| 253 listener.WaitUntilSatisfied(); | |
| 254 EXPECT_TRUE(custom_page_click_zone->GetLayer()->visible()); | |
| 255 EXPECT_TRUE(model->custom_launcher_page_enabled()); | |
| 256 EXPECT_TRUE(custom_page_view->visible()); | |
| 257 } | |
| 258 } | 385 } |
| OLD | NEW |