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

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: Removing the SelectionBound test from Android, since touch_editing_controller not included in Andro… 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
« no previous file with comments | « content/browser/web_contents/touch_editable_impl_aura.cc ('k') | ui/base/BUILD.gn » ('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"
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 void OnSelectionOrCursorChanged(const ui::SelectionBound& anchor,
53 const gfx::Rect& focus) override { 54 const ui::SelectionBound& focus) override {
54 selection_changed_callback_arrived_ = true; 55 selection_changed_callback_arrived_ = true;
55 TouchEditableImplAura::OnSelectionOrCursorChanged(anchor, focus); 56 TouchEditableImplAura::OnSelectionOrCursorChanged(anchor, focus);
56 if (waiting_for_selection_changed_callback_) 57 if (waiting_for_selection_changed_callback_)
57 selection_changed_wait_run_loop_->Quit(); 58 selection_changed_wait_run_loop_->Quit();
58 } 59 }
59 60
60 virtual void GestureEventAck(int gesture_event_type) override { 61 void GestureEventAck(int gesture_event_type) override {
61 last_gesture_ack_type_ = 62 last_gesture_ack_type_ =
62 static_cast<WebInputEvent::Type>(gesture_event_type); 63 static_cast<WebInputEvent::Type>(gesture_event_type);
63 TouchEditableImplAura::GestureEventAck(gesture_event_type); 64 TouchEditableImplAura::GestureEventAck(gesture_event_type);
64 if (waiting_for_gesture_ack_type_ == gesture_event_type) 65 if (waiting_for_gesture_ack_type_ == gesture_event_type)
65 gesture_ack_wait_run_loop_->Quit(); 66 gesture_ack_wait_run_loop_->Quit();
66 } 67 }
67 68
68 virtual void DidStopFlinging() override { 69 void DidStopFlinging() override {
69 fling_stop_callback_arrived_ = true; 70 fling_stop_callback_arrived_ = true;
70 TouchEditableImplAura::DidStopFlinging(); 71 TouchEditableImplAura::DidStopFlinging();
71 if (waiting_for_fling_stop_callback_) 72 if (waiting_for_fling_stop_callback_)
72 fling_stop_wait_run_loop_->Quit(); 73 fling_stop_wait_run_loop_->Quit();
73 } 74 }
74 75
75 virtual void WaitForSelectionChangeCallback() { 76 virtual void WaitForSelectionChangeCallback() {
76 if (selection_changed_callback_arrived_) 77 if (selection_changed_callback_arrived_)
77 return; 78 return;
78 waiting_for_selection_changed_callback_ = true; 79 waiting_for_selection_changed_callback_ = true;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 scoped_ptr<base::RunLoop> fling_stop_wait_run_loop_; 112 scoped_ptr<base::RunLoop> fling_stop_wait_run_loop_;
112 113
113 DISALLOW_COPY_AND_ASSIGN(TestTouchEditableImplAura); 114 DISALLOW_COPY_AND_ASSIGN(TestTouchEditableImplAura);
114 }; 115 };
115 116
116 class TouchEditableImplAuraTest : public ContentBrowserTest { 117 class TouchEditableImplAuraTest : public ContentBrowserTest {
117 public: 118 public:
118 TouchEditableImplAuraTest() {} 119 TouchEditableImplAuraTest() {}
119 120
120 protected: 121 protected:
121 virtual void SetUpCommandLine(CommandLine* command_line) override { 122 void SetUpOnMainThread() override {
123 ContentBrowserTest::SetUpOnMainThread();
124 aura::client::SetScreenPositionClient(shell()->window()->GetRootWindow(),
125 &screen_position_client_);
126 }
127
128 void SetUpCommandLine(CommandLine* command_line) override {
122 command_line->AppendSwitch(switches::kEnableTouchEditing); 129 command_line->AppendSwitch(switches::kEnableTouchEditing);
123 } 130 }
124 131
125 // Executes the javascript synchronously and makes sure the returned value is 132 // Executes the javascript synchronously and makes sure the returned value is
126 // freed properly. 133 // freed properly.
127 void ExecuteSyncJSFunction(RenderFrameHost* rfh, const std::string& jscript) { 134 void ExecuteSyncJSFunction(RenderFrameHost* rfh, const std::string& jscript) {
128 scoped_ptr<base::Value> value = 135 scoped_ptr<base::Value> value =
129 content::ExecuteScriptAndGetValue(rfh, jscript); 136 content::ExecuteScriptAndGetValue(rfh, jscript);
130 } 137 }
131 138
(...skipping 16 matching lines...) Expand all
148 ui::TouchSelectionController* GetTouchSelectionController( 155 ui::TouchSelectionController* GetTouchSelectionController(
149 TouchEditableImplAura* touch_editable) { 156 TouchEditableImplAura* touch_editable) {
150 return touch_editable->touch_selection_controller_.get(); 157 return touch_editable->touch_selection_controller_.get();
151 } 158 }
152 159
153 ui::TextInputType GetTextInputType(TouchEditableImplAura* touch_editable) { 160 ui::TextInputType GetTextInputType(TouchEditableImplAura* touch_editable) {
154 return touch_editable->text_input_type_; 161 return touch_editable->text_input_type_;
155 } 162 }
156 163
157 private: 164 private:
165 wm::DefaultScreenPositionClient screen_position_client_;
166
158 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAuraTest); 167 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAuraTest);
159 }; 168 };
160 169
161 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, 170 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest,
162 TouchSelectionOriginatingFromWebpageTest) { 171 TouchSelectionOriginatingFromWebpageTest) {
163 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); 172 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html"));
164 WebContentsImpl* web_contents = 173 WebContentsImpl* web_contents =
165 static_cast<WebContentsImpl*>(shell()->web_contents()); 174 static_cast<WebContentsImpl*>(shell()->web_contents());
166 RenderFrameHost* main_frame = web_contents->GetMainFrame(); 175 RenderFrameHost* main_frame = web_contents->GetMainFrame();
167 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( 176 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>(
(...skipping 18 matching lines...) Expand all
186 content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); 195 content::ExecuteScriptAndGetValue(main_frame, "get_selection()");
187 std::string selection; 196 std::string selection;
188 value->GetAsString(&selection); 197 value->GetAsString(&selection);
189 198
190 // Check if selection handles are showing. 199 // Check if selection handles are showing.
191 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); 200 EXPECT_TRUE(GetTouchSelectionController(touch_editable));
192 EXPECT_STREQ("Some text we can select", selection.c_str()); 201 EXPECT_STREQ("Some text we can select", selection.c_str());
193 202
194 // Lets move the handles a bit to modify the selection 203 // Lets move the handles a bit to modify the selection
195 touch_editable->Reset(); 204 touch_editable->Reset();
205 ui::SelectionBound anchor, focus;
206 touch_editable->GetSelectionEndPoints(&anchor, &focus);
207 int handle_grab_x = bounds.x() + anchor.edge_bottom.x();
208 int handle_grab_y = bounds.y() + anchor.edge_bottom.y() + 1;
196 generator.GestureScrollSequence( 209 generator.GestureScrollSequence(
197 gfx::Point(10, 47), 210 gfx::Point(handle_grab_x, handle_grab_y),
198 gfx::Point(30, 47), 211 gfx::Point(handle_grab_x + 20, handle_grab_y),
199 base::TimeDelta::FromMilliseconds(20), 212 base::TimeDelta::FromMilliseconds(20),
200 5); 213 5);
201 touch_editable->WaitForSelectionChangeCallback(); 214 touch_editable->WaitForSelectionChangeCallback();
202 215
203 EXPECT_TRUE(GetTouchSelectionController(touch_editable)); 216 EXPECT_TRUE(GetTouchSelectionController(touch_editable));
204 value = content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); 217 value = content::ExecuteScriptAndGetValue(main_frame, "get_selection()");
205 value->GetAsString(&selection); 218 value->GetAsString(&selection);
206 219
207 // It is hard to tell what exactly the selection would be now. But it would 220 // It is hard to tell what exactly the selection would be now. But it would
208 // definitely be less than whatever was selected before. 221 // 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, 455 value = content::ExecuteScriptAndGetValue(main_frame,
443 "get_cursor_position()"); 456 "get_cursor_position()");
444 int new_cursor_pos = -1; 457 int new_cursor_pos = -1;
445 value->GetAsInteger(&new_cursor_pos); 458 value->GetAsInteger(&new_cursor_pos);
446 EXPECT_NE(-1, new_cursor_pos); 459 EXPECT_NE(-1, new_cursor_pos);
447 // Cursor should have moved. 460 // Cursor should have moved.
448 EXPECT_NE(new_cursor_pos, cursor_pos); 461 EXPECT_NE(new_cursor_pos, cursor_pos);
449 } 462 }
450 463
451 } // namespace content 464 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/touch_editable_impl_aura.cc ('k') | ui/base/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698