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" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
13 #include "content/browser/web_contents/web_contents_view_aura.h" | 13 #include "content/browser/web_contents/web_contents_view_aura.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_view.h" | 15 #include "content/public/browser/web_contents_view.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
18 #include "content/public/test/content_browser_test.h" | 18 #include "content/public/test/content_browser_test.h" |
19 #include "content/public/test/content_browser_test_utils.h" | 19 #include "content/public/test/content_browser_test_utils.h" |
20 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
21 #include "content/shell/browser/shell.h" | 21 #include "content/shell/browser/shell.h" |
| 22 #include "third_party/WebKit/public/web/WebInputEvent.h" |
22 #include "ui/aura/test/event_generator.h" | 23 #include "ui/aura/test/event_generator.h" |
23 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
24 #include "ui/aura/window_tree_host.h" | 25 #include "ui/aura/window_tree_host.h" |
25 #include "ui/base/ui_base_switches.h" | 26 #include "ui/base/ui_base_switches.h" |
26 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 27 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
27 #include "ui/events/event_utils.h" | 28 #include "ui/events/event_utils.h" |
28 | 29 |
| 30 using blink::WebInputEvent; |
| 31 |
29 namespace content { | 32 namespace content { |
30 | 33 |
31 class TestTouchEditableImplAura : public TouchEditableImplAura { | 34 class TestTouchEditableImplAura : public TouchEditableImplAura { |
32 public: | 35 public: |
33 TestTouchEditableImplAura() | 36 TestTouchEditableImplAura() |
34 : selection_changed_callback_arrived_(false), | 37 : selection_changed_callback_arrived_(false), |
35 waiting_for_selection_changed_callback_(false), | 38 waiting_for_selection_changed_callback_(false), |
36 gesture_ack_callback_arrived_(false), | 39 waiting_for_gesture_ack_type_(WebInputEvent::Undefined), |
37 waiting_for_gesture_ack_callback_(false) {} | 40 last_gesture_ack_type_(WebInputEvent::Undefined) {} |
38 | 41 |
39 virtual void Reset() { | 42 virtual void Reset() { |
40 selection_changed_callback_arrived_ = false; | 43 selection_changed_callback_arrived_ = false; |
41 waiting_for_selection_changed_callback_ = false; | 44 waiting_for_selection_changed_callback_ = false; |
42 gesture_ack_callback_arrived_ = false; | 45 waiting_for_gesture_ack_type_ = WebInputEvent::Undefined; |
43 waiting_for_gesture_ack_callback_ = false; | 46 last_gesture_ack_type_ = WebInputEvent::Undefined; |
44 } | 47 } |
45 | 48 |
46 virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor, | 49 virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor, |
47 const gfx::Rect& focus) OVERRIDE { | 50 const gfx::Rect& focus) OVERRIDE { |
48 selection_changed_callback_arrived_ = true; | 51 selection_changed_callback_arrived_ = true; |
49 TouchEditableImplAura::OnSelectionOrCursorChanged(anchor, focus); | 52 TouchEditableImplAura::OnSelectionOrCursorChanged(anchor, focus); |
50 if (waiting_for_selection_changed_callback_) | 53 if (waiting_for_selection_changed_callback_) |
51 selection_changed_wait_run_loop_->Quit(); | 54 selection_changed_wait_run_loop_->Quit(); |
52 } | 55 } |
53 | 56 |
54 virtual void GestureEventAck(int gesture_event_type) OVERRIDE { | 57 virtual void GestureEventAck(int gesture_event_type) OVERRIDE { |
55 gesture_ack_callback_arrived_ = true; | 58 last_gesture_ack_type_ = |
| 59 static_cast<WebInputEvent::Type>(gesture_event_type); |
56 TouchEditableImplAura::GestureEventAck(gesture_event_type); | 60 TouchEditableImplAura::GestureEventAck(gesture_event_type); |
57 if (waiting_for_gesture_ack_callback_) | 61 if (waiting_for_gesture_ack_type_ == gesture_event_type) |
58 gesture_ack_wait_run_loop_->Quit(); | 62 gesture_ack_wait_run_loop_->Quit(); |
59 } | 63 } |
60 | 64 |
61 virtual void WaitForSelectionChangeCallback() { | 65 virtual void WaitForSelectionChangeCallback() { |
62 if (selection_changed_callback_arrived_) | 66 if (selection_changed_callback_arrived_) |
63 return; | 67 return; |
64 waiting_for_selection_changed_callback_ = true; | 68 waiting_for_selection_changed_callback_ = true; |
65 selection_changed_wait_run_loop_.reset(new base::RunLoop()); | 69 selection_changed_wait_run_loop_.reset(new base::RunLoop()); |
66 selection_changed_wait_run_loop_->Run(); | 70 selection_changed_wait_run_loop_->Run(); |
67 } | 71 } |
68 | 72 |
69 virtual void WaitForGestureAck() { | 73 virtual void WaitForGestureAck(WebInputEvent::Type gesture_event_type) { |
70 if (gesture_ack_callback_arrived_) | 74 if (last_gesture_ack_type_ == gesture_event_type) |
71 return; | 75 return; |
72 waiting_for_gesture_ack_callback_ = true; | 76 waiting_for_gesture_ack_type_ = gesture_event_type; |
73 gesture_ack_wait_run_loop_.reset(new base::RunLoop()); | 77 gesture_ack_wait_run_loop_.reset(new base::RunLoop()); |
74 gesture_ack_wait_run_loop_->Run(); | 78 gesture_ack_wait_run_loop_->Run(); |
75 } | 79 } |
76 | 80 |
77 protected: | 81 protected: |
78 virtual ~TestTouchEditableImplAura() {} | 82 virtual ~TestTouchEditableImplAura() {} |
79 | 83 |
80 private: | 84 private: |
81 bool selection_changed_callback_arrived_; | 85 bool selection_changed_callback_arrived_; |
82 bool waiting_for_selection_changed_callback_; | 86 bool waiting_for_selection_changed_callback_; |
83 bool gesture_ack_callback_arrived_; | 87 WebInputEvent::Type waiting_for_gesture_ack_type_; |
84 bool waiting_for_gesture_ack_callback_; | 88 WebInputEvent::Type last_gesture_ack_type_; |
85 scoped_ptr<base::RunLoop> selection_changed_wait_run_loop_; | 89 scoped_ptr<base::RunLoop> selection_changed_wait_run_loop_; |
86 scoped_ptr<base::RunLoop> gesture_ack_wait_run_loop_; | 90 scoped_ptr<base::RunLoop> gesture_ack_wait_run_loop_; |
87 | 91 |
88 DISALLOW_COPY_AND_ASSIGN(TestTouchEditableImplAura); | 92 DISALLOW_COPY_AND_ASSIGN(TestTouchEditableImplAura); |
89 }; | 93 }; |
90 | 94 |
91 // This class ignores mouse-moved, mouse-entered and mouse-exited events | 95 // This class ignores mouse-moved, mouse-entered and mouse-exited events |
92 // without passing them to TouchEditableImplAura. Normally, we should not | 96 // without passing them to TouchEditableImplAura. Normally, we should not |
93 // receive these events; but, sometimes we receive them which breaks the tests | 97 // receive these events; but, sometimes we receive them which breaks the tests |
94 // and makes them flaky: crbug.com/276992. | 98 // and makes them flaky: crbug.com/276992. |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 366 aura::test::EventGenerator generator(content->GetRootWindow(), content); |
363 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 367 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
364 EXPECT_EQ(GetRenderWidgetHostViewAura(touch_editable), rwhva); | 368 EXPECT_EQ(GetRenderWidgetHostViewAura(touch_editable), rwhva); |
365 | 369 |
366 ExecuteSyncJSFunction(main_frame, "focus_textfield()"); | 370 ExecuteSyncJSFunction(main_frame, "focus_textfield()"); |
367 touch_editable->WaitForSelectionChangeCallback(); | 371 touch_editable->WaitForSelectionChangeCallback(); |
368 | 372 |
369 // Tap textfield | 373 // Tap textfield |
370 touch_editable->Reset(); | 374 touch_editable->Reset(); |
371 generator.GestureTapAt(gfx::Point(bounds.x() + 50, bounds.y() + 40)); | 375 generator.GestureTapAt(gfx::Point(bounds.x() + 50, bounds.y() + 40)); |
372 // Tap Down and Tap acks are sent synchronously. | 376 // Tap Down acks are sent synchronously, while Tap acks are asynchronous. |
| 377 touch_editable->WaitForGestureAck(WebInputEvent::GestureTap); |
373 touch_editable->WaitForSelectionChangeCallback(); | 378 touch_editable->WaitForSelectionChangeCallback(); |
374 touch_editable->Reset(); | 379 touch_editable->Reset(); |
375 | 380 |
376 // Check if cursor handle is showing. | 381 // Check if cursor handle is showing. |
377 EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType(touch_editable)); | 382 EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType(touch_editable)); |
378 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); | 383 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
379 | 384 |
380 scoped_ptr<base::Value> value = | 385 scoped_ptr<base::Value> value = |
381 content::ExecuteScriptAndGetValue(main_frame, "get_cursor_position()"); | 386 content::ExecuteScriptAndGetValue(main_frame, "get_cursor_position()"); |
382 int cursor_pos = -1; | 387 int cursor_pos = -1; |
(...skipping 11 matching lines...) Expand all Loading... |
394 value = content::ExecuteScriptAndGetValue(main_frame, | 399 value = content::ExecuteScriptAndGetValue(main_frame, |
395 "get_cursor_position()"); | 400 "get_cursor_position()"); |
396 int new_cursor_pos = -1; | 401 int new_cursor_pos = -1; |
397 value->GetAsInteger(&new_cursor_pos); | 402 value->GetAsInteger(&new_cursor_pos); |
398 EXPECT_NE(-1, new_cursor_pos); | 403 EXPECT_NE(-1, new_cursor_pos); |
399 // Cursor should have moved. | 404 // Cursor should have moved. |
400 EXPECT_NE(new_cursor_pos, cursor_pos); | 405 EXPECT_NE(new_cursor_pos, cursor_pos); |
401 } | 406 } |
402 | 407 |
403 } // namespace content | 408 } // namespace content |
OLD | NEW |