Commit 73da669d authored by evy@chromium.org's avatar evy@chromium.org

To allow the user to return to TouchExplorationMode with mouse moves passed...

To allow the user to return to TouchExplorationMode with mouse moves passed through, there is a one line change in the .cc file (386).
Manual cursor_client changes have been added to the unit tests.
A browser test has been added to more accurately test the cursor state.

TEST= TouchExplorationTest.SplitTap (ui_unittest)  TouchExplorationTest.SplitTapExplore (browser_test)
BUG=389584

Review URL: https://codereview.chromium.org/359453003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282339 0039d316-1c4b-4281-b951-d872f2087c98
parent 2544aa33
......@@ -14,6 +14,7 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test_utils.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/window_tree_host.h"
#include "ui/compositor/compositor.h"
......@@ -33,6 +34,27 @@ class TouchExplorationTest : public InProcessBrowserTest {
virtual ~TouchExplorationTest() {}
protected:
virtual void SetUpOnMainThread() OVERRIDE {
// The RenderView for WebContents is created as a result of the
// navigation to the New Tab page which is done as part of the test
// SetUp. The creation involves sending a resize message to the renderer
// process. Here we wait for the resize ack to be received, because
// currently WindowEventDispatcher has code to hold touch and mouse
// move events until resize is complete (crbug.com/384342) which
// interferes with this test.
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
content::WaitForResizeComplete(web_contents);
root_window_ = ash::Shell::GetInstance()->GetPrimaryRootWindow();
event_handler_.reset(new ui::test::TestEventHandler());
root_window_->AddPreTargetHandler(event_handler_.get());
}
virtual void CleanUpOnMainThread() OVERRIDE {
SwitchTouchExplorationMode(false);
root_window_->RemovePreTargetHandler(event_handler_.get());
}
void SwitchTouchExplorationMode(bool on) {
ash::AccessibilityDelegate* ad =
ash::Shell::GetInstance()->accessibility_delegate();
......@@ -47,6 +69,8 @@ class TouchExplorationTest : public InProcessBrowserTest {
ui::GestureDetector::Config gesture_detector_config_;
base::SimpleTestTickClock* simulated_clock_;
aura::Window* root_window_;
scoped_ptr<ui::test::TestEventHandler> event_handler_;
private:
DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest);
......@@ -56,73 +80,110 @@ private:
// get rewritten when the touch exploration mode is on, and aren't affected
// after the touch exploration mode is turned off.
IN_PROC_BROWSER_TEST_F(TouchExplorationTest, ToggleOnOff) {
// The RenderView for WebContents is created as a result of the navigation
// to the New Tab page which is done as part of the test SetUp. The creation
// involves sending a resize message to the renderer process. Here we wait
// for the resize ack to be received, because currently WindowEventDispatcher
// has code to hold touch and mouse move events until resize is complete
// (crbug.com/384342) which interferes with this test.
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
content::WaitForResizeComplete(web_contents);
aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
scoped_ptr<ui::test::TestEventHandler>
event_handler(new ui::test::TestEventHandler());
root_window->AddPreTargetHandler(event_handler.get());
SwitchTouchExplorationMode(true);
aura::test::EventGenerator generator(root_window);
aura::test::EventGenerator generator(root_window_);
base::TimeDelta initial_time = Now();
ui::TouchEvent initial_press(
ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time);
float delta_time =
(initial_press.location() - gfx::Point(109,209)).Length() /
gesture_detector_config_.minimum_swipe_velocity;
ui::TouchEvent touch_move(
ui::ET_TOUCH_MOVED,
gfx::Point(109, 209),
1,
initial_time + base::TimeDelta::FromSecondsD(delta_time));
generator.Dispatch(&initial_press);
// Since the touch exploration controller doesn't know if the user is
// double-tapping or not, touch exploration is only initiated if the
// user moves more than 8 pixels away from the initial location (the "slop"),
// or after 300 ms has elapsed if the finger does not move fast enough.
generator.Dispatch(&touch_move);
// 300 ms has elapsed and the finger does not move fast enough to begin
// gestures. Here, the touch move event is not important as a move, but
// a way to create time advancement.
ui::TouchEvent touch_time_advance(ui::ET_TOUCH_MOVED,
gfx::Point(100, 200),
1,
initial_time +
gesture_detector_config_.double_tap_timeout +
base::TimeDelta::FromMilliseconds(1));
generator.Dispatch(&touch_time_advance);
// Number of mouse events may be greater than 1 because of ET_MOUSE_ENTERED.
EXPECT_GT(event_handler->num_mouse_events(), 0);
EXPECT_EQ(0, event_handler->num_touch_events());
event_handler->Reset();
EXPECT_GT(event_handler_->num_mouse_events(), 0);
EXPECT_EQ(0, event_handler_->num_touch_events());
event_handler_->Reset();
SwitchTouchExplorationMode(false);
generator.MoveTouchId(gfx::Point(11, 12), 1);
EXPECT_EQ(0, event_handler->num_mouse_events());
EXPECT_EQ(1, event_handler->num_touch_events());
event_handler->Reset();
EXPECT_EQ(0, event_handler_->num_mouse_events());
EXPECT_EQ(1, event_handler_->num_touch_events());
event_handler_->Reset();
SwitchTouchExplorationMode(true);
initial_time = Now();
ui::TouchEvent second_initial_press(
ui::ET_TOUCH_PRESSED, gfx::Point(500, 600), 2, initial_time);
delta_time =
(second_initial_press.location() - gfx::Point(509, 609)).Length() /
gesture_detector_config_.minimum_swipe_velocity;
ui::TouchEvent second_move(
generator.Dispatch(&second_initial_press);
ui::TouchEvent second_touch_time_advance(
ui::ET_TOUCH_MOVED,
gfx::Point(509, 609),
gfx::Point(500, 600),
2,
initial_time + base::TimeDelta::FromSecondsD(delta_time));
initial_time + gesture_detector_config_.double_tap_timeout +
base::TimeDelta::FromMilliseconds(1));
generator.Dispatch(&second_touch_time_advance);
EXPECT_GT(event_handler_->num_mouse_events(), 0);
EXPECT_EQ(0, event_handler_->num_touch_events());
}
generator.Dispatch(&second_initial_press);
generator.Dispatch(&second_move);
EXPECT_GT(event_handler->num_mouse_events(), 0);
EXPECT_EQ(0, event_handler->num_touch_events());
// This test makes sure that after the user clicks with split tap,
// they continue to touch exploration mode if the original touch exploration
// finger is still on the screen.
IN_PROC_BROWSER_TEST_F(TouchExplorationTest, SplitTapExplore) {
SwitchTouchExplorationMode(true);
aura::test::EventGenerator generator(root_window_);
aura::client::CursorClient* cursor_client =
aura::client::GetCursorClient(root_window_);
SwitchTouchExplorationMode(false);
root_window->RemovePreTargetHandler(event_handler.get());
// Mouse events should show the cursor.
generator.MoveMouseTo(gfx::Point(30, 31));
EXPECT_TRUE(cursor_client->IsMouseEventsEnabled());
EXPECT_TRUE(cursor_client->IsCursorVisible());
// The cursor should be shown immediately after the press, and hidden
// after the move.
base::TimeDelta initial_time = Now();
ui::TouchEvent initial_press(
ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time);
generator.Dispatch(&initial_press);
EXPECT_TRUE(cursor_client->IsMouseEventsEnabled());
EXPECT_TRUE(cursor_client->IsCursorVisible());
// Initiate touch explore by waiting for the tap timer timeout. Time is
// advanced by sending a move event after the timeout period.
ui::TouchEvent touch_time_advance(
ui::ET_TOUCH_MOVED,
gfx::Point(100, 200),
1,
initial_time + gesture_detector_config_.double_tap_timeout +
base::TimeDelta::FromMilliseconds(1));
generator.Dispatch(&touch_time_advance);
EXPECT_TRUE(cursor_client->IsMouseEventsEnabled());
EXPECT_FALSE(cursor_client->IsCursorVisible());
event_handler_->Reset();
// Press and release with a second finger for split tap. This should send
// touch press and release events which should send a click press and release.
// Once the press is passed through, mouse events should be disabled.
// Mouse events are reenabled after the release.
generator.set_current_location(gfx::Point(102, 202));
generator.PressTouchId(2);
EXPECT_FALSE(cursor_client->IsMouseEventsEnabled());
EXPECT_FALSE(cursor_client->IsCursorVisible());
generator.ReleaseTouchId(2);
EXPECT_TRUE(cursor_client->IsMouseEventsEnabled());
EXPECT_FALSE(cursor_client->IsCursorVisible());
EXPECT_EQ(2, event_handler_->num_touch_events());
event_handler_->Reset();
// Continuing to move the touch exploration finger should send more mouse
// events.
generator.MoveTouchId(gfx::Point(509, 609), 1);
EXPECT_EQ(0, event_handler_->num_touch_events());
EXPECT_TRUE(cursor_client->IsMouseEventsEnabled());
EXPECT_FALSE(cursor_client->IsCursorVisible());
}
} // namespace ui
......@@ -502,8 +502,8 @@ ui::EventRewriteStatus TouchExplorationController::InTouchExploreSecondPress(
initial_press_->touch_id(),
event.time_stamp()));
(*rewritten_event)->set_flags(event.flags());
EnterTouchToMouseMode();
state_ = TOUCH_EXPLORATION;
EnterTouchToMouseMode();
VLOG_STATE();
return ui::EVENT_REWRITE_REWRITTEN;
}
......
......@@ -670,6 +670,7 @@ TEST_F(TouchExplorationTest, SplitTap) {
EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
ClearCapturedEvents();
EXPECT_TRUE(IsInTouchToMouseMode());
// Now tap and release at a different location. This should result in a
// single touch and release at the location of the first (held) tap,
......@@ -678,10 +679,19 @@ TEST_F(TouchExplorationTest, SplitTap) {
ui::TouchEvent split_tap_press(
ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now());
generator_->Dispatch(&split_tap_press);
// To simulate the behavior of the real device, we manually disable
// mouse events. To not rely on manually setting the state, this is also
// tested in touch_exploration_controller_browsertest.
cursor_client()->DisableMouseEvents();
EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled());
EXPECT_FALSE(cursor_client()->IsCursorVisible());
EXPECT_FALSE(IsInGestureInProgressState());
ui::TouchEvent split_tap_release(
ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now());
generator_->Dispatch(&split_tap_release);
// Releasing the second finger should re-enable mouse events putting us
// back into the touch exploration mode.
EXPECT_TRUE(IsInTouchToMouseMode());
EXPECT_FALSE(IsInNoFingersDownState());
std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents();
......@@ -690,6 +700,13 @@ TEST_F(TouchExplorationTest, SplitTap) {
EXPECT_EQ(initial_touch_location, captured_events[0]->location());
EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
EXPECT_EQ(initial_touch_location, captured_events[1]->location());
ClearCapturedEvents();
ui::TouchEvent touch_explore_release(
ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now());
generator_->Dispatch(&touch_explore_release);
AdvanceSimulatedTimePastTapDelay();
EXPECT_TRUE(IsInNoFingersDownState());
}
// If split tap is started but the touch explore finger is released first,
......@@ -751,18 +768,26 @@ TEST_F(TouchExplorationTest, SplitTapLongPress) {
ClearCapturedEvents();
// Now tap and release at a different location. This should result in a
// single touch and release at the location of the first (held) tap,
// not at the location of the second tap and release.
// After the release, there is still a finger in touch explore mode.
// Now tap, hold, and release at a different location. This should result
// in a single touch and release (long press) at the location of the first
// (held) tap, not at the location of the second tap and release.
ui::TouchEvent split_tap_press(
ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now());
generator_->Dispatch(&split_tap_press);
// To simulate the behavior of the real device, we manually disable
// mouse events, like in the SplitTap test.
cursor_client()->DisableMouseEvents();
EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled());
EXPECT_FALSE(cursor_client()->IsCursorVisible());
EXPECT_FALSE(IsInGestureInProgressState());
simulated_clock_->Advance(gesture_detector_config_.longpress_timeout);
// After the release, there is still a finger in touch exploration, and
// mouse events should be enabled again.
ui::TouchEvent split_tap_release(
ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now());
generator_->Dispatch(&split_tap_release);
EXPECT_FALSE(IsInNoFingersDownState());
EXPECT_TRUE(IsInTouchToMouseMode());
std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents();
ASSERT_EQ(2U, captured_events.size());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment