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 10 matching lines...) Expand all Loading... |
21 #include "content/test/content_browser_test_utils.h" | 21 #include "content/test/content_browser_test_utils.h" |
22 #include "ui/aura/root_window.h" | 22 #include "ui/aura/root_window.h" |
23 #include "ui/aura/test/event_generator.h" | 23 #include "ui/aura/test/event_generator.h" |
24 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
25 #include "ui/base/events/event_utils.h" | 25 #include "ui/base/events/event_utils.h" |
26 #include "ui/base/ui_base_switches.h" | 26 #include "ui/base/ui_base_switches.h" |
27 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 27 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
28 | 28 |
29 namespace content { | 29 namespace content { |
30 | 30 |
| 31 // TODO(mohsen): Remove logs if the test showed no flakiness anymore. |
31 class TestTouchEditableImplAura : public TouchEditableImplAura { | 32 class TestTouchEditableImplAura : public TouchEditableImplAura { |
32 public: | 33 public: |
33 TestTouchEditableImplAura() | 34 TestTouchEditableImplAura() |
34 : selection_changed_callback_arrived_(false), | 35 : selection_changed_callback_arrived_(false), |
35 waiting_for_selection_changed_callback_(false), | 36 waiting_for_selection_changed_callback_(false), |
36 gesture_ack_callback_arrived_(false), | 37 gesture_ack_callback_arrived_(false), |
37 waiting_for_gesture_ack_callback_(false) {} | 38 waiting_for_gesture_ack_callback_(false) {} |
38 | 39 |
39 void Reset() { | 40 void Reset() { |
| 41 LOG(INFO) << "TestTouchEditableImplAura::Reset()"; |
40 selection_changed_callback_arrived_ = false; | 42 selection_changed_callback_arrived_ = false; |
41 waiting_for_selection_changed_callback_ = false; | 43 waiting_for_selection_changed_callback_ = false; |
42 gesture_ack_callback_arrived_ = false; | 44 gesture_ack_callback_arrived_ = false; |
43 waiting_for_gesture_ack_callback_ = false; | 45 waiting_for_gesture_ack_callback_ = false; |
44 } | 46 } |
45 | 47 |
46 virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor, | 48 virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor, |
47 const gfx::Rect& focus) OVERRIDE { | 49 const gfx::Rect& focus) OVERRIDE { |
| 50 LOG(INFO) << "TestTouchEditableImplAura::OnSelectionOrCursorChanged(" |
| 51 << anchor.ToString() << ", " << focus.ToString() << ")"; |
48 selection_changed_callback_arrived_ = true; | 52 selection_changed_callback_arrived_ = true; |
49 TouchEditableImplAura::OnSelectionOrCursorChanged(anchor, focus); | 53 TouchEditableImplAura::OnSelectionOrCursorChanged(anchor, focus); |
50 if (waiting_for_selection_changed_callback_) | 54 if (waiting_for_selection_changed_callback_) |
51 selection_changed_wait_run_loop_->Quit(); | 55 selection_changed_wait_run_loop_->Quit(); |
52 } | 56 } |
53 | 57 |
54 virtual void GestureEventAck(int gesture_event_type) OVERRIDE { | 58 virtual void GestureEventAck(int gesture_event_type) OVERRIDE { |
| 59 LOG(INFO) << "TestTouchEditableImplAura::GestureEventAck(" |
| 60 << gesture_event_type << ")"; |
55 gesture_ack_callback_arrived_ = true; | 61 gesture_ack_callback_arrived_ = true; |
56 TouchEditableImplAura::GestureEventAck(gesture_event_type); | 62 TouchEditableImplAura::GestureEventAck(gesture_event_type); |
57 if (waiting_for_gesture_ack_callback_) | 63 if (waiting_for_gesture_ack_callback_) |
58 gesture_ack_wait_run_loop_->Quit(); | 64 gesture_ack_wait_run_loop_->Quit(); |
59 } | 65 } |
60 | 66 |
61 void WaitForSelectionChangeCallback() { | 67 void WaitForSelectionChangeCallback() { |
| 68 LOG(INFO) << "TestTouchEditableImplAura::WaitForSelectionChangeCallback()"; |
62 if (selection_changed_callback_arrived_) | 69 if (selection_changed_callback_arrived_) |
63 return; | 70 return; |
64 waiting_for_selection_changed_callback_ = true; | 71 waiting_for_selection_changed_callback_ = true; |
65 selection_changed_wait_run_loop_.reset(new base::RunLoop()); | 72 selection_changed_wait_run_loop_.reset(new base::RunLoop()); |
66 selection_changed_wait_run_loop_->Run(); | 73 selection_changed_wait_run_loop_->Run(); |
67 } | 74 } |
68 | 75 |
69 void WaitForGestureAck() { | 76 void WaitForGestureAck() { |
| 77 LOG(INFO) << "TestTouchEditableImplAura::WaitForGestureAck()"; |
70 if (gesture_ack_callback_arrived_) | 78 if (gesture_ack_callback_arrived_) |
71 return; | 79 return; |
72 waiting_for_gesture_ack_callback_ = true; | 80 waiting_for_gesture_ack_callback_ = true; |
73 gesture_ack_wait_run_loop_.reset(new base::RunLoop()); | 81 gesture_ack_wait_run_loop_.reset(new base::RunLoop()); |
74 gesture_ack_wait_run_loop_->Run(); | 82 gesture_ack_wait_run_loop_->Run(); |
75 } | 83 } |
76 | 84 |
77 protected: | 85 protected: |
78 virtual ~TestTouchEditableImplAura() {} | 86 virtual ~TestTouchEditableImplAura() {} |
79 | 87 |
(...skipping 28 matching lines...) Expand all Loading... |
108 // complete. | 116 // complete. |
109 void StartTestWithPage(const std::string& url) { | 117 void StartTestWithPage(const std::string& url) { |
110 ASSERT_TRUE(test_server()->Start()); | 118 ASSERT_TRUE(test_server()->Start()); |
111 GURL test_url(test_server()->GetURL(url)); | 119 GURL test_url(test_server()->GetURL(url)); |
112 NavigateToURL(shell(), test_url); | 120 NavigateToURL(shell(), test_url); |
113 aura::Window* content = | 121 aura::Window* content = |
114 shell()->web_contents()->GetView()->GetContentNativeView(); | 122 shell()->web_contents()->GetView()->GetContentNativeView(); |
115 content->GetRootWindow()->SetHostSize(gfx::Size(800, 600)); | 123 content->GetRootWindow()->SetHostSize(gfx::Size(800, 600)); |
116 } | 124 } |
117 | 125 |
| 126 // TODO(mohsen): Remove logs if the test showed no flakiness anymore. |
118 void TestTouchSelectionOriginatingFromWebpage() { | 127 void TestTouchSelectionOriginatingFromWebpage() { |
119 ASSERT_NO_FATAL_FAILURE( | 128 ASSERT_NO_FATAL_FAILURE( |
120 StartTestWithPage("files/touch_selection.html")); | 129 StartTestWithPage("files/touch_selection.html")); |
121 WebContentsImpl* web_contents = | 130 WebContentsImpl* web_contents = |
122 static_cast<WebContentsImpl*>(shell()->web_contents()); | 131 static_cast<WebContentsImpl*>(shell()->web_contents()); |
123 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 132 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
124 web_contents->GetRenderViewHost()); | 133 web_contents->GetRenderViewHost()); |
125 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( | 134 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( |
126 web_contents->GetView()); | 135 web_contents->GetView()); |
127 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; | 136 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; |
128 view_aura->SetTouchEditableForTest(touch_editable); | 137 view_aura->SetTouchEditableForTest(touch_editable); |
129 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( | 138 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
130 web_contents->GetRenderWidgetHostView()); | 139 web_contents->GetRenderWidgetHostView()); |
131 aura::Window* content = web_contents->GetView()->GetContentNativeView(); | 140 aura::Window* content = web_contents->GetView()->GetContentNativeView(); |
132 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 141 aura::test::EventGenerator generator(content->GetRootWindow(), content); |
133 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 142 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
134 | 143 |
| 144 LOG(INFO) << "Select text and wait for selection change."; |
135 touch_editable->Reset(); | 145 touch_editable->Reset(); |
136 ExecuteSyncJSFunction(view_host, "select_all_text()"); | 146 ExecuteSyncJSFunction(view_host, "select_all_text()"); |
137 touch_editable->WaitForSelectionChangeCallback(); | 147 touch_editable->WaitForSelectionChangeCallback(); |
138 | 148 |
| 149 LOG(INFO) << "Tap on selection to bring up handles."; |
139 // Tap inside selection to bring up selection handles. | 150 // Tap inside selection to bring up selection handles. |
140 generator.GestureTapAt(gfx::Point(bounds.x() + 10, bounds.y() + 10)); | 151 generator.GestureTapAt(gfx::Point(bounds.x() + 10, bounds.y() + 10)); |
141 EXPECT_EQ(touch_editable->rwhva_, rwhva); | 152 EXPECT_EQ(touch_editable->rwhva_, rwhva); |
142 | 153 |
| 154 LOG(INFO) << "Get selection."; |
143 scoped_ptr<base::Value> value = | 155 scoped_ptr<base::Value> value = |
144 content::ExecuteScriptAndGetValue(view_host, "get_selection()"); | 156 content::ExecuteScriptAndGetValue(view_host, "get_selection()"); |
145 std::string selection; | 157 std::string selection; |
146 value->GetAsString(&selection); | 158 value->GetAsString(&selection); |
147 | 159 |
| 160 LOG(INFO) << "Test handles and selection."; |
148 // Check if selection handles are showing. | 161 // Check if selection handles are showing. |
149 EXPECT_TRUE(touch_editable->touch_selection_controller_.get()); | 162 EXPECT_TRUE(touch_editable->touch_selection_controller_.get()); |
150 EXPECT_STREQ("Some text we can select", selection.c_str()); | 163 EXPECT_STREQ("Some text we can select", selection.c_str()); |
151 | 164 |
| 165 LOG(INFO) << "Drag handles to modify the selection."; |
152 // Lets move the handles a bit to modify the selection | 166 // Lets move the handles a bit to modify the selection |
153 touch_editable->Reset(); | 167 touch_editable->Reset(); |
154 generator.GestureScrollSequence( | 168 generator.GestureScrollSequence( |
155 gfx::Point(10, 47), | 169 gfx::Point(10, 47), |
156 gfx::Point(30, 47), | 170 gfx::Point(30, 47), |
157 base::TimeDelta::FromMilliseconds(20), | 171 base::TimeDelta::FromMilliseconds(20), |
158 1); | 172 1); |
| 173 LOG(INFO) << "Handle moved. Now, waiting for selection to change."; |
| 174 touch_editable->WaitForSelectionChangeCallback(); |
| 175 LOG(INFO) << "Selection changed."; |
| 176 |
| 177 LOG(INFO) << "Test selection."; |
159 EXPECT_TRUE(touch_editable->touch_selection_controller_.get()); | 178 EXPECT_TRUE(touch_editable->touch_selection_controller_.get()); |
160 value = content::ExecuteScriptAndGetValue(view_host, "get_selection()"); | 179 value = content::ExecuteScriptAndGetValue(view_host, "get_selection()"); |
161 value->GetAsString(&selection); | 180 value->GetAsString(&selection); |
162 | 181 |
163 // It is hard to tell what exactly the selection would be now. But it would | 182 // It is hard to tell what exactly the selection would be now. But it would |
164 // definitely be less than whatever was selected before. | 183 // definitely be less than whatever was selected before. |
165 EXPECT_GT(std::strlen("Some text we can select"), selection.size()); | 184 EXPECT_GT(std::strlen("Some text we can select"), selection.size()); |
166 } | 185 } |
167 | 186 |
168 void TestTouchSelectionOnLongPress() { | 187 void TestTouchSelectionOnLongPress() { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 value->GetAsInteger(&new_cursor_pos); | 345 value->GetAsInteger(&new_cursor_pos); |
327 EXPECT_NE(-1, new_cursor_pos); | 346 EXPECT_NE(-1, new_cursor_pos); |
328 // Cursor should have moved. | 347 // Cursor should have moved. |
329 EXPECT_NE(new_cursor_pos, cursor_pos); | 348 EXPECT_NE(new_cursor_pos, cursor_pos); |
330 } | 349 } |
331 | 350 |
332 private: | 351 private: |
333 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAuraTest); | 352 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAuraTest); |
334 }; | 353 }; |
335 | 354 |
336 #if defined(OS_CHROMEOS) | |
337 #define MAYBE_TouchSelectionOriginatingFromWebpageTest \ | |
338 DISABLED_TouchSelectionOriginatingFromWebpageTest | |
339 #else | |
340 #define MAYBE_TouchSelectionOriginatingFromWebpageTest \ | |
341 TouchSelectionOriginatingFromWebpageTest | |
342 #endif | |
343 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, | 355 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
344 MAYBE_TouchSelectionOriginatingFromWebpageTest) { | 356 TouchSelectionOriginatingFromWebpageTest) { |
345 TestTouchSelectionOriginatingFromWebpage(); | 357 TestTouchSelectionOriginatingFromWebpage(); |
346 } | 358 } |
347 | 359 |
348 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, | 360 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
349 TestTouchSelectionHiddenWhenScrolling) { | 361 TestTouchSelectionHiddenWhenScrolling) { |
350 TestTouchSelectionHiddenWhenScrolling(); | 362 TestTouchSelectionHiddenWhenScrolling(); |
351 } | 363 } |
352 | 364 |
353 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, | 365 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
354 TouchSelectionOnLongPressTest) { | 366 TouchSelectionOnLongPressTest) { |
355 TestTouchSelectionOnLongPress(); | 367 TestTouchSelectionOnLongPress(); |
356 } | 368 } |
357 | 369 |
358 // TODO(miu): Disabled test due to flakiness. http://crbug.com/235991 | 370 // TODO(miu): Disabled test due to flakiness. http://crbug.com/235991 |
359 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, | 371 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
360 DISABLED_TouchCursorInTextfieldTest) { | 372 DISABLED_TouchCursorInTextfieldTest) { |
361 TestTouchCursorInTextfield(); | 373 TestTouchCursorInTextfield(); |
362 } | 374 } |
363 | 375 |
364 } // namespace content | 376 } // namespace content |
OLD | NEW |