OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/web_contents/touch_editable_impl_aura.h" | 5 #include "content/browser/web_contents/touch_editable_impl_aura.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 using blink::WebInputEvent; | 29 using blink::WebInputEvent; |
30 | 30 |
31 namespace content { | 31 namespace content { |
32 | 32 |
33 class TestTouchEditableImplAura : public TouchEditableImplAura { | 33 class TestTouchEditableImplAura : public TouchEditableImplAura { |
34 public: | 34 public: |
35 TestTouchEditableImplAura() | 35 TestTouchEditableImplAura() |
36 : selection_changed_callback_arrived_(false), | 36 : selection_changed_callback_arrived_(false), |
37 waiting_for_selection_changed_callback_(false), | 37 waiting_for_selection_changed_callback_(false), |
38 waiting_for_gesture_ack_type_(WebInputEvent::Undefined), | 38 waiting_for_gesture_ack_type_(WebInputEvent::Undefined), |
39 last_gesture_ack_type_(WebInputEvent::Undefined) {} | 39 last_gesture_ack_type_(WebInputEvent::Undefined), |
| 40 fling_stop_callback_arrived_(false), |
| 41 waiting_for_fling_stop_callback_(false) {} |
40 | 42 |
41 virtual void Reset() { | 43 virtual void Reset() { |
42 selection_changed_callback_arrived_ = false; | 44 selection_changed_callback_arrived_ = false; |
43 waiting_for_selection_changed_callback_ = false; | 45 waiting_for_selection_changed_callback_ = false; |
44 waiting_for_gesture_ack_type_ = WebInputEvent::Undefined; | 46 waiting_for_gesture_ack_type_ = WebInputEvent::Undefined; |
45 last_gesture_ack_type_ = WebInputEvent::Undefined; | 47 last_gesture_ack_type_ = WebInputEvent::Undefined; |
| 48 fling_stop_callback_arrived_ = false; |
| 49 waiting_for_fling_stop_callback_ = false; |
46 } | 50 } |
47 | 51 |
48 virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor, | 52 virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor, |
49 const gfx::Rect& focus) OVERRIDE { | 53 const gfx::Rect& focus) OVERRIDE { |
50 selection_changed_callback_arrived_ = true; | 54 selection_changed_callback_arrived_ = true; |
51 TouchEditableImplAura::OnSelectionOrCursorChanged(anchor, focus); | 55 TouchEditableImplAura::OnSelectionOrCursorChanged(anchor, focus); |
52 if (waiting_for_selection_changed_callback_) | 56 if (waiting_for_selection_changed_callback_) |
53 selection_changed_wait_run_loop_->Quit(); | 57 selection_changed_wait_run_loop_->Quit(); |
54 } | 58 } |
55 | 59 |
56 virtual void GestureEventAck(int gesture_event_type) OVERRIDE { | 60 virtual void GestureEventAck(int gesture_event_type) OVERRIDE { |
57 last_gesture_ack_type_ = | 61 last_gesture_ack_type_ = |
58 static_cast<WebInputEvent::Type>(gesture_event_type); | 62 static_cast<WebInputEvent::Type>(gesture_event_type); |
59 TouchEditableImplAura::GestureEventAck(gesture_event_type); | 63 TouchEditableImplAura::GestureEventAck(gesture_event_type); |
60 if (waiting_for_gesture_ack_type_ == gesture_event_type) | 64 if (waiting_for_gesture_ack_type_ == gesture_event_type) |
61 gesture_ack_wait_run_loop_->Quit(); | 65 gesture_ack_wait_run_loop_->Quit(); |
62 } | 66 } |
63 | 67 |
| 68 virtual void DidStopFlinging() OVERRIDE { |
| 69 fling_stop_callback_arrived_ = true; |
| 70 TouchEditableImplAura::DidStopFlinging(); |
| 71 if (waiting_for_fling_stop_callback_) |
| 72 fling_stop_wait_run_loop_->Quit(); |
| 73 } |
| 74 |
64 virtual void WaitForSelectionChangeCallback() { | 75 virtual void WaitForSelectionChangeCallback() { |
65 if (selection_changed_callback_arrived_) | 76 if (selection_changed_callback_arrived_) |
66 return; | 77 return; |
67 waiting_for_selection_changed_callback_ = true; | 78 waiting_for_selection_changed_callback_ = true; |
68 selection_changed_wait_run_loop_.reset(new base::RunLoop()); | 79 selection_changed_wait_run_loop_.reset(new base::RunLoop()); |
69 selection_changed_wait_run_loop_->Run(); | 80 selection_changed_wait_run_loop_->Run(); |
70 } | 81 } |
71 | 82 |
72 virtual void WaitForGestureAck(WebInputEvent::Type gesture_event_type) { | 83 virtual void WaitForGestureAck(WebInputEvent::Type gesture_event_type) { |
73 if (last_gesture_ack_type_ == gesture_event_type) | 84 if (last_gesture_ack_type_ == gesture_event_type) |
74 return; | 85 return; |
75 waiting_for_gesture_ack_type_ = gesture_event_type; | 86 waiting_for_gesture_ack_type_ = gesture_event_type; |
76 gesture_ack_wait_run_loop_.reset(new base::RunLoop()); | 87 gesture_ack_wait_run_loop_.reset(new base::RunLoop()); |
77 gesture_ack_wait_run_loop_->Run(); | 88 gesture_ack_wait_run_loop_->Run(); |
78 } | 89 } |
79 | 90 |
| 91 virtual void WaitForFlingStopCallback() { |
| 92 if (fling_stop_callback_arrived_) |
| 93 return; |
| 94 waiting_for_fling_stop_callback_ = true; |
| 95 fling_stop_wait_run_loop_.reset(new base::RunLoop()); |
| 96 fling_stop_wait_run_loop_->Run(); |
| 97 } |
| 98 |
80 protected: | 99 protected: |
81 virtual ~TestTouchEditableImplAura() {} | 100 virtual ~TestTouchEditableImplAura() {} |
82 | 101 |
83 private: | 102 private: |
84 bool selection_changed_callback_arrived_; | 103 bool selection_changed_callback_arrived_; |
85 bool waiting_for_selection_changed_callback_; | 104 bool waiting_for_selection_changed_callback_; |
86 WebInputEvent::Type waiting_for_gesture_ack_type_; | 105 WebInputEvent::Type waiting_for_gesture_ack_type_; |
87 WebInputEvent::Type last_gesture_ack_type_; | 106 WebInputEvent::Type last_gesture_ack_type_; |
| 107 bool fling_stop_callback_arrived_; |
| 108 bool waiting_for_fling_stop_callback_; |
88 scoped_ptr<base::RunLoop> selection_changed_wait_run_loop_; | 109 scoped_ptr<base::RunLoop> selection_changed_wait_run_loop_; |
89 scoped_ptr<base::RunLoop> gesture_ack_wait_run_loop_; | 110 scoped_ptr<base::RunLoop> gesture_ack_wait_run_loop_; |
| 111 scoped_ptr<base::RunLoop> fling_stop_wait_run_loop_; |
90 | 112 |
91 DISALLOW_COPY_AND_ASSIGN(TestTouchEditableImplAura); | 113 DISALLOW_COPY_AND_ASSIGN(TestTouchEditableImplAura); |
92 }; | 114 }; |
93 | 115 |
94 class TouchEditableImplAuraTest : public ContentBrowserTest { | 116 class TouchEditableImplAuraTest : public ContentBrowserTest { |
95 public: | 117 public: |
96 TouchEditableImplAuraTest() {} | 118 TouchEditableImplAuraTest() {} |
97 | 119 |
98 protected: | 120 protected: |
99 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 121 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 10, | 258 10, |
237 10, | 259 10, |
238 0, | 260 0, |
239 ui::EventTimeForNow(), | 261 ui::EventTimeForNow(), |
240 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END, 0, 0)); | 262 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END, 0, 0)); |
241 rwhva->OnGestureEvent(&scroll_end); | 263 rwhva->OnGestureEvent(&scroll_end); |
242 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); | 264 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
243 } | 265 } |
244 | 266 |
245 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, | 267 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
| 268 TestTouchSelectionReshownAfterFling) { |
| 269 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); |
| 270 WebContentsImpl* web_contents = |
| 271 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 272 RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 273 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( |
| 274 web_contents->GetView()); |
| 275 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; |
| 276 view_aura->SetTouchEditableForTest(touch_editable); |
| 277 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
| 278 web_contents->GetRenderWidgetHostView()); |
| 279 EXPECT_EQ(GetRenderWidgetHostViewAura(touch_editable), rwhva); |
| 280 |
| 281 // Long press to select word. |
| 282 ui::GestureEvent long_press( |
| 283 10, |
| 284 10, |
| 285 0, |
| 286 ui::EventTimeForNow(), |
| 287 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0)); |
| 288 touch_editable->Reset(); |
| 289 rwhva->OnGestureEvent(&long_press); |
| 290 touch_editable->WaitForSelectionChangeCallback(); |
| 291 |
| 292 // Check if selection handles are showing. |
| 293 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
| 294 |
| 295 scoped_ptr<base::Value> value = |
| 296 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); |
| 297 std::string selection; |
| 298 value->GetAsString(&selection); |
| 299 EXPECT_STREQ("Some", selection.c_str()); |
| 300 |
| 301 // Start scrolling. Handles should get hidden. |
| 302 ui::GestureEvent scroll_begin( |
| 303 10, |
| 304 10, |
| 305 0, |
| 306 ui::EventTimeForNow(), |
| 307 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0, 0)); |
| 308 rwhva->OnGestureEvent(&scroll_begin); |
| 309 EXPECT_FALSE(GetTouchSelectionController(touch_editable)); |
| 310 |
| 311 // Start a fling. Handles should come back after fling stops. |
| 312 ui::GestureEvent fling_start( |
| 313 10, |
| 314 10, |
| 315 0, |
| 316 ui::EventTimeForNow(), |
| 317 ui::GestureEventDetails(ui::ET_SCROLL_FLING_START, 1, 0)); |
| 318 rwhva->OnGestureEvent(&fling_start); |
| 319 touch_editable->WaitForFlingStopCallback(); |
| 320 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
| 321 } |
| 322 |
| 323 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
246 TouchSelectionOnLongPressTest) { | 324 TouchSelectionOnLongPressTest) { |
247 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); | 325 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); |
248 WebContentsImpl* web_contents = | 326 WebContentsImpl* web_contents = |
249 static_cast<WebContentsImpl*>(shell()->web_contents()); | 327 static_cast<WebContentsImpl*>(shell()->web_contents()); |
250 RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 328 RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
251 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( | 329 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( |
252 web_contents->GetView()); | 330 web_contents->GetView()); |
253 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; | 331 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; |
254 view_aura->SetTouchEditableForTest(touch_editable); | 332 view_aura->SetTouchEditableForTest(touch_editable); |
255 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( | 333 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 value = content::ExecuteScriptAndGetValue(main_frame, | 445 value = content::ExecuteScriptAndGetValue(main_frame, |
368 "get_cursor_position()"); | 446 "get_cursor_position()"); |
369 int new_cursor_pos = -1; | 447 int new_cursor_pos = -1; |
370 value->GetAsInteger(&new_cursor_pos); | 448 value->GetAsInteger(&new_cursor_pos); |
371 EXPECT_NE(-1, new_cursor_pos); | 449 EXPECT_NE(-1, new_cursor_pos); |
372 // Cursor should have moved. | 450 // Cursor should have moved. |
373 EXPECT_NE(new_cursor_pos, cursor_pos); | 451 EXPECT_NE(new_cursor_pos, cursor_pos); |
374 } | 452 } |
375 | 453 |
376 } // namespace content | 454 } // namespace content |
OLD | NEW |