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

Unified Diff: chrome/browser/apps/custom_launcher_page_browsertest_views.cc

Issue 913133007: Allow scroll events to open custom launcher pages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add tap Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/app_list/views/app_list_main_view.h » ('j') | ui/app_list/views/start_page_view.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/apps/custom_launcher_page_browsertest_views.cc
diff --git a/chrome/browser/apps/custom_launcher_page_browsertest_views.cc b/chrome/browser/apps/custom_launcher_page_browsertest_views.cc
index d718056b5b9bd624eda141f013e34700509dec59..f590be20406b2377ca29a9ed6f618cc70e94352f 100644
--- a/chrome/browser/apps/custom_launcher_page_browsertest_views.cc
+++ b/chrome/browser/apps/custom_launcher_page_browsertest_views.cc
@@ -20,6 +20,7 @@
#include "ui/app_list/views/app_list_main_view.h"
#include "ui/app_list/views/app_list_view.h"
#include "ui/app_list/views/contents_view.h"
+#include "ui/events/test/event_generator.h"
#include "ui/views/controls/webview/webview.h"
namespace {
@@ -82,6 +83,37 @@ class CustomLauncherPageBrowserTest
return app_list_view;
}
+ // Set the active page on the app list, according to |state|. Does not wait
+ // for any animation or custom page to complete.
+ void SetActivePageAndVerify(app_list::AppListModel::State state) {
+ app_list::ContentsView* contents_view =
+ GetAppListView()->app_list_main_view()->contents_view();
+ contents_view->SetActivePage(contents_view->GetPageIndexForState(state));
+ EXPECT_TRUE(contents_view->IsStateActive(state));
+ }
+
+ void SetCustomLauncherPageEnabled(bool enabled) {
+ const base::string16 kLauncherPageDisableScript =
+ base::ASCIIToUTF16("disableCustomLauncherPage();");
+ const base::string16 kLauncherPageEnableScript =
+ base::ASCIIToUTF16("enableCustomLauncherPage();");
+
+ app_list::ContentsView* contents_view =
+ GetAppListView()->app_list_main_view()->contents_view();
+ views::WebView* custom_page_view =
+ static_cast<views::WebView*>(contents_view->custom_page_view());
+ content::RenderFrameHost* custom_page_frame =
+ custom_page_view->GetWebContents()->GetMainFrame();
+
+ const char* test_message =
+ enabled ? "launcherPageEnabled" : "launcherPageDisabled";
+
+ ExtensionTestMessageListener listener(test_message, false);
+ custom_page_frame->ExecuteJavaScript(enabled ? kLauncherPageEnableScript
+ : kLauncherPageDisableScript);
+ listener.WaitUntilSatisfied();
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(CustomLauncherPageBrowserTest);
};
@@ -112,6 +144,115 @@ IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest,
}
}
+// Test that the app list will switch to the custom launcher page by sending a
+// click inside the clickzone, or a mouse scroll event.
+IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest,
+ EventsActivateSwitchToCustomPage) {
+ LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched");
+ // Use an event generator to ensure targeting is correct.
+ app_list::AppListView* app_list_view = GetAppListView();
+ app_list::ContentsView* contents_view =
+ app_list_view->app_list_main_view()->contents_view();
+ gfx::NativeWindow window = app_list_view->GetWidget()->GetNativeWindow();
+ ui::test::EventGenerator event_generator(window->GetRootWindow(), window);
+ EXPECT_TRUE(
+ contents_view->IsStateActive(app_list::AppListModel::STATE_START));
+
+ // Find the clickzone.
+ gfx::Rect bounds = contents_view->GetCustomPageCollapsedBounds();
+ bounds.Intersect(contents_view->bounds());
+ 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
+
+ // First try clicking 10px above the clickzone.
+ gfx::Point point_above_clickzone = point_in_clickzone;
+ point_above_clickzone.set_y(bounds.y() - 10);
+
+ event_generator.MoveMouseRelativeTo(window, point_above_clickzone);
+ event_generator.ClickLeftButton();
+
+ // Should stay on the start page.
+ EXPECT_TRUE(
+ contents_view->IsStateActive(app_list::AppListModel::STATE_START));
+
+ // Now click in the clickzone.
+ event_generator.MoveMouseRelativeTo(window, point_in_clickzone);
+ // First, try disabling the custom page view. Click should do nothing.
+ SetCustomLauncherPageEnabled(false);
+ event_generator.ClickLeftButton();
+ EXPECT_TRUE(
+ contents_view->IsStateActive(app_list::AppListModel::STATE_START));
+ // Click again with it enabled. The active state should update immediately.
+ SetCustomLauncherPageEnabled(true);
+ event_generator.ClickLeftButton();
+ EXPECT_TRUE(contents_view->IsStateActive(
+ app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
+
+ // Back to the start page. And send a mouse wheel event.
+ SetActivePageAndVerify(app_list::AppListModel::STATE_START);
+ // Generate wheel events above the clickzone.
+ event_generator.MoveMouseRelativeTo(window, point_above_clickzone);
+ // Scrolling left, right or up should do nothing.
+ event_generator.MoveMouseWheel(-5, 0);
+ event_generator.MoveMouseWheel(5, 0);
+ event_generator.MoveMouseWheel(0, -5);
+ EXPECT_TRUE(
+ contents_view->IsStateActive(app_list::AppListModel::STATE_START));
+ // Scroll down to open launcher page.
+ event_generator.MoveMouseWheel(0, 5);
+ EXPECT_TRUE(contents_view->IsStateActive(
+ app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
+
+ // Constants for gesture/trackpad events.
+ const base::TimeDelta step_delay = base::TimeDelta::FromMilliseconds(300);
+ const int num_steps = 5;
+ 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.
+
+ // Gesture events need to be in screen coordinates.
+ views::View::ConvertPointToScreen(contents_view, &point_above_clickzone);
+ views::View::ConvertPointToScreen(contents_view, &point_in_clickzone);
+
+ // Back to the start page. And send a scroll gesture.
+ SetActivePageAndVerify(app_list::AppListModel::STATE_START);
+ // Going down should do nothing.
+ event_generator.GestureScrollSequence(
+ point_above_clickzone, point_in_clickzone, step_delay, num_steps);
+ EXPECT_TRUE(
+ contents_view->IsStateActive(app_list::AppListModel::STATE_START));
+ // Now go up - should change state.
+ event_generator.GestureScrollSequence(
+ point_in_clickzone, point_above_clickzone, step_delay, num_steps);
+ EXPECT_TRUE(contents_view->IsStateActive(
+ app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
+
+ // Back to the start page. And send a trackpad scroll event.
+ SetActivePageAndVerify(app_list::AppListModel::STATE_START);
+ // Going down left, right or up should do nothing.
+ event_generator.ScrollSequence(point_in_clickzone, step_delay, -5, 0,
+ num_steps, num_fingers);
+ event_generator.ScrollSequence(point_in_clickzone, step_delay, 5, 0,
+ num_steps, num_fingers);
+ event_generator.ScrollSequence(point_in_clickzone, step_delay, 0, -5,
+ num_steps, num_fingers);
+ EXPECT_TRUE(
+ contents_view->IsStateActive(app_list::AppListModel::STATE_START));
+ // Scroll up to open launcher page.
+ event_generator.ScrollSequence(point_in_clickzone, step_delay, 0, 5,
+ num_steps, num_fingers);
+ EXPECT_TRUE(contents_view->IsStateActive(
+ app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
+
+ // Back to the start page. And send a tap gesture.
+ SetActivePageAndVerify(app_list::AppListModel::STATE_START);
+ // Tapping outside the clickzone should do nothing.
+ event_generator.GestureTapAt(point_above_clickzone);
+ EXPECT_TRUE(
+ contents_view->IsStateActive(app_list::AppListModel::STATE_START));
+ // Now tap in the clickzone.
+ event_generator.GestureTapAt(point_in_clickzone);
+ EXPECT_TRUE(contents_view->IsStateActive(
+ app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
+}
+
IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSubpages) {
LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched");
@@ -211,11 +352,6 @@ IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest,
}
IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSetEnabled) {
- const base::string16 kLauncherPageDisableScript =
- base::ASCIIToUTF16("disableCustomLauncherPage();");
- const base::string16 kLauncherPageEnableScript =
- base::ASCIIToUTF16("enableCustomLauncherPage();");
-
LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched");
app_list::AppListView* app_list_view = GetAppListView();
app_list::AppListModel* model = app_list_view->app_list_main_view()->model();
@@ -224,35 +360,17 @@ IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSetEnabled) {
views::WebView* custom_page_view =
static_cast<views::WebView*>(contents_view->custom_page_view());
-
- content::RenderFrameHost* custom_page_frame =
- custom_page_view->GetWebContents()->GetMainFrame();
- views::Widget* custom_page_click_zone =
- app_list_view->app_list_main_view()->GetCustomPageClickzone();
-
ASSERT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
- EXPECT_TRUE(custom_page_click_zone->GetLayer()->visible());
EXPECT_TRUE(model->custom_launcher_page_enabled());
EXPECT_TRUE(custom_page_view->visible());
- {
- ExtensionTestMessageListener listener("launcherPageDisabled", false);
- custom_page_frame->ExecuteJavaScript(kLauncherPageDisableScript);
- listener.WaitUntilSatisfied();
- EXPECT_FALSE(custom_page_click_zone->GetLayer()->visible());
- EXPECT_FALSE(model->custom_launcher_page_enabled());
- EXPECT_FALSE(custom_page_view->visible());
- }
+ SetCustomLauncherPageEnabled(false);
+ EXPECT_FALSE(model->custom_launcher_page_enabled());
+ EXPECT_FALSE(custom_page_view->visible());
- {
- ExtensionTestMessageListener listener("launcherPageEnabled", false);
- custom_page_frame->ExecuteJavaScript(kLauncherPageEnableScript);
-
- listener.WaitUntilSatisfied();
- EXPECT_TRUE(custom_page_click_zone->GetLayer()->visible());
- EXPECT_TRUE(model->custom_launcher_page_enabled());
- EXPECT_TRUE(custom_page_view->visible());
- }
+ SetCustomLauncherPageEnabled(true);
+ EXPECT_TRUE(model->custom_launcher_page_enabled());
+ EXPECT_TRUE(custom_page_view->visible());
}
« no previous file with comments | « no previous file | ui/app_list/views/app_list_main_view.h » ('j') | ui/app_list/views/start_page_view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698