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(); | |
|
calamity
2015/02/17 00:54:09
This returns coordinates in the contents view's co
tapted
2015/02/17 03:06:00
Yep! Fixed. Darn border.
It's 31 pixels (border_i
| |
| 165 | |
| 166 // First try clicking 10px above the clickzone. | |
| 167 gfx::Point point_above_clickzone = point_in_clickzone; | |
| 168 point_above_clickzone.set_y(bounds.y() - 10); | |
| 169 | |
| 170 event_generator.MoveMouseRelativeTo(window, point_above_clickzone); | |
| 171 event_generator.ClickLeftButton(); | |
| 172 | |
| 173 // Should stay on the start page. | |
| 174 EXPECT_TRUE( | |
| 175 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 176 | |
| 177 // Now click in the clickzone. | |
| 178 event_generator.MoveMouseRelativeTo(window, point_in_clickzone); | |
| 179 // First, try disabling the custom page view. Click should do nothing. | |
| 180 SetCustomLauncherPageEnabled(false); | |
| 181 event_generator.ClickLeftButton(); | |
| 182 EXPECT_TRUE( | |
| 183 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 184 // Click again with it enabled. The active state should update immediately. | |
| 185 SetCustomLauncherPageEnabled(true); | |
| 186 event_generator.ClickLeftButton(); | |
| 187 EXPECT_TRUE(contents_view->IsStateActive( | |
| 188 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); | |
| 189 | |
| 190 // Back to the start page. And send a mouse wheel event. | |
| 191 SetActivePageAndVerify(app_list::AppListModel::STATE_START); | |
| 192 // Generate wheel events above the clickzone. | |
| 193 event_generator.MoveMouseRelativeTo(window, point_above_clickzone); | |
| 194 // Scrolling left, right or up should do nothing. | |
| 195 event_generator.MoveMouseWheel(-5, 0); | |
| 196 event_generator.MoveMouseWheel(5, 0); | |
| 197 event_generator.MoveMouseWheel(0, -5); | |
| 198 EXPECT_TRUE( | |
| 199 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 200 // Scroll down to open launcher page. | |
| 201 event_generator.MoveMouseWheel(0, 5); | |
| 202 EXPECT_TRUE(contents_view->IsStateActive( | |
| 203 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); | |
| 204 | |
| 205 // Constants for gesture/trackpad events. | |
| 206 const base::TimeDelta step_delay = base::TimeDelta::FromMilliseconds(300); | |
| 207 const int num_steps = 5; | |
| 208 const int num_fingers = 2; | |
|
calamity
2015/02/17 00:54:09
kStepDelay etc?
tapted
2015/02/17 03:06:01
Yeah I was doing that for ages, and it blew my min
calamity
2015/02/17 05:19:29
Everything I know is a lie.
| |
| 209 | |
| 210 // Gesture events need to be in screen coordinates. | |
| 211 views::View::ConvertPointToScreen(contents_view, &point_above_clickzone); | |
| 212 views::View::ConvertPointToScreen(contents_view, &point_in_clickzone); | |
| 213 | |
| 214 // Back to the start page. And send a scroll gesture. | |
| 215 SetActivePageAndVerify(app_list::AppListModel::STATE_START); | |
| 216 // Going down should do nothing. | |
| 217 event_generator.GestureScrollSequence( | |
| 218 point_above_clickzone, point_in_clickzone, step_delay, num_steps); | |
| 219 EXPECT_TRUE( | |
| 220 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 221 // Now go up - should change state. | |
| 222 event_generator.GestureScrollSequence( | |
| 223 point_in_clickzone, point_above_clickzone, step_delay, num_steps); | |
| 224 EXPECT_TRUE(contents_view->IsStateActive( | |
| 225 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); | |
| 226 | |
| 227 // Back to the start page. And send a trackpad scroll event. | |
| 228 SetActivePageAndVerify(app_list::AppListModel::STATE_START); | |
| 229 // Going down left, right or up should do nothing. | |
| 230 event_generator.ScrollSequence(point_in_clickzone, step_delay, -5, 0, | |
| 231 num_steps, num_fingers); | |
| 232 event_generator.ScrollSequence(point_in_clickzone, step_delay, 5, 0, | |
| 233 num_steps, num_fingers); | |
| 234 event_generator.ScrollSequence(point_in_clickzone, step_delay, 0, -5, | |
| 235 num_steps, num_fingers); | |
| 236 EXPECT_TRUE( | |
| 237 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 238 // Scroll up to open launcher page. | |
| 239 event_generator.ScrollSequence(point_in_clickzone, step_delay, 0, 5, | |
| 240 num_steps, num_fingers); | |
| 241 EXPECT_TRUE(contents_view->IsStateActive( | |
| 242 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); | |
| 243 | |
| 244 // Back to the start page. And send a tap gesture. | |
| 245 SetActivePageAndVerify(app_list::AppListModel::STATE_START); | |
| 246 // Tapping outside the clickzone should do nothing. | |
| 247 event_generator.GestureTapAt(point_above_clickzone); | |
| 248 EXPECT_TRUE( | |
| 249 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | |
| 250 // Now tap in the clickzone. | |
| 251 event_generator.GestureTapAt(point_in_clickzone); | |
| 252 EXPECT_TRUE(contents_view->IsStateActive( | |
| 253 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); | |
| 254 } | |
| 255 | |
| 115 IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSubpages) { | 256 IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSubpages) { |
| 116 LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched"); | 257 LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched"); |
| 117 | 258 |
| 118 app_list::AppListView* app_list_view = GetAppListView(); | 259 app_list::AppListView* app_list_view = GetAppListView(); |
| 119 app_list::AppListModel* model = app_list_view->app_list_main_view()->model(); | 260 app_list::AppListModel* model = app_list_view->app_list_main_view()->model(); |
| 120 app_list::ContentsView* contents_view = | 261 app_list::ContentsView* contents_view = |
| 121 app_list_view->app_list_main_view()->contents_view(); | 262 app_list_view->app_list_main_view()->contents_view(); |
| 122 | 263 |
| 123 ASSERT_TRUE( | 264 ASSERT_TRUE( |
| 124 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | 265 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 | 345 |
| 205 // The app list view will have changed on ChromeOS. | 346 // The app list view will have changed on ChromeOS. |
| 206 app_list_view = GetAppListView(); | 347 app_list_view = GetAppListView(); |
| 207 contents_view = app_list_view->app_list_main_view()->contents_view(); | 348 contents_view = app_list_view->app_list_main_view()->contents_view(); |
| 208 EXPECT_TRUE(contents_view->IsStateActive( | 349 EXPECT_TRUE(contents_view->IsStateActive( |
| 209 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); | 350 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)); |
| 210 } | 351 } |
| 211 } | 352 } |
| 212 | 353 |
| 213 IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSetEnabled) { | 354 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"); | 355 LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched"); |
| 220 app_list::AppListView* app_list_view = GetAppListView(); | 356 app_list::AppListView* app_list_view = GetAppListView(); |
| 221 app_list::AppListModel* model = app_list_view->app_list_main_view()->model(); | 357 app_list::AppListModel* model = app_list_view->app_list_main_view()->model(); |
| 222 app_list::ContentsView* contents_view = | 358 app_list::ContentsView* contents_view = |
| 223 app_list_view->app_list_main_view()->contents_view(); | 359 app_list_view->app_list_main_view()->contents_view(); |
| 224 | 360 |
| 225 views::WebView* custom_page_view = | 361 views::WebView* custom_page_view = |
| 226 static_cast<views::WebView*>(contents_view->custom_page_view()); | 362 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( | 363 ASSERT_TRUE( |
| 234 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); | 364 contents_view->IsStateActive(app_list::AppListModel::STATE_START)); |
| 235 | 365 |
| 236 EXPECT_TRUE(custom_page_click_zone->GetLayer()->visible()); | |
| 237 EXPECT_TRUE(model->custom_launcher_page_enabled()); | 366 EXPECT_TRUE(model->custom_launcher_page_enabled()); |
| 238 EXPECT_TRUE(custom_page_view->visible()); | 367 EXPECT_TRUE(custom_page_view->visible()); |
| 239 { | |
| 240 ExtensionTestMessageListener listener("launcherPageDisabled", false); | |
| 241 custom_page_frame->ExecuteJavaScript(kLauncherPageDisableScript); | |
| 242 | 368 |
| 243 listener.WaitUntilSatisfied(); | 369 SetCustomLauncherPageEnabled(false); |
| 244 EXPECT_FALSE(custom_page_click_zone->GetLayer()->visible()); | 370 EXPECT_FALSE(model->custom_launcher_page_enabled()); |
| 245 EXPECT_FALSE(model->custom_launcher_page_enabled()); | 371 EXPECT_FALSE(custom_page_view->visible()); |
| 246 EXPECT_FALSE(custom_page_view->visible()); | |
| 247 } | |
| 248 | 372 |
| 249 { | 373 SetCustomLauncherPageEnabled(true); |
| 250 ExtensionTestMessageListener listener("launcherPageEnabled", false); | 374 EXPECT_TRUE(model->custom_launcher_page_enabled()); |
| 251 custom_page_frame->ExecuteJavaScript(kLauncherPageEnableScript); | 375 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 } | 376 } |
| OLD | NEW |