Chromium Code Reviews| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 std::string selection; | 165 std::string selection; |
| 166 value->GetAsString(&selection); | 166 value->GetAsString(&selection); |
| 167 | 167 |
| 168 // Check if selection handles are showing. | 168 // Check if selection handles are showing. |
| 169 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); | 169 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
| 170 EXPECT_STREQ("Some text we can select", selection.c_str()); | 170 EXPECT_STREQ("Some text we can select", selection.c_str()); |
| 171 | 171 |
| 172 // Lets move the handles a bit to modify the selection | 172 // Lets move the handles a bit to modify the selection |
| 173 touch_editable->Reset(); | 173 touch_editable->Reset(); |
| 174 generator.GestureScrollSequence( | 174 generator.GestureScrollSequence( |
| 175 gfx::Point(10, 47), | 175 gfx::Point(bounds.x() + 10, bounds.y() + 47), |
| 176 gfx::Point(30, 47), | 176 gfx::Point(bounds.x() + 30, bounds.y() + 47), |
| 177 base::TimeDelta::FromMilliseconds(20), | 177 base::TimeDelta::FromMilliseconds(20), |
| 178 5); | 178 5); |
| 179 touch_editable->WaitForSelectionChangeCallback(); | 179 touch_editable->WaitForSelectionChangeCallback(); |
| 180 | 180 |
| 181 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); | 181 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
| 182 value = content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); | 182 value = content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); |
| 183 value->GetAsString(&selection); | 183 value->GetAsString(&selection); |
| 184 | 184 |
| 185 // It is hard to tell what exactly the selection would be now. But it would | 185 // It is hard to tell what exactly the selection would be now. But it would |
| 186 // definitely be less than whatever was selected before. | 186 // definitely be less than whatever was selected before. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 rwhva->OnGestureEvent(&double_tap); | 311 rwhva->OnGestureEvent(&double_tap); |
| 312 touch_editable->WaitForSelectionChangeCallback(); | 312 touch_editable->WaitForSelectionChangeCallback(); |
| 313 | 313 |
| 314 // Check if selection handles are showing. | 314 // Check if selection handles are showing. |
| 315 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); | 315 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
| 316 | 316 |
| 317 scoped_ptr<base::Value> value = | 317 scoped_ptr<base::Value> value = |
| 318 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); | 318 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); |
| 319 std::string selection; | 319 std::string selection; |
| 320 value->GetAsString(&selection); | 320 value->GetAsString(&selection); |
| 321 #if defined(OS_WIN) | |
| 322 // In Windows, the default behavior is to select the whitespace after the word | |
| 323 // when the word is selected. | |
| 324 EXPECT_STREQ("Some ", selection.c_str()); | |
|
sky
2014/05/29 19:28:28
nit: you can just do:
EXPECT_EQ("Some ", selection
| |
| 325 #else | |
| 321 EXPECT_STREQ("Some", selection.c_str()); | 326 EXPECT_STREQ("Some", selection.c_str()); |
| 327 #endif // defined (OS_WIN) | |
| 322 } | 328 } |
| 323 | 329 |
| 324 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, | 330 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
| 325 TouchCursorInTextfieldTest) { | 331 TouchCursorInTextfieldTest) { |
| 326 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); | 332 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); |
| 327 WebContentsImpl* web_contents = | 333 WebContentsImpl* web_contents = |
| 328 static_cast<WebContentsImpl*>(shell()->web_contents()); | 334 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 329 RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 335 RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 330 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( | 336 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( |
| 331 web_contents->GetView()); | 337 web_contents->GetView()); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 354 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); | 360 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
| 355 | 361 |
| 356 scoped_ptr<base::Value> value = | 362 scoped_ptr<base::Value> value = |
| 357 content::ExecuteScriptAndGetValue(main_frame, "get_cursor_position()"); | 363 content::ExecuteScriptAndGetValue(main_frame, "get_cursor_position()"); |
| 358 int cursor_pos = -1; | 364 int cursor_pos = -1; |
| 359 value->GetAsInteger(&cursor_pos); | 365 value->GetAsInteger(&cursor_pos); |
| 360 EXPECT_NE(-1, cursor_pos); | 366 EXPECT_NE(-1, cursor_pos); |
| 361 | 367 |
| 362 // Move the cursor handle. | 368 // Move the cursor handle. |
| 363 generator.GestureScrollSequence( | 369 generator.GestureScrollSequence( |
| 364 gfx::Point(50, 59), | 370 gfx::Point(bounds.x() + 50, bounds.y() + 59), |
| 365 gfx::Point(10, 59), | 371 gfx::Point(bounds.x() + 10, bounds.y() + 59), |
| 366 base::TimeDelta::FromMilliseconds(20), | 372 base::TimeDelta::FromMilliseconds(20), |
| 367 1); | 373 1); |
| 368 touch_editable->WaitForSelectionChangeCallback(); | 374 touch_editable->WaitForSelectionChangeCallback(); |
| 369 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); | 375 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); |
| 370 value = content::ExecuteScriptAndGetValue(main_frame, | 376 value = content::ExecuteScriptAndGetValue(main_frame, |
| 371 "get_cursor_position()"); | 377 "get_cursor_position()"); |
| 372 int new_cursor_pos = -1; | 378 int new_cursor_pos = -1; |
| 373 value->GetAsInteger(&new_cursor_pos); | 379 value->GetAsInteger(&new_cursor_pos); |
| 374 EXPECT_NE(-1, new_cursor_pos); | 380 EXPECT_NE(-1, new_cursor_pos); |
| 375 // Cursor should have moved. | 381 // Cursor should have moved. |
| 376 EXPECT_NE(new_cursor_pos, cursor_pos); | 382 EXPECT_NE(new_cursor_pos, cursor_pos); |
| 377 } | 383 } |
| 378 | 384 |
| 379 } // namespace content | 385 } // namespace content |
| OLD | NEW |