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

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

Issue 700563002: Implementing directional text selection handles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new_assets_text
Patch Set: Created 6 years, 1 month 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
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"
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/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
16 #include "content/public/test/browser_test_utils.h" 16 #include "content/public/test/browser_test_utils.h"
17 #include "content/public/test/content_browser_test.h" 17 #include "content/public/test/content_browser_test.h"
18 #include "content/public/test/content_browser_test_utils.h" 18 #include "content/public/test/content_browser_test_utils.h"
19 #include "content/public/test/test_utils.h" 19 #include "content/public/test/test_utils.h"
20 #include "content/shell/browser/shell.h" 20 #include "content/shell/browser/shell.h"
21 #include "third_party/WebKit/public/web/WebInputEvent.h" 21 #include "third_party/WebKit/public/web/WebInputEvent.h"
22 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
23 #include "ui/aura/window_tree_host.h" 23 #include "ui/aura/window_tree_host.h"
24 #include "ui/base/ui_base_switches.h" 24 #include "ui/base/ui_base_switches.h"
25 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 25 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
26 #include "ui/events/event_utils.h" 26 #include "ui/events/event_utils.h"
27 #include "ui/events/test/event_generator.h" 27 #include "ui/events/test/event_generator.h"
28 #include "ui/wm/core/default_screen_position_client.h"
28 29
29 using blink::WebInputEvent; 30 using blink::WebInputEvent;
30 31
31 namespace content { 32 namespace content {
32 33
33 class TestTouchEditableImplAura : public TouchEditableImplAura { 34 class TestTouchEditableImplAura : public TouchEditableImplAura {
34 public: 35 public:
35 TestTouchEditableImplAura() 36 TestTouchEditableImplAura()
36 : selection_changed_callback_arrived_(false), 37 : selection_changed_callback_arrived_(false),
37 waiting_for_selection_changed_callback_(false), 38 waiting_for_selection_changed_callback_(false),
38 waiting_for_gesture_ack_type_(WebInputEvent::Undefined), 39 waiting_for_gesture_ack_type_(WebInputEvent::Undefined),
39 last_gesture_ack_type_(WebInputEvent::Undefined), 40 last_gesture_ack_type_(WebInputEvent::Undefined),
40 fling_stop_callback_arrived_(false), 41 fling_stop_callback_arrived_(false),
41 waiting_for_fling_stop_callback_(false) {} 42 waiting_for_fling_stop_callback_(false) {}
42 43
43 virtual void Reset() { 44 virtual void Reset() {
44 selection_changed_callback_arrived_ = false; 45 selection_changed_callback_arrived_ = false;
45 waiting_for_selection_changed_callback_ = false; 46 waiting_for_selection_changed_callback_ = false;
46 waiting_for_gesture_ack_type_ = WebInputEvent::Undefined; 47 waiting_for_gesture_ack_type_ = WebInputEvent::Undefined;
47 last_gesture_ack_type_ = WebInputEvent::Undefined; 48 last_gesture_ack_type_ = WebInputEvent::Undefined;
48 fling_stop_callback_arrived_ = false; 49 fling_stop_callback_arrived_ = false;
49 waiting_for_fling_stop_callback_ = false; 50 waiting_for_fling_stop_callback_ = false;
50 } 51 }
51 52
52 virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor, 53 virtual void OnSelectionOrCursorChanged(
53 const gfx::Rect& focus) override { 54 const ui::SelectionBound& anchor,
55 const ui::SelectionBound& focus) override {
54 selection_changed_callback_arrived_ = true; 56 selection_changed_callback_arrived_ = true;
55 TouchEditableImplAura::OnSelectionOrCursorChanged(anchor, focus); 57 TouchEditableImplAura::OnSelectionOrCursorChanged(anchor, focus);
56 if (waiting_for_selection_changed_callback_) 58 if (waiting_for_selection_changed_callback_)
57 selection_changed_wait_run_loop_->Quit(); 59 selection_changed_wait_run_loop_->Quit();
58 } 60 }
59 61
60 virtual void GestureEventAck(int gesture_event_type) override { 62 virtual void GestureEventAck(int gesture_event_type) override {
61 last_gesture_ack_type_ = 63 last_gesture_ack_type_ =
62 static_cast<WebInputEvent::Type>(gesture_event_type); 64 static_cast<WebInputEvent::Type>(gesture_event_type);
63 TouchEditableImplAura::GestureEventAck(gesture_event_type); 65 TouchEditableImplAura::GestureEventAck(gesture_event_type);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 133
132 // Starts the test server and navigates to the given url. Sets a large enough 134 // Starts the test server and navigates to the given url. Sets a large enough
133 // size to the root window. Returns after the navigation to the url is 135 // size to the root window. Returns after the navigation to the url is
134 // complete. 136 // complete.
135 void StartTestWithPage(const std::string& url) { 137 void StartTestWithPage(const std::string& url) {
136 ASSERT_TRUE(test_server()->Start()); 138 ASSERT_TRUE(test_server()->Start());
137 GURL test_url(test_server()->GetURL(url)); 139 GURL test_url(test_server()->GetURL(url));
138 NavigateToURL(shell(), test_url); 140 NavigateToURL(shell(), test_url);
139 aura::Window* content = shell()->web_contents()->GetContentNativeView(); 141 aura::Window* content = shell()->web_contents()->GetContentNativeView();
140 content->GetHost()->SetBounds(gfx::Rect(800, 600)); 142 content->GetHost()->SetBounds(gfx::Rect(800, 600));
143 aura::client::SetScreenPositionClient(
144 content->GetRootWindow(), &screen_position_client_);
mohsen 2014/11/07 16:52:27 Can you move this to SetUp()? (the same for simila
mfomitchev 2014/11/10 04:04:11 Done.
141 } 145 }
142 146
143 RenderWidgetHostViewAura* GetRenderWidgetHostViewAura( 147 RenderWidgetHostViewAura* GetRenderWidgetHostViewAura(
144 TouchEditableImplAura* touch_editable) { 148 TouchEditableImplAura* touch_editable) {
145 return touch_editable->rwhva_; 149 return touch_editable->rwhva_;
146 } 150 }
147 151
148 ui::TouchSelectionController* GetTouchSelectionController( 152 ui::TouchSelectionController* GetTouchSelectionController(
149 TouchEditableImplAura* touch_editable) { 153 TouchEditableImplAura* touch_editable) {
150 return touch_editable->touch_selection_controller_.get(); 154 return touch_editable->touch_selection_controller_.get();
151 } 155 }
152 156
153 ui::TextInputType GetTextInputType(TouchEditableImplAura* touch_editable) { 157 ui::TextInputType GetTextInputType(TouchEditableImplAura* touch_editable) {
154 return touch_editable->text_input_type_; 158 return touch_editable->text_input_type_;
155 } 159 }
156 160
157 private: 161 private:
162 wm::DefaultScreenPositionClient screen_position_client_;
163
158 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAuraTest); 164 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAuraTest);
159 }; 165 };
160 166
161 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, 167 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest,
162 TouchSelectionOriginatingFromWebpageTest) { 168 TouchSelectionOriginatingFromWebpageTest) {
163 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); 169 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html"));
164 WebContentsImpl* web_contents = 170 WebContentsImpl* web_contents =
165 static_cast<WebContentsImpl*>(shell()->web_contents()); 171 static_cast<WebContentsImpl*>(shell()->web_contents());
166 RenderFrameHost* main_frame = web_contents->GetMainFrame(); 172 RenderFrameHost* main_frame = web_contents->GetMainFrame();
167 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( 173 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>(
(...skipping 18 matching lines...) Expand all
186 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); 192 content::ExecuteScriptAndGetValue(main_frame, "get_selection()");
187 std::string selection; 193 std::string selection;
188 value->GetAsString(&selection); 194 value->GetAsString(&selection);
189 195
190 // Check if selection handles are showing. 196 // Check if selection handles are showing.
191 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); 197 EXPECT_TRUE(GetTouchSelectionController(touch_editable));
192 EXPECT_STREQ("Some text we can select", selection.c_str()); 198 EXPECT_STREQ("Some text we can select", selection.c_str());
193 199
194 // Lets move the handles a bit to modify the selection 200 // Lets move the handles a bit to modify the selection
195 touch_editable->Reset(); 201 touch_editable->Reset();
202 ui::SelectionBound anchor, focus;
203 touch_editable->GetSelectionEndPoints(&anchor, &focus);
204 int handle_grab_x = bounds.x() + anchor.edge_bottom.x();
205 int handle_grab_y = bounds.y() + anchor.edge_bottom.y() + 1;
196 generator.GestureScrollSequence( 206 generator.GestureScrollSequence(
197 gfx::Point(10, 47), 207 gfx::Point(handle_grab_x, handle_grab_y),
198 gfx::Point(30, 47), 208 gfx::Point(handle_grab_x + 20, handle_grab_y),
199 base::TimeDelta::FromMilliseconds(20), 209 base::TimeDelta::FromMilliseconds(20),
200 5); 210 5);
201 touch_editable->WaitForSelectionChangeCallback(); 211 touch_editable->WaitForSelectionChangeCallback();
202 212
203 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); 213 EXPECT_TRUE(GetTouchSelectionController(touch_editable));
204 value = content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); 214 value = content::ExecuteScriptAndGetValue(main_frame, "get_selection()");
205 value->GetAsString(&selection); 215 value->GetAsString(&selection);
206 216
207 // It is hard to tell what exactly the selection would be now. But it would 217 // It is hard to tell what exactly the selection would be now. But it would
208 // definitely be less than whatever was selected before. 218 // definitely be less than whatever was selected before.
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 value = content::ExecuteScriptAndGetValue(main_frame, 452 value = content::ExecuteScriptAndGetValue(main_frame,
443 "get_cursor_position()"); 453 "get_cursor_position()");
444 int new_cursor_pos = -1; 454 int new_cursor_pos = -1;
445 value->GetAsInteger(&new_cursor_pos); 455 value->GetAsInteger(&new_cursor_pos);
446 EXPECT_NE(-1, new_cursor_pos); 456 EXPECT_NE(-1, new_cursor_pos);
447 // Cursor should have moved. 457 // Cursor should have moved.
448 EXPECT_NE(new_cursor_pos, cursor_pos); 458 EXPECT_NE(new_cursor_pos, cursor_pos);
449 } 459 }
450 460
451 } // namespace content 461 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698