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

Side by Side Diff: content/browser/web_contents/touch_editable_impl_aura_browsertest.cc

Issue 23449013: Re-enable TouchSelectionOriginatingFromWebpageTest with some fixes and logs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added comments for drag_offset_ Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/views/touchui/touch_selection_controller_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 19 matching lines...) Expand all
30 30
31 class TestTouchEditableImplAura : public TouchEditableImplAura { 31 class TestTouchEditableImplAura : public TouchEditableImplAura {
32 public: 32 public:
33 TestTouchEditableImplAura() 33 TestTouchEditableImplAura()
34 : selection_changed_callback_arrived_(false), 34 : selection_changed_callback_arrived_(false),
35 waiting_for_selection_changed_callback_(false), 35 waiting_for_selection_changed_callback_(false),
36 gesture_ack_callback_arrived_(false), 36 gesture_ack_callback_arrived_(false),
37 waiting_for_gesture_ack_callback_(false) {} 37 waiting_for_gesture_ack_callback_(false) {}
38 38
39 void Reset() { 39 void Reset() {
40 LOG(INFO) << "TestTouchEditableImplAura::Reset()";
sky 2013/08/30 19:52:50 This is temporary, right? Please add a TODO to rem
mohsen 2013/08/30 20:03:57 Done.
40 selection_changed_callback_arrived_ = false; 41 selection_changed_callback_arrived_ = false;
41 waiting_for_selection_changed_callback_ = false; 42 waiting_for_selection_changed_callback_ = false;
42 gesture_ack_callback_arrived_ = false; 43 gesture_ack_callback_arrived_ = false;
43 waiting_for_gesture_ack_callback_ = false; 44 waiting_for_gesture_ack_callback_ = false;
44 } 45 }
45 46
46 virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor, 47 virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor,
47 const gfx::Rect& focus) OVERRIDE { 48 const gfx::Rect& focus) OVERRIDE {
49 LOG(INFO) << "TestTouchEditableImplAura::OnSelectionOrCursorChanged("
50 << anchor.ToString() << ", " << focus.ToString() << ")";
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 {
58 LOG(INFO) << "TestTouchEditableImplAura::GestureEventAck("
59 << gesture_event_type << ")";
55 gesture_ack_callback_arrived_ = true; 60 gesture_ack_callback_arrived_ = true;
56 TouchEditableImplAura::GestureEventAck(gesture_event_type); 61 TouchEditableImplAura::GestureEventAck(gesture_event_type);
57 if (waiting_for_gesture_ack_callback_) 62 if (waiting_for_gesture_ack_callback_)
58 gesture_ack_wait_run_loop_->Quit(); 63 gesture_ack_wait_run_loop_->Quit();
59 } 64 }
60 65
61 void WaitForSelectionChangeCallback() { 66 void WaitForSelectionChangeCallback() {
67 LOG(INFO) << "TestTouchEditableImplAura::WaitForSelectionChangeCallback()";
62 if (selection_changed_callback_arrived_) 68 if (selection_changed_callback_arrived_)
63 return; 69 return;
64 waiting_for_selection_changed_callback_ = true; 70 waiting_for_selection_changed_callback_ = true;
65 selection_changed_wait_run_loop_.reset(new base::RunLoop()); 71 selection_changed_wait_run_loop_.reset(new base::RunLoop());
66 selection_changed_wait_run_loop_->Run(); 72 selection_changed_wait_run_loop_->Run();
67 } 73 }
68 74
69 void WaitForGestureAck() { 75 void WaitForGestureAck() {
76 LOG(INFO) << "TestTouchEditableImplAura::WaitForGestureAck()";
70 if (gesture_ack_callback_arrived_) 77 if (gesture_ack_callback_arrived_)
71 return; 78 return;
72 waiting_for_gesture_ack_callback_ = true; 79 waiting_for_gesture_ack_callback_ = true;
73 gesture_ack_wait_run_loop_.reset(new base::RunLoop()); 80 gesture_ack_wait_run_loop_.reset(new base::RunLoop());
74 gesture_ack_wait_run_loop_->Run(); 81 gesture_ack_wait_run_loop_->Run();
75 } 82 }
76 83
77 protected: 84 protected:
78 virtual ~TestTouchEditableImplAura() {} 85 virtual ~TestTouchEditableImplAura() {}
79 86
(...skipping 28 matching lines...) Expand all
108 // complete. 115 // complete.
109 void StartTestWithPage(const std::string& url) { 116 void StartTestWithPage(const std::string& url) {
110 ASSERT_TRUE(test_server()->Start()); 117 ASSERT_TRUE(test_server()->Start());
111 GURL test_url(test_server()->GetURL(url)); 118 GURL test_url(test_server()->GetURL(url));
112 NavigateToURL(shell(), test_url); 119 NavigateToURL(shell(), test_url);
113 aura::Window* content = 120 aura::Window* content =
114 shell()->web_contents()->GetView()->GetContentNativeView(); 121 shell()->web_contents()->GetView()->GetContentNativeView();
115 content->GetRootWindow()->SetHostSize(gfx::Size(800, 600)); 122 content->GetRootWindow()->SetHostSize(gfx::Size(800, 600));
116 } 123 }
117 124
125 // TODO(mohsen): Remove logs if the test showed no flakiness anymore.
118 void TestTouchSelectionOriginatingFromWebpage() { 126 void TestTouchSelectionOriginatingFromWebpage() {
119 ASSERT_NO_FATAL_FAILURE( 127 ASSERT_NO_FATAL_FAILURE(
120 StartTestWithPage("files/touch_selection.html")); 128 StartTestWithPage("files/touch_selection.html"));
121 WebContentsImpl* web_contents = 129 WebContentsImpl* web_contents =
122 static_cast<WebContentsImpl*>(shell()->web_contents()); 130 static_cast<WebContentsImpl*>(shell()->web_contents());
123 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( 131 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>(
124 web_contents->GetRenderViewHost()); 132 web_contents->GetRenderViewHost());
125 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( 133 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>(
126 web_contents->GetView()); 134 web_contents->GetView());
127 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; 135 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura;
128 view_aura->SetTouchEditableForTest(touch_editable); 136 view_aura->SetTouchEditableForTest(touch_editable);
129 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( 137 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>(
130 web_contents->GetRenderWidgetHostView()); 138 web_contents->GetRenderWidgetHostView());
131 aura::Window* content = web_contents->GetView()->GetContentNativeView(); 139 aura::Window* content = web_contents->GetView()->GetContentNativeView();
132 aura::test::EventGenerator generator(content->GetRootWindow(), content); 140 aura::test::EventGenerator generator(content->GetRootWindow(), content);
133 gfx::Rect bounds = content->GetBoundsInRootWindow(); 141 gfx::Rect bounds = content->GetBoundsInRootWindow();
134 142
143 LOG(INFO) << "Select text and wait for selection change.";
135 touch_editable->Reset(); 144 touch_editable->Reset();
136 ExecuteSyncJSFunction(view_host, "select_all_text()"); 145 ExecuteSyncJSFunction(view_host, "select_all_text()");
137 touch_editable->WaitForSelectionChangeCallback(); 146 touch_editable->WaitForSelectionChangeCallback();
138 147
148 LOG(INFO) << "Tap on selection to bring up handles.";
139 // Tap inside selection to bring up selection handles. 149 // Tap inside selection to bring up selection handles.
140 generator.GestureTapAt(gfx::Point(bounds.x() + 10, bounds.y() + 10)); 150 generator.GestureTapAt(gfx::Point(bounds.x() + 10, bounds.y() + 10));
141 EXPECT_EQ(touch_editable->rwhva_, rwhva); 151 EXPECT_EQ(touch_editable->rwhva_, rwhva);
142 152
153 LOG(INFO) << "Get selection.";
143 scoped_ptr<base::Value> value = 154 scoped_ptr<base::Value> value =
144 content::ExecuteScriptAndGetValue(view_host, "get_selection()"); 155 content::ExecuteScriptAndGetValue(view_host, "get_selection()");
145 std::string selection; 156 std::string selection;
146 value->GetAsString(&selection); 157 value->GetAsString(&selection);
147 158
159 LOG(INFO) << "Test handles and selection.";
148 // Check if selection handles are showing. 160 // Check if selection handles are showing.
149 EXPECT_TRUE(touch_editable->touch_selection_controller_.get()); 161 EXPECT_TRUE(touch_editable->touch_selection_controller_.get());
150 EXPECT_STREQ("Some text we can select", selection.c_str()); 162 EXPECT_STREQ("Some text we can select", selection.c_str());
151 163
164 LOG(INFO) << "Drag handles to modify the selection.";
152 // Lets move the handles a bit to modify the selection 165 // Lets move the handles a bit to modify the selection
153 touch_editable->Reset(); 166 touch_editable->Reset();
154 generator.GestureScrollSequence( 167 generator.GestureScrollSequence(
155 gfx::Point(10, 47), 168 gfx::Point(10, 47),
156 gfx::Point(30, 47), 169 gfx::Point(30, 47),
157 base::TimeDelta::FromMilliseconds(20), 170 base::TimeDelta::FromMilliseconds(20),
158 1); 171 1);
172 LOG(INFO) << "Handle moved. Now, waiting for selection to change.";
173 touch_editable->WaitForSelectionChangeCallback();
174 LOG(INFO) << "Selection changed.";
175
176 LOG(INFO) << "Test selection.";
159 EXPECT_TRUE(touch_editable->touch_selection_controller_.get()); 177 EXPECT_TRUE(touch_editable->touch_selection_controller_.get());
160 value = content::ExecuteScriptAndGetValue(view_host, "get_selection()"); 178 value = content::ExecuteScriptAndGetValue(view_host, "get_selection()");
161 value->GetAsString(&selection); 179 value->GetAsString(&selection);
162 180
163 // It is hard to tell what exactly the selection would be now. But it would 181 // It is hard to tell what exactly the selection would be now. But it would
164 // definitely be less than whatever was selected before. 182 // definitely be less than whatever was selected before.
165 EXPECT_GT(std::strlen("Some text we can select"), selection.size()); 183 EXPECT_GT(std::strlen("Some text we can select"), selection.size());
166 } 184 }
167 185
168 void TestTouchSelectionOnLongPress() { 186 void TestTouchSelectionOnLongPress() {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 value->GetAsInteger(&new_cursor_pos); 344 value->GetAsInteger(&new_cursor_pos);
327 EXPECT_NE(-1, new_cursor_pos); 345 EXPECT_NE(-1, new_cursor_pos);
328 // Cursor should have moved. 346 // Cursor should have moved.
329 EXPECT_NE(new_cursor_pos, cursor_pos); 347 EXPECT_NE(new_cursor_pos, cursor_pos);
330 } 348 }
331 349
332 private: 350 private:
333 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAuraTest); 351 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAuraTest);
334 }; 352 };
335 353
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, 354 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest,
344 MAYBE_TouchSelectionOriginatingFromWebpageTest) { 355 TouchSelectionOriginatingFromWebpageTest) {
345 TestTouchSelectionOriginatingFromWebpage(); 356 TestTouchSelectionOriginatingFromWebpage();
346 } 357 }
347 358
348 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, 359 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest,
349 TestTouchSelectionHiddenWhenScrolling) { 360 TestTouchSelectionHiddenWhenScrolling) {
350 TestTouchSelectionHiddenWhenScrolling(); 361 TestTouchSelectionHiddenWhenScrolling();
351 } 362 }
352 363
353 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, 364 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest,
354 TouchSelectionOnLongPressTest) { 365 TouchSelectionOnLongPressTest) {
355 TestTouchSelectionOnLongPress(); 366 TestTouchSelectionOnLongPress();
356 } 367 }
357 368
358 // TODO(miu): Disabled test due to flakiness. http://crbug.com/235991 369 // TODO(miu): Disabled test due to flakiness. http://crbug.com/235991
359 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, 370 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest,
360 DISABLED_TouchCursorInTextfieldTest) { 371 DISABLED_TouchCursorInTextfieldTest) {
361 TestTouchCursorInTextfield(); 372 TestTouchCursorInTextfield();
362 } 373 }
363 374
364 } // namespace content 375 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | ui/views/touchui/touch_selection_controller_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698