OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <queue> | 5 #include <queue> |
6 #include <set> | 6 #include <set> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #include "extensions/browser/api/extensions_api_client.h" | 69 #include "extensions/browser/api/extensions_api_client.h" |
70 #include "extensions/browser/app_window/native_app_window.h" | 70 #include "extensions/browser/app_window/native_app_window.h" |
71 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 71 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
72 #include "extensions/common/extension.h" | 72 #include "extensions/common/extension.h" |
73 #include "extensions/common/extensions_client.h" | 73 #include "extensions/common/extensions_client.h" |
74 #include "extensions/test/extension_test_message_listener.h" | 74 #include "extensions/test/extension_test_message_listener.h" |
75 #include "media/base/media_switches.h" | 75 #include "media/base/media_switches.h" |
76 #include "net/test/embedded_test_server/embedded_test_server.h" | 76 #include "net/test/embedded_test_server/embedded_test_server.h" |
77 #include "net/test/embedded_test_server/http_request.h" | 77 #include "net/test/embedded_test_server/http_request.h" |
78 #include "net/test/embedded_test_server/http_response.h" | 78 #include "net/test/embedded_test_server/http_response.h" |
| 79 #include "ui/aura/env.h" |
79 #include "ui/aura/window.h" | 80 #include "ui/aura/window.h" |
80 #include "ui/base/l10n/l10n_util.h" | 81 #include "ui/base/l10n/l10n_util.h" |
81 #include "ui/compositor/compositor.h" | 82 #include "ui/compositor/compositor.h" |
82 #include "ui/compositor/compositor_observer.h" | 83 #include "ui/compositor/compositor_observer.h" |
83 #include "ui/display/display_switches.h" | 84 #include "ui/display/display_switches.h" |
84 #include "ui/events/event_switches.h" | 85 #include "ui/events/event_switches.h" |
85 #include "ui/events/gesture_detection/gesture_configuration.h" | 86 #include "ui/events/gesture_detection/gesture_configuration.h" |
86 #include "ui/gl/gl_switches.h" | 87 #include "ui/gl/gl_switches.h" |
87 #include "ui/views/view.h" | 88 #include "ui/views/view.h" |
88 #include "ui/views/widget/widget.h" | 89 #include "ui/views/widget/widget.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 if (std::string(current->GetClassName()).find("WebView") != | 240 if (std::string(current->GetClassName()).find("WebView") != |
240 std::string::npos) { | 241 std::string::npos) { |
241 return current; | 242 return current; |
242 } | 243 } |
243 | 244 |
244 for (int i = 0; i < current->child_count(); ++i) | 245 for (int i = 0; i < current->child_count(); ++i) |
245 queue.push(current->child_at(i)); | 246 queue.push(current->child_at(i)); |
246 } | 247 } |
247 return nullptr; | 248 return nullptr; |
248 } | 249 } |
| 250 |
| 251 // Waits for select control shown/closed. |
| 252 class SelectControlWaiter : public aura::WindowObserver, |
| 253 public aura::EnvObserver { |
| 254 public: |
| 255 SelectControlWaiter() { |
| 256 aura::Env::GetInstanceDontCreate()->AddObserver(this); |
| 257 } |
| 258 |
| 259 ~SelectControlWaiter() override { |
| 260 aura::Env::GetInstanceDontCreate()->RemoveObserver(this); |
| 261 } |
| 262 |
| 263 void Wait(bool wait_for_widget_shown) { |
| 264 wait_for_widget_shown_ = wait_for_widget_shown; |
| 265 message_loop_runner_ = new content::MessageLoopRunner; |
| 266 message_loop_runner_->Run(); |
| 267 base::RunLoop().RunUntilIdle(); |
| 268 } |
| 269 |
| 270 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override { |
| 271 if (wait_for_widget_shown_ && visible) |
| 272 message_loop_runner_->Quit(); |
| 273 } |
| 274 |
| 275 void OnWindowInitialized(aura::Window* window) override { |
| 276 if (window->type() != ui::wm::WINDOW_TYPE_MENU) |
| 277 return; |
| 278 window->AddObserver(this); |
| 279 observed_windows_.insert(window); |
| 280 } |
| 281 |
| 282 void OnWindowDestroyed(aura::Window* window) override { |
| 283 observed_windows_.erase(window); |
| 284 if (!wait_for_widget_shown_ && observed_windows_.empty()) |
| 285 message_loop_runner_->Quit(); |
| 286 } |
| 287 |
| 288 private: |
| 289 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 290 std::set<aura::Window*> observed_windows_; |
| 291 bool wait_for_widget_shown_ = false; |
| 292 |
| 293 DISALLOW_COPY_AND_ASSIGN(SelectControlWaiter); |
| 294 }; |
| 295 |
| 296 // Simulate real click with delay between mouse down and up. |
| 297 class LeftMouseClick { |
| 298 public: |
| 299 explicit LeftMouseClick(content::WebContents* web_contents) |
| 300 : web_contents_(web_contents) {} |
| 301 |
| 302 ~LeftMouseClick() { |
| 303 DCHECK(click_completed_); |
| 304 } |
| 305 |
| 306 void Click(const gfx::Point& point, int duration_ms) { |
| 307 DCHECK(click_completed_); |
| 308 click_completed_ = false; |
| 309 mouse_event_.type = blink::WebInputEvent::MouseDown; |
| 310 mouse_event_.button = blink::WebMouseEvent::ButtonLeft; |
| 311 mouse_event_.x = point.x(); |
| 312 mouse_event_.y = point.y(); |
| 313 mouse_event_.modifiers = 0; |
| 314 const gfx::Rect offset = web_contents_->GetContainerBounds(); |
| 315 mouse_event_.globalX = point.x() + offset.x(); |
| 316 mouse_event_.globalY = point.y() + offset.y(); |
| 317 mouse_event_.clickCount = 1; |
| 318 web_contents_->GetRenderViewHost()->GetWidget()->ForwardMouseEvent( |
| 319 mouse_event_); |
| 320 |
| 321 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 322 FROM_HERE, base::Bind(&LeftMouseClick::SendMouseUp, |
| 323 base::Unretained(this)), |
| 324 base::TimeDelta::FromMilliseconds(duration_ms)); |
| 325 } |
| 326 |
| 327 // Wait for click completed. |
| 328 void Wait() { |
| 329 if (click_completed_) |
| 330 return; |
| 331 message_loop_runner_ = new content::MessageLoopRunner; |
| 332 message_loop_runner_->Run(); |
| 333 message_loop_runner_ = nullptr; |
| 334 } |
| 335 |
| 336 private: |
| 337 void SendMouseUp() { |
| 338 mouse_event_.type = blink::WebInputEvent::MouseUp; |
| 339 web_contents_->GetRenderViewHost()->GetWidget()->ForwardMouseEvent( |
| 340 mouse_event_); |
| 341 click_completed_ = true; |
| 342 if (message_loop_runner_) |
| 343 message_loop_runner_->Quit(); |
| 344 } |
| 345 |
| 346 // Unowned pointer. |
| 347 content::WebContents* web_contents_; |
| 348 |
| 349 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 350 |
| 351 blink::WebMouseEvent mouse_event_; |
| 352 |
| 353 bool click_completed_ = true; |
| 354 |
| 355 DISALLOW_COPY_AND_ASSIGN(LeftMouseClick); |
| 356 }; |
| 357 |
249 #endif | 358 #endif |
250 | 359 |
251 } // namespace | 360 } // namespace |
252 | 361 |
253 // This class intercepts media access request from the embedder. The request | 362 // This class intercepts media access request from the embedder. The request |
254 // should be triggered only if the embedder API (from tests) allows the request | 363 // should be triggered only if the embedder API (from tests) allows the request |
255 // in Javascript. | 364 // in Javascript. |
256 // We do not issue the actual media request; the fact that the request reached | 365 // We do not issue the actual media request; the fact that the request reached |
257 // embedder's WebContents is good enough for our tests. This is also to make | 366 // embedder's WebContents is good enough for our tests. This is also to make |
258 // the test run successfully on trybots. | 367 // the test run successfully on trybots. |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 | 1229 |
1121 // Tests that addListener call succeeds on webview's WebRequest API events. | 1230 // Tests that addListener call succeeds on webview's WebRequest API events. |
1122 IN_PROC_BROWSER_TEST_P(WebViewTest, Shim_TestWebRequestAPIAddListener) { | 1231 IN_PROC_BROWSER_TEST_P(WebViewTest, Shim_TestWebRequestAPIAddListener) { |
1123 TestHelper("testWebRequestAPIAddListener", "web_view/shim", NO_TEST_SERVER); | 1232 TestHelper("testWebRequestAPIAddListener", "web_view/shim", NO_TEST_SERVER); |
1124 } | 1233 } |
1125 | 1234 |
1126 IN_PROC_BROWSER_TEST_P(WebViewTest, Shim_TestWebRequestAPIErrorOccurred) { | 1235 IN_PROC_BROWSER_TEST_P(WebViewTest, Shim_TestWebRequestAPIErrorOccurred) { |
1127 TestHelper("testWebRequestAPIErrorOccurred", "web_view/shim", NO_TEST_SERVER); | 1236 TestHelper("testWebRequestAPIErrorOccurred", "web_view/shim", NO_TEST_SERVER); |
1128 } | 1237 } |
1129 | 1238 |
| 1239 #if defined(USE_AURA) |
| 1240 // Test validates that select tag can be shown and hidden in webview safely |
| 1241 // using quick touch. |
| 1242 IN_PROC_BROWSER_TEST_P(WebViewTest, SelectShowHide) { |
| 1243 LoadAppWithGuest("web_view/select"); |
| 1244 |
| 1245 content::WebContents* embedder_contents = GetFirstAppWindowWebContents(); |
| 1246 ASSERT_TRUE(embedder_contents); |
| 1247 |
| 1248 std::vector<content::WebContents*> guest_contents_list; |
| 1249 GetGuestViewManager()->GetGuestWebContentsList(&guest_contents_list); |
| 1250 ASSERT_EQ(1u, guest_contents_list.size()); |
| 1251 content::WebContents* guest_contents = guest_contents_list[0]; |
| 1252 |
| 1253 const gfx::Rect embedder_rect = embedder_contents->GetContainerBounds(); |
| 1254 const gfx::Rect guest_rect = guest_contents->GetContainerBounds(); |
| 1255 const gfx::Point click_point(guest_rect.x() - embedder_rect.x() + 10, |
| 1256 guest_rect.y() - embedder_rect.y() + 10); |
| 1257 |
| 1258 // Important, pass mouse click to embedder in order to transfer focus. Note |
| 1259 // that SelectControlWaiter may be waited ealier than click is completed. |
| 1260 LeftMouseClick mouse_click(embedder_contents); |
| 1261 SelectControlWaiter select_control_waiter; |
| 1262 |
| 1263 for (int i = 0; i < 5; ++i) { |
| 1264 const int click_duration_ms = 10 + i * 25; |
| 1265 mouse_click.Click(click_point, click_duration_ms); |
| 1266 select_control_waiter.Wait(true); |
| 1267 mouse_click.Wait(); |
| 1268 |
| 1269 mouse_click.Click(click_point, click_duration_ms); |
| 1270 select_control_waiter.Wait(false); |
| 1271 mouse_click.Wait(); |
| 1272 } |
| 1273 } |
| 1274 #endif |
| 1275 |
1130 // http://crbug.com/315920 | 1276 // http://crbug.com/315920 |
1131 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX)) | 1277 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX)) |
1132 #define MAYBE_Shim_TestChromeExtensionURL DISABLED_Shim_TestChromeExtensionURL | 1278 #define MAYBE_Shim_TestChromeExtensionURL DISABLED_Shim_TestChromeExtensionURL |
1133 #else | 1279 #else |
1134 #define MAYBE_Shim_TestChromeExtensionURL Shim_TestChromeExtensionURL | 1280 #define MAYBE_Shim_TestChromeExtensionURL Shim_TestChromeExtensionURL |
1135 #endif | 1281 #endif |
1136 IN_PROC_BROWSER_TEST_P(WebViewTest, MAYBE_Shim_TestChromeExtensionURL) { | 1282 IN_PROC_BROWSER_TEST_P(WebViewTest, MAYBE_Shim_TestChromeExtensionURL) { |
1137 TestHelper("testChromeExtensionURL", "web_view/shim", NO_TEST_SERVER); | 1283 TestHelper("testChromeExtensionURL", "web_view/shim", NO_TEST_SERVER); |
1138 } | 1284 } |
1139 | 1285 |
(...skipping 2536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3676 gfx::Point embedder_origin = | 3822 gfx::Point embedder_origin = |
3677 GetEmbedderWebContents()->GetContainerBounds().origin(); | 3823 GetEmbedderWebContents()->GetContainerBounds().origin(); |
3678 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y()); | 3824 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y()); |
3679 | 3825 |
3680 // Generate and send synthetic touch event. | 3826 // Generate and send synthetic touch event. |
3681 content::SimulateTouchPressAt(GetEmbedderWebContents(), | 3827 content::SimulateTouchPressAt(GetEmbedderWebContents(), |
3682 guest_rect.CenterPoint()); | 3828 guest_rect.CenterPoint()); |
3683 EXPECT_TRUE(aura_webview->HasFocus()); | 3829 EXPECT_TRUE(aura_webview->HasFocus()); |
3684 } | 3830 } |
3685 #endif | 3831 #endif |
OLD | NEW |