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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( | 222 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
223 web_contents->GetRenderWidgetHostView()); | 223 web_contents->GetRenderWidgetHostView()); |
224 EXPECT_EQ(GetRenderWidgetHostViewAura(touch_editable), rwhva); | 224 EXPECT_EQ(GetRenderWidgetHostViewAura(touch_editable), rwhva); |
225 | 225 |
226 // Long press to select word. | 226 // Long press to select word. |
227 ui::GestureEvent long_press( | 227 ui::GestureEvent long_press( |
228 10, | 228 10, |
229 10, | 229 10, |
230 0, | 230 0, |
231 ui::EventTimeForNow(), | 231 ui::EventTimeForNow(), |
232 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0)); | 232 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS)); |
233 touch_editable->Reset(); | 233 touch_editable->Reset(); |
234 rwhva->OnGestureEvent(&long_press); | 234 rwhva->OnGestureEvent(&long_press); |
235 touch_editable->WaitForSelectionChangeCallback(); | 235 touch_editable->WaitForSelectionChangeCallback(); |
236 | 236 |
237 // Check if selection handles are showing. | 237 // Check if selection handles are showing. |
238 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); | 238 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
239 | 239 |
240 scoped_ptr<base::Value> value = | 240 scoped_ptr<base::Value> value = |
241 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); | 241 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); |
242 std::string selection; | 242 std::string selection; |
243 value->GetAsString(&selection); | 243 value->GetAsString(&selection); |
244 EXPECT_STREQ("Some", selection.c_str()); | 244 EXPECT_STREQ("Some", selection.c_str()); |
245 | 245 |
246 // Start scrolling. Handles should get hidden. | 246 // Start scrolling. Handles should get hidden. |
247 ui::GestureEvent scroll_begin( | 247 ui::GestureEvent scroll_begin( |
248 10, | 248 10, |
249 10, | 249 10, |
250 0, | 250 0, |
251 ui::EventTimeForNow(), | 251 ui::EventTimeForNow(), |
252 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0, 0)); | 252 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN)); |
253 rwhva->OnGestureEvent(&scroll_begin); | 253 rwhva->OnGestureEvent(&scroll_begin); |
254 EXPECT_FALSE(GetTouchSelectionController(touch_editable)); | 254 EXPECT_FALSE(GetTouchSelectionController(touch_editable)); |
255 | 255 |
256 // Handles should come back after scroll ends. | 256 // Handles should come back after scroll ends. |
257 ui::GestureEvent scroll_end( | 257 ui::GestureEvent scroll_end( |
258 10, | 258 10, |
259 10, | 259 10, |
260 0, | 260 0, |
261 ui::EventTimeForNow(), | 261 ui::EventTimeForNow(), |
262 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END, 0, 0)); | 262 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END)); |
263 rwhva->OnGestureEvent(&scroll_end); | 263 rwhva->OnGestureEvent(&scroll_end); |
264 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); | 264 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
265 } | 265 } |
266 | 266 |
267 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, | 267 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
268 TestTouchSelectionReshownAfterFling) { | 268 TestTouchSelectionReshownAfterFling) { |
269 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); | 269 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); |
270 WebContentsImpl* web_contents = | 270 WebContentsImpl* web_contents = |
271 static_cast<WebContentsImpl*>(shell()->web_contents()); | 271 static_cast<WebContentsImpl*>(shell()->web_contents()); |
272 RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 272 RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
273 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( | 273 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( |
274 web_contents->GetView()); | 274 web_contents->GetView()); |
275 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; | 275 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; |
276 view_aura->SetTouchEditableForTest(touch_editable); | 276 view_aura->SetTouchEditableForTest(touch_editable); |
277 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( | 277 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
278 web_contents->GetRenderWidgetHostView()); | 278 web_contents->GetRenderWidgetHostView()); |
279 EXPECT_EQ(GetRenderWidgetHostViewAura(touch_editable), rwhva); | 279 EXPECT_EQ(GetRenderWidgetHostViewAura(touch_editable), rwhva); |
280 | 280 |
281 // Long press to select word. | 281 // Long press to select word. |
282 ui::GestureEvent long_press( | 282 ui::GestureEvent long_press( |
283 10, | 283 10, |
284 10, | 284 10, |
285 0, | 285 0, |
286 ui::EventTimeForNow(), | 286 ui::EventTimeForNow(), |
287 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0)); | 287 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS)); |
288 touch_editable->Reset(); | 288 touch_editable->Reset(); |
289 rwhva->OnGestureEvent(&long_press); | 289 rwhva->OnGestureEvent(&long_press); |
290 touch_editable->WaitForSelectionChangeCallback(); | 290 touch_editable->WaitForSelectionChangeCallback(); |
291 | 291 |
292 // Check if selection handles are showing. | 292 // Check if selection handles are showing. |
293 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); | 293 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
294 | 294 |
295 scoped_ptr<base::Value> value = | 295 scoped_ptr<base::Value> value = |
296 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); | 296 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); |
297 std::string selection; | 297 std::string selection; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( | 333 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
334 web_contents->GetRenderWidgetHostView()); | 334 web_contents->GetRenderWidgetHostView()); |
335 EXPECT_EQ(GetRenderWidgetHostViewAura(touch_editable), rwhva); | 335 EXPECT_EQ(GetRenderWidgetHostViewAura(touch_editable), rwhva); |
336 | 336 |
337 // Long press to select word. | 337 // Long press to select word. |
338 ui::GestureEvent long_press( | 338 ui::GestureEvent long_press( |
339 10, | 339 10, |
340 10, | 340 10, |
341 0, | 341 0, |
342 ui::EventTimeForNow(), | 342 ui::EventTimeForNow(), |
343 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0)); | 343 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS)); |
344 touch_editable->Reset(); | 344 touch_editable->Reset(); |
345 rwhva->OnGestureEvent(&long_press); | 345 rwhva->OnGestureEvent(&long_press); |
346 touch_editable->WaitForSelectionChangeCallback(); | 346 touch_editable->WaitForSelectionChangeCallback(); |
347 | 347 |
348 // Check if selection handles are showing. | 348 // Check if selection handles are showing. |
349 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); | 349 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
350 | 350 |
351 scoped_ptr<base::Value> value = | 351 scoped_ptr<base::Value> value = |
352 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); | 352 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); |
353 std::string selection; | 353 std::string selection; |
354 value->GetAsString(&selection); | 354 value->GetAsString(&selection); |
355 EXPECT_STREQ("Some", selection.c_str()); | 355 EXPECT_STREQ("Some", selection.c_str()); |
356 } | 356 } |
357 | 357 |
358 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, | 358 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
359 NoTouchSelectionOnDoubleTapTest) { | 359 NoTouchSelectionOnDoubleTapTest) { |
360 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); | 360 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); |
361 WebContentsImpl* web_contents = | 361 WebContentsImpl* web_contents = |
362 static_cast<WebContentsImpl*>(shell()->web_contents()); | 362 static_cast<WebContentsImpl*>(shell()->web_contents()); |
363 RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 363 RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
364 WebContentsViewAura* view_aura = | 364 WebContentsViewAura* view_aura = |
365 static_cast<WebContentsViewAura*>(web_contents->GetView()); | 365 static_cast<WebContentsViewAura*>(web_contents->GetView()); |
366 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; | 366 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; |
367 view_aura->SetTouchEditableForTest(touch_editable); | 367 view_aura->SetTouchEditableForTest(touch_editable); |
368 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( | 368 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
369 web_contents->GetRenderWidgetHostView()); | 369 web_contents->GetRenderWidgetHostView()); |
370 EXPECT_EQ(GetRenderWidgetHostViewAura(touch_editable), rwhva); | 370 EXPECT_EQ(GetRenderWidgetHostViewAura(touch_editable), rwhva); |
371 | 371 |
372 // Double-tap to select word. | 372 // Double-tap to select word. |
373 ui::GestureEvent double_tap( | 373 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); |
374 10, | 374 details.set_tap_count(2); |
375 10, | 375 ui::GestureEvent double_tap(10, 10, 0, ui::EventTimeForNow(), details); |
376 0, | |
377 ui::EventTimeForNow(), | |
378 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 2, 0)); | |
379 touch_editable->Reset(); | 376 touch_editable->Reset(); |
380 rwhva->OnGestureEvent(&double_tap); | 377 rwhva->OnGestureEvent(&double_tap); |
381 touch_editable->WaitForSelectionChangeCallback(); | 378 touch_editable->WaitForSelectionChangeCallback(); |
382 | 379 |
383 // Make sure touch selection handles are not showing. | 380 // Make sure touch selection handles are not showing. |
384 EXPECT_FALSE(GetTouchSelectionController(touch_editable)); | 381 EXPECT_FALSE(GetTouchSelectionController(touch_editable)); |
385 | 382 |
386 scoped_ptr<base::Value> value = | 383 scoped_ptr<base::Value> value = |
387 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); | 384 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); |
388 std::string selection; | 385 std::string selection; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 value = content::ExecuteScriptAndGetValue(main_frame, | 442 value = content::ExecuteScriptAndGetValue(main_frame, |
446 "get_cursor_position()"); | 443 "get_cursor_position()"); |
447 int new_cursor_pos = -1; | 444 int new_cursor_pos = -1; |
448 value->GetAsInteger(&new_cursor_pos); | 445 value->GetAsInteger(&new_cursor_pos); |
449 EXPECT_NE(-1, new_cursor_pos); | 446 EXPECT_NE(-1, new_cursor_pos); |
450 // Cursor should have moved. | 447 // Cursor should have moved. |
451 EXPECT_NE(new_cursor_pos, cursor_pos); | 448 EXPECT_NE(new_cursor_pos, cursor_pos); |
452 } | 449 } |
453 | 450 |
454 } // namespace content | 451 } // namespace content |
OLD | NEW |