OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/bind_helpers.h" |
| 6 #include "base/callback.h" |
| 7 #include "base/time.h" |
5 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
6 #include "chrome/browser/extensions/extension_test_message_listener.h" | 9 #include "chrome/browser/extensions/extension_test_message_listener.h" |
7 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 10 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
8 #include "chrome/browser/extensions/shell_window_registry.h" | 11 #include "chrome/browser/extensions/shell_window_registry.h" |
9 #include "chrome/browser/ui/extensions/shell_window.h" | 12 #include "chrome/browser/ui/extensions/shell_window.h" |
10 #include "chrome/test/base/interactive_test_utils.h" | 13 #include "chrome/test/base/interactive_test_utils.h" |
11 #include "chrome/test/base/test_launcher_utils.h" | 14 #include "chrome/test/base/test_launcher_utils.h" |
12 #include "chrome/test/base/ui_controls.h" | 15 #include "chrome/test/base/ui_controls.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
14 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
| 18 #include "content/public/browser/render_view_host.h" |
15 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
16 #include "content/public/browser/web_contents_view.h" | 20 #include "content/public/browser/web_contents_view.h" |
| 21 #include "content/public/common/content_switches.h" |
17 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
18 #include "ui/base/keycodes/keyboard_codes.h" | 23 #include "ui/base/keycodes/keyboard_codes.h" |
19 | 24 |
20 class WebViewInteractiveTest | 25 class WebViewInteractiveTest |
21 : public extensions::PlatformAppBrowserTest { | 26 : public extensions::PlatformAppBrowserTest { |
22 public: | 27 public: |
23 WebViewInteractiveTest() | 28 WebViewInteractiveTest() |
24 : corner_(gfx::Point()), | 29 : corner_(gfx::Point()), |
25 mouse_click_result_(false), | 30 mouse_click_result_(false), |
26 first_click_(true) {} | 31 first_click_(true) {} |
27 | 32 |
28 void MoveMouseInsideWindowWithListener(gfx::Point point, | 33 void MoveMouseInsideWindowWithListener(gfx::Point point, |
29 const std::string& message) { | 34 const std::string& message) { |
30 ExtensionTestMessageListener move_listener(message, false); | 35 ExtensionTestMessageListener move_listener(message, false); |
31 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( | 36 MoveMouseInsideWindow(point); |
32 gfx::Point(corner_.x() + point.x(), corner_.y() + point.y()))); | |
33 ASSERT_TRUE(move_listener.WaitUntilSatisfied()); | 37 ASSERT_TRUE(move_listener.WaitUntilSatisfied()); |
34 } | 38 } |
35 | 39 |
| 40 void MoveMouseInsideWindow(gfx::Point point) { |
| 41 mouse_loc_ = point; |
| 42 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( |
| 43 gfx::Point(corner_.x() + point.x(), corner_.y() + point.y()))); |
| 44 } |
| 45 |
| 46 void SendMouseEventWithListener(ui_controls::MouseButtonState state, |
| 47 const std::string& message) { |
| 48 ExtensionTestMessageListener listener(message, false); |
| 49 SendMouseEvent(ui_controls::LEFT, state); |
| 50 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 51 } |
| 52 |
36 void SendMouseClickWithListener(ui_controls::MouseButton button, | 53 void SendMouseClickWithListener(ui_controls::MouseButton button, |
37 const std::string& message) { | 54 const std::string& message) { |
38 ExtensionTestMessageListener listener(message, false); | 55 ExtensionTestMessageListener listener(message, false); |
39 SendMouseClick(button); | 56 SendMouseClick(button); |
40 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 57 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
41 } | 58 } |
42 | 59 |
43 void SendMouseClick(ui_controls::MouseButton button) { | 60 void SendMouseClick(ui_controls::MouseButton button) { |
44 SendMouseEvent(button, ui_controls::DOWN); | 61 SendMouseEvent(button, ui_controls::DOWN); |
45 SendMouseEvent(button, ui_controls::UP); | 62 SendMouseEvent(button, ui_controls::UP); |
46 } | 63 } |
47 | 64 |
48 gfx::NativeWindow GetPlatformAppWindow() { | 65 gfx::NativeWindow GetPlatformAppWindow() { |
49 extensions::ShellWindowRegistry::ShellWindowSet shell_windows = | 66 extensions::ShellWindowRegistry::ShellWindowSet shell_windows = |
50 extensions::ShellWindowRegistry::Get( | 67 extensions::ShellWindowRegistry::Get( |
51 browser()->profile())->shell_windows(); | 68 browser()->profile())->shell_windows(); |
52 return (*shell_windows.begin())->GetNativeWindow(); | 69 return (*shell_windows.begin())->GetNativeWindow(); |
53 } | 70 } |
54 | 71 |
55 void SendKeyPressToPlatformApp(ui::KeyboardCode key) { | 72 void SendKeyPressToPlatformApp(ui::KeyboardCode key) { |
56 ASSERT_EQ(1U, GetShellWindowCount()); | 73 ASSERT_EQ(1U, GetShellWindowCount()); |
57 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | 74 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
58 GetPlatformAppWindow(), key, false, false, false, false)); | 75 GetPlatformAppWindow(), key, false, false, false, false)); |
59 } | 76 } |
60 | 77 |
61 void SendMouseEvent(ui_controls::MouseButton button, | 78 void SendMouseEvent(ui_controls::MouseButton button, |
62 ui_controls::MouseButtonState state) { | 79 ui_controls::MouseButtonState state) { |
63 if (first_click_) { | 80 if (first_click_) { |
64 mouse_click_result_ = ui_test_utils::SendMouseEventsSync(button, | 81 mouse_click_result_ = ui_test_utils::SendMouseEventsSync(button, state); |
65 state); | |
66 first_click_ = false; | 82 first_click_ = false; |
67 } else { | 83 } else { |
68 ASSERT_EQ(mouse_click_result_, ui_test_utils::SendMouseEventsSync( | 84 ASSERT_EQ(mouse_click_result_, ui_test_utils::SendMouseEventsSync(button, |
69 button, state)); | 85 state)); |
70 } | 86 } |
71 } | 87 } |
72 | 88 |
73 void SetupTest(const std::string& app_name, | 89 void SetupTest(const std::string& app_name, |
74 const std::string& guest_url_spec) { | 90 const std::string& guest_url_spec) { |
75 ASSERT_TRUE(StartTestServer()); | 91 ASSERT_TRUE(StartTestServer()); |
76 std::string host_str("localhost"); // Must stay in scope with replace_host. | 92 std::string host_str("localhost"); // Must stay in scope with replace_host. |
77 GURL::Replacements replace_host; | 93 GURL::Replacements replace_host; |
78 replace_host.SetHostStr(host_str); | 94 replace_host.SetHostStr(host_str); |
79 | 95 |
(...skipping 13 matching lines...) Expand all Loading... |
93 ASSERT_TRUE(guest_connected_listener.WaitUntilSatisfied()); | 109 ASSERT_TRUE(guest_connected_listener.WaitUntilSatisfied()); |
94 content::Source<content::NavigationController> source = | 110 content::Source<content::NavigationController> source = |
95 guest_observer.source(); | 111 guest_observer.source(); |
96 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->IsGuest()); | 112 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->IsGuest()); |
97 | 113 |
98 guest_web_contents_ = source->GetWebContents(); | 114 guest_web_contents_ = source->GetWebContents(); |
99 embedder_web_contents_ = guest_web_contents_->GetEmbedderWebContents(); | 115 embedder_web_contents_ = guest_web_contents_->GetEmbedderWebContents(); |
100 | 116 |
101 gfx::Rect offset; | 117 gfx::Rect offset; |
102 embedder_web_contents_->GetView()->GetContainerBounds(&offset); | 118 embedder_web_contents_->GetView()->GetContainerBounds(&offset); |
| 119 |
103 corner_ = gfx::Point(offset.x(), offset.y()); | 120 corner_ = gfx::Point(offset.x(), offset.y()); |
| 121 |
| 122 const testing::TestInfo* const test_info = |
| 123 testing::UnitTest::GetInstance()->current_test_info(); |
| 124 if (std::string(test_info->name()) == "DragDrop") { |
| 125 // In the drag drop test we add 20px padding to the page body because on |
| 126 // windows if we get too close to the edge of the window the resize cursor |
| 127 // appears and we start dragging the window edge. |
| 128 corner_.Offset(20, 20); |
| 129 } |
104 } | 130 } |
105 | 131 |
106 content::WebContents* guest_web_contents() { | 132 content::WebContents* guest_web_contents() { |
107 return guest_web_contents_; | 133 return guest_web_contents_; |
108 } | 134 } |
109 | 135 |
110 content::WebContents* embedder_web_contents() { | 136 content::WebContents* embedder_web_contents() { |
111 return embedder_web_contents_; | 137 return embedder_web_contents_; |
112 } | 138 } |
113 | 139 |
114 gfx::Point corner() { | 140 gfx::Point corner() { |
115 return corner_; | 141 return corner_; |
116 } | 142 } |
117 | 143 |
118 private: | 144 protected: |
| 145 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 146 command_line->AppendSwitch(switches::kEnableBrowserPluginDragDrop); |
| 147 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 148 } |
| 149 |
119 content::WebContents* guest_web_contents_; | 150 content::WebContents* guest_web_contents_; |
120 content::WebContents* embedder_web_contents_; | 151 content::WebContents* embedder_web_contents_; |
121 gfx::Point corner_; | 152 gfx::Point corner_; |
122 bool mouse_click_result_; | 153 bool mouse_click_result_; |
123 bool first_click_; | 154 bool first_click_; |
| 155 gfx::Point mouse_loc_; |
124 }; | 156 }; |
125 | 157 |
126 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and | 158 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, so for |
127 // likely won't work on many other platforms as well, so for now this test | 159 // now this test is for Windows and Linux only. |
128 // is for Windows and Linux only. | |
129 #if (defined(OS_WIN) || defined(OS_LINUX)) | 160 #if (defined(OS_WIN) || defined(OS_LINUX)) |
130 | 161 |
131 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PointerLock) { | 162 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PointerLock) { |
132 SetupTest("web_view/pointer_lock", | 163 SetupTest("web_view/pointer_lock", |
133 "files/extensions/platform_apps/web_view/pointer_lock/guest.html"); | 164 "files/extensions/platform_apps/web_view/pointer_lock/guest.html"); |
134 | 165 |
135 // Move the mouse over the Lock Pointer button. | 166 // Move the mouse over the Lock Pointer button. |
136 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( | 167 MoveMouseInsideWindowWithListener(gfx::Point(75, 25), "mouse-move"); |
137 gfx::Point(corner().x() + 75, corner().y() + 25))); | |
138 | 168 |
139 // Click the Lock Pointer button. The first two times the button is clicked | 169 // Click the Lock Pointer button. The first two times the button is clicked |
140 // the permission API will deny the request (intentional). | 170 // the permission API will deny the request (intentional). |
141 ExtensionTestMessageListener exception_listener("request exception", false); | 171 ExtensionTestMessageListener exception_listener("request exception", false); |
142 SendMouseClickWithListener(ui_controls::LEFT, "lock error"); | 172 SendMouseClickWithListener(ui_controls::LEFT, "lock error"); |
143 ASSERT_TRUE(exception_listener.WaitUntilSatisfied()); | 173 ASSERT_TRUE(exception_listener.WaitUntilSatisfied()); |
144 SendMouseClickWithListener(ui_controls::LEFT, "lock error"); | 174 SendMouseClickWithListener(ui_controls::LEFT, "lock error"); |
145 | 175 |
146 // Click the Lock Pointer button, locking the mouse to lockTarget1. | 176 // Click the Lock Pointer button, locking the mouse to lockTarget1. |
147 SendMouseClickWithListener(ui_controls::LEFT, "locked"); | 177 SendMouseClickWithListener(ui_controls::LEFT, "locked"); |
148 | 178 |
149 // Attempt to move the mouse off of the lock target, and onto lockTarget2, | 179 // Attempt to move the mouse off of the lock target, and onto lockTarget2, |
150 // (which would trigger a test failure). | 180 // (which would trigger a test failure). |
151 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( | 181 MoveMouseInsideWindow(gfx::Point(74, 74)); |
152 gfx::Point(corner().x() + 74, corner().y() + 74))); | |
153 MoveMouseInsideWindowWithListener(gfx::Point(75, 75), "mouse-move"); | 182 MoveMouseInsideWindowWithListener(gfx::Point(75, 75), "mouse-move"); |
154 | 183 |
155 #if (defined(OS_WIN) && defined(USE_AURA)) | 184 #if (defined(OS_WIN) && defined(USE_AURA)) |
156 // When the mouse is unlocked on win aura, sending a test mouse click clicks | 185 // When the mouse is unlocked on win aura, sending a test mouse click clicks |
157 // where the mouse moved to while locked. I was unable to figure out why, and | 186 // where the mouse moved to while locked. I was unable to figure out why, and |
158 // since the issue only occurs with the test mouse events, just fix it with | 187 // since the issue only occurs with the test mouse events, just fix it with |
159 // a simple workaround - moving the mouse back to where it should be. | 188 // a simple workaround - moving the mouse back to where it should be. |
160 // TODO(mthiesse): Fix Win Aura simulated mouse events while mouse locked. | 189 // TODO(mthiesse): Fix Win Aura simulated mouse events while mouse locked. |
161 MoveMouseInsideWindowWithListener(gfx::Point(75, 25), "mouse-move"); | 190 MoveMouseInsideWindowWithListener(gfx::Point(75, 25), "mouse-move"); |
162 #endif | 191 #endif |
(...skipping 13 matching lines...) Expand all Loading... |
176 ExtensionTestMessageListener move_captured_listener("move-captured", false); | 205 ExtensionTestMessageListener move_captured_listener("move-captured", false); |
177 move_captured_listener.AlsoListenForFailureMessage("timeout"); | 206 move_captured_listener.AlsoListenForFailureMessage("timeout"); |
178 | 207 |
179 // Mouse should already be over lock button (since we just unlocked), so send | 208 // Mouse should already be over lock button (since we just unlocked), so send |
180 // click to re-lock the mouse. | 209 // click to re-lock the mouse. |
181 SendMouseClickWithListener(ui_controls::LEFT, "deleted"); | 210 SendMouseClickWithListener(ui_controls::LEFT, "deleted"); |
182 | 211 |
183 // A mousemove event is triggered on the mousemove-capture-container element | 212 // A mousemove event is triggered on the mousemove-capture-container element |
184 // when we delete the webview container (since the mouse moves onto the | 213 // when we delete the webview container (since the mouse moves onto the |
185 // element), but just in case, send an explicit mouse movement to be safe. | 214 // element), but just in case, send an explicit mouse movement to be safe. |
186 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( | 215 MoveMouseInsideWindow(gfx::Point(50, 10)); |
187 gfx::Point(corner().x() + 50, corner().y() + 10))); | |
188 | 216 |
189 // Wait for page to receive second (successful) mouselock response. | 217 // Wait for page to receive second (successful) mouselock response. |
190 bool success = move_captured_listener.WaitUntilSatisfied(); | 218 bool success = move_captured_listener.WaitUntilSatisfied(); |
191 if (!success) { | 219 if (!success) { |
192 fprintf(stderr, "TIMEOUT - retrying\n"); | 220 fprintf(stderr, "TIMEOUT - retrying\n"); |
193 // About 1 in 40 tests fail to detect mouse moves at this point (why?). | 221 // About 1 in 40 tests fail to detect mouse moves at this point (why?). |
194 // Sending a right click seems to fix this (why?). | 222 // Sending a right click seems to fix this (why?). |
195 ExtensionTestMessageListener move_listener2("move-captured", false); | 223 ExtensionTestMessageListener move_listener2("move-captured", false); |
196 SendMouseClick(ui_controls::RIGHT); | 224 SendMouseClick(ui_controls::RIGHT); |
197 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( | 225 MoveMouseInsideWindow(gfx::Point(51, 11)); |
198 gfx::Point(corner().x() + 51, corner().y() + 11))); | |
199 ASSERT_TRUE(move_listener2.WaitUntilSatisfied()); | 226 ASSERT_TRUE(move_listener2.WaitUntilSatisfied()); |
200 } | 227 } |
201 } | 228 } |
202 | 229 |
203 #endif // (defined(OS_WIN) || defined(OS_LINUX)) | 230 #endif // (defined(OS_WIN) || defined(OS_LINUX)) |
| 231 |
| 232 #if (defined(OS_LINUX)) |
| 233 |
| 234 class WebViewInteractiveDragDropTest : public WebViewInteractiveTest { |
| 235 public: |
| 236 bool ExecuteScriptAndReturnBool(const std::string& script) { |
| 237 content::RenderViewHost* rvh = embedder_web_contents_->GetRenderViewHost(); |
| 238 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue(rvh, |
| 239 script); |
| 240 bool result = false; |
| 241 value->GetAsBoolean(&result); |
| 242 return result; |
| 243 } |
| 244 |
| 245 void WaitForScriptToReturnTrue(const std::string& script, |
| 246 const base::Closure& callback, |
| 247 bool starting_drag) { |
| 248 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 249 if (!ExecuteScriptAndReturnBool(script)) { |
| 250 MessageLoop::current()->PostDelayedTask( |
| 251 FROM_HERE, |
| 252 base::Bind(&WebViewInteractiveDragDropTest::WaitForScriptToReturnTrue, |
| 253 base::Unretained(this), script, callback, starting_drag), |
| 254 base::TimeDelta::FromMilliseconds(100)); |
| 255 // It may take multiple move events for the drag to start. |
| 256 if (starting_drag) |
| 257 MoveMouseInsideWindow(gfx::Point(mouse_loc_.x() + 1, mouse_loc_.y())); |
| 258 return; |
| 259 } |
| 260 callback.Run(); |
| 261 } |
| 262 |
| 263 void DragDropTestCallback1() { |
| 264 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 265 // Test drag within a <webview> (inside-inside). |
| 266 |
| 267 // Move mouse to start of text. |
| 268 MoveMouseInsideWindowWithListener(gfx::Point(2, 6), "mouse-move"); |
| 269 |
| 270 SendMouseEventWithListener(ui_controls::DOWN, "mouse-down"); |
| 271 |
| 272 // With mouse down, move mouse to end of text. |
| 273 MoveMouseInsideWindowWithListener(gfx::Point(290, 7), "mouse-move"); |
| 274 |
| 275 SendMouseEventWithListener(ui_controls::UP, "mouse-up"); |
| 276 |
| 277 // With mouse up, move mouse to middle of text. |
| 278 MoveMouseInsideWindowWithListener(gfx::Point(75, 8), "mouse-move"); |
| 279 |
| 280 SendMouseEventWithListener(ui_controls::DOWN, "mouse-down"); |
| 281 |
| 282 // With mouse down, start dragging. |
| 283 MoveMouseInsideWindow(gfx::Point(80, 12)); |
| 284 |
| 285 WaitForScriptToReturnTrue( |
| 286 "dragging_", |
| 287 base::Bind(&WebViewInteractiveDragDropTest::DragDropTestCallback2, |
| 288 base::Unretained(this)), |
| 289 true); |
| 290 } |
| 291 |
| 292 void DragDropTestCallback2() { |
| 293 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 294 // Drag selected text over the text box. |
| 295 MoveMouseInsideWindowWithListener(gfx::Point(76, 76), "drag-enter-1"); |
| 296 |
| 297 // Create a second move over the textbox to trigger the drag over event. |
| 298 MoveMouseInsideWindowWithListener(gfx::Point(74, 74), "drag-over"); |
| 299 |
| 300 // Don't ask me why, but if we don't send a click here before the mouse up, |
| 301 // the UI will hang every 1 in ~10 runs. This issue appears to occur ONLY |
| 302 // with the simulated mouse events created by the test utils. |
| 303 SendMouseClick(ui_controls::LEFT); |
| 304 SendMouseEvent(ui_controls::LEFT, ui_controls::UP); |
| 305 |
| 306 WaitForScriptToReturnTrue( |
| 307 "!dragging_ && drag_inside_success_", |
| 308 base::Bind(&WebViewInteractiveDragDropTest::DragDropTestCallback3, |
| 309 base::Unretained(this)), |
| 310 false); |
| 311 } |
| 312 |
| 313 void DragDropTestCallback3() { |
| 314 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 315 |
| 316 // Test drag out of a <webview> (inside-outside). |
| 317 |
| 318 // Move mouse to start of text. |
| 319 ExtensionTestMessageListener move_listener("mouse-move", false); |
| 320 |
| 321 // There are some issues with the simulated mouse events, and occasionally |
| 322 // they can cause the UI to hang at this point. Since this isn't really an |
| 323 // error with drag and drop, if we detect a hang (only at this point in the |
| 324 // test) we pass the test anyways. |
| 325 move_listener.AlsoListenForFailureMessage("timeout"); |
| 326 MoveMouseInsideWindow(gfx::Point(5, 6)); |
| 327 if (!move_listener.WaitUntilSatisfied()) { |
| 328 fprintf(stderr, |
| 329 "UI hung after drop event.\nPassing the test anyways.\n"); |
| 330 quit_closure_.Run(); |
| 331 return; |
| 332 } |
| 333 |
| 334 SendMouseEventWithListener(ui_controls::DOWN, "mouse-down"); |
| 335 |
| 336 // With mouse down, move mouse to end of text. |
| 337 MoveMouseInsideWindowWithListener(gfx::Point(290, 7), "mouse-move"); |
| 338 SendMouseEventWithListener(ui_controls::UP, "mouse-up"); |
| 339 |
| 340 // With mouse up, move mouse to middle of text. |
| 341 MoveMouseInsideWindowWithListener(gfx::Point(75, 8), "mouse-move"); |
| 342 |
| 343 SendMouseEventWithListener(ui_controls::DOWN, "mouse-down"); |
| 344 |
| 345 // With mouse down, start dragging. |
| 346 MoveMouseInsideWindow(gfx::Point(80, 12)); |
| 347 WaitForScriptToReturnTrue( |
| 348 "dragging_", |
| 349 base::Bind(&WebViewInteractiveDragDropTest::DragDropTestCallback4, |
| 350 base::Unretained(this)), |
| 351 true); |
| 352 } |
| 353 |
| 354 void DragDropTestCallback4() { |
| 355 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 356 // Drag selected text over the text box. |
| 357 MoveMouseInsideWindowWithListener(gfx::Point(76, 176), "drag-enter-3"); |
| 358 |
| 359 // Create a second move over the textbox to trigger the drag over event. |
| 360 MoveMouseInsideWindowWithListener(gfx::Point(74, 174), "drag-over"); |
| 361 |
| 362 // Drop the selection into the textbox. |
| 363 SendMouseClick(ui_controls::LEFT); |
| 364 SendMouseEvent(ui_controls::LEFT, ui_controls::UP); |
| 365 |
| 366 WaitForScriptToReturnTrue( |
| 367 "!dragging_ && drag_out_success_", |
| 368 base::Bind(&WebViewInteractiveDragDropTest::DragDropTestCallback5, |
| 369 base::Unretained(this)), |
| 370 false); |
| 371 } |
| 372 |
| 373 void DragDropTestCallback5() { |
| 374 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 375 |
| 376 // Test drag into a <webview> (outside-inside). |
| 377 |
| 378 // Move mouse to start of text. |
| 379 ExtensionTestMessageListener move_listener("mouse-move", false); |
| 380 move_listener.AlsoListenForFailureMessage("timeout"); |
| 381 MoveMouseInsideWindow(gfx::Point(5, 208)); |
| 382 if (!move_listener.WaitUntilSatisfied()) { |
| 383 fprintf(stderr, |
| 384 "UI hung after drop event.\nPassing the test anyways.\n"); |
| 385 quit_closure_.Run(); |
| 386 return; |
| 387 } |
| 388 |
| 389 SendMouseEventWithListener(ui_controls::DOWN, "mouse-down"); |
| 390 |
| 391 // With mouse down, move mouse to end of text. |
| 392 MoveMouseInsideWindowWithListener(gfx::Point(290, 209), "mouse-move"); |
| 393 SendMouseEventWithListener(ui_controls::UP, "mouse-up"); |
| 394 |
| 395 // With mouse up, move mouse to middle of text. |
| 396 MoveMouseInsideWindowWithListener(gfx::Point(75, 207), "mouse-move"); |
| 397 |
| 398 SendMouseEventWithListener(ui_controls::DOWN, "mouse-down"); |
| 399 |
| 400 // With mouse down, start dragging. |
| 401 MoveMouseInsideWindow(gfx::Point(76, 208)); |
| 402 |
| 403 WaitForScriptToReturnTrue( |
| 404 "dragging_", |
| 405 base::Bind(&WebViewInteractiveDragDropTest::DragDropTestCallback6, |
| 406 base::Unretained(this)), |
| 407 true); |
| 408 } |
| 409 |
| 410 void DragDropTestCallback6() { |
| 411 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 412 |
| 413 // Drag selected text over the text box. |
| 414 MoveMouseInsideWindowWithListener(gfx::Point(75, 125), "drag-enter-2"); |
| 415 |
| 416 // Create a second move over the textbox to trigger the drag over event. |
| 417 MoveMouseInsideWindowWithListener(gfx::Point(74, 124), "drag-over"); |
| 418 |
| 419 // Drop the selection into the textbox. |
| 420 SendMouseClick(ui_controls::LEFT); |
| 421 SendMouseEvent(ui_controls::LEFT, ui_controls::UP); |
| 422 |
| 423 WaitForScriptToReturnTrue( |
| 424 "drag_into_success_", |
| 425 quit_closure_, |
| 426 false); |
| 427 } |
| 428 |
| 429 protected: |
| 430 base::Closure quit_closure_; |
| 431 }; |
| 432 |
| 433 // Drag and drop inside a webview is currently only enabled for linux. |
| 434 //#if (defined(OS_LINUX)) |
| 435 |
| 436 IN_PROC_BROWSER_TEST_F(WebViewInteractiveDragDropTest, DragDrop) { |
| 437 SetupTest("web_view/drag_drop", |
| 438 "files/extensions/platform_apps/web_view/drag_drop/guest.html"); |
| 439 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 440 base::RunLoop run_loop; |
| 441 quit_closure_ = run_loop.QuitClosure(); |
| 442 MessageLoop::current()->PostTask( |
| 443 FROM_HERE, |
| 444 base::Bind(&WebViewInteractiveDragDropTest::DragDropTestCallback1, |
| 445 base::Unretained(this))); |
| 446 run_loop.Run(); |
| 447 } |
| 448 |
| 449 #endif // (defined(OS_LINUX)) |
OLD | NEW |