| 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 "content/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
| 6 | 6 |
| 7 #include <tuple> | 7 #include <tuple> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
| 12 #include "content/common/input/synthetic_web_input_event_builders.h" | 12 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 13 #include "content/common/input_messages.h" | 13 #include "content/common/input_messages.h" |
| 14 #include "content/common/resize_params.h" |
| 14 #include "content/public/test/mock_render_thread.h" | 15 #include "content/public/test/mock_render_thread.h" |
| 16 #include "content/renderer/devtools/render_widget_screen_metrics_emulator.h" |
| 15 #include "content/test/fake_compositor_dependencies.h" | 17 #include "content/test/fake_compositor_dependencies.h" |
| 16 #include "content/test/mock_render_process.h" | 18 #include "content/test/mock_render_process.h" |
| 17 #include "ipc/ipc_test_sink.h" | 19 #include "ipc/ipc_test_sink.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" |
| 20 #include "third_party/WebKit/public/web/WebInputEvent.h" | 23 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 21 #include "ui/events/blink/web_input_event_traits.h" | 24 #include "ui/events/blink/web_input_event_traits.h" |
| 22 #include "ui/gfx/geometry/rect.h" | 25 #include "ui/gfx/geometry/rect.h" |
| 23 | 26 |
| 24 using testing::_; | 27 using testing::_; |
| 25 | 28 |
| 26 namespace content { | 29 namespace content { |
| 27 | 30 |
| 28 namespace { | 31 namespace { |
| 29 | 32 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 histogram_tester().ExpectTotalCount("Event.Touch.TouchLatencyOutsideFling", | 362 histogram_tester().ExpectTotalCount("Event.Touch.TouchLatencyOutsideFling", |
| 360 2); | 363 2); |
| 361 | 364 |
| 362 touch.MovePoint(0, 30, 30); | 365 touch.MovePoint(0, 30, 30); |
| 363 touch.touchStartOrFirstTouchMove = false; | 366 touch.touchStartOrFirstTouchMove = false; |
| 364 widget()->SendInputEvent(touch); | 367 widget()->SendInputEvent(touch); |
| 365 histogram_tester().ExpectTotalCount("Event.Touch.TouchLatencyOutsideFling", | 368 histogram_tester().ExpectTotalCount("Event.Touch.TouchLatencyOutsideFling", |
| 366 2); | 369 2); |
| 367 } | 370 } |
| 368 | 371 |
| 372 class PopupRenderWidget : public RenderWidget { |
| 373 public: |
| 374 explicit PopupRenderWidget(CompositorDependencies* compositor_deps) |
| 375 : RenderWidget(compositor_deps, |
| 376 blink::WebPopupTypePage, |
| 377 ScreenInfo(), |
| 378 false, |
| 379 false, |
| 380 false) { |
| 381 webwidget_internal_ = &mock_webwidget_; |
| 382 // A RenderWidget is not fully initialized until it has a routing ID. |
| 383 SetRoutingID(1); |
| 384 did_show_ = true; |
| 385 } |
| 386 |
| 387 IPC::TestSink* sink() { return &sink_; } |
| 388 |
| 389 MockWebWidget* mock_webwidget() { return &mock_webwidget_; } |
| 390 |
| 391 void SetScreenMetricsEmulationParameters( |
| 392 bool, |
| 393 const blink::WebDeviceEmulationParams&) override {} |
| 394 |
| 395 protected: |
| 396 ~PopupRenderWidget() override { webwidget_internal_ = nullptr; } |
| 397 |
| 398 bool Send(IPC::Message* msg) override { |
| 399 sink_.OnMessageReceived(*msg); |
| 400 delete msg; |
| 401 return true; |
| 402 } |
| 403 |
| 404 private: |
| 405 IPC::TestSink sink_; |
| 406 MockWebWidget mock_webwidget_; |
| 407 |
| 408 DISALLOW_COPY_AND_ASSIGN(PopupRenderWidget); |
| 409 }; |
| 410 |
| 411 class RenderWidgetPopupUnittest : public testing::Test { |
| 412 public: |
| 413 RenderWidgetPopupUnittest() |
| 414 : widget_(new PopupRenderWidget(&compositor_deps_)) {} |
| 415 ~RenderWidgetPopupUnittest() override {} |
| 416 |
| 417 PopupRenderWidget* widget() const { return widget_.get(); } |
| 418 FakeCompositorDependencies compositor_deps_; |
| 419 |
| 420 private: |
| 421 MockRenderProcess render_process_; |
| 422 MockRenderThread render_thread_; |
| 423 scoped_refptr<PopupRenderWidget> widget_; |
| 424 |
| 425 DISALLOW_COPY_AND_ASSIGN(RenderWidgetPopupUnittest); |
| 426 }; |
| 427 |
| 428 TEST_F(RenderWidgetPopupUnittest, EmulatingPopupRect) { |
| 429 blink::WebRect popup_screen_rect(200, 250, 100, 400); |
| 430 widget()->setWindowRect(popup_screen_rect); |
| 431 |
| 432 // The view and window rect on a popup type RenderWidget should be |
| 433 // immediately set, without requiring an ACK. |
| 434 EXPECT_EQ(popup_screen_rect.x, widget()->windowRect().x); |
| 435 EXPECT_EQ(popup_screen_rect.y, widget()->windowRect().y); |
| 436 |
| 437 EXPECT_EQ(popup_screen_rect.x, widget()->viewRect().x); |
| 438 EXPECT_EQ(popup_screen_rect.y, widget()->viewRect().y); |
| 439 |
| 440 gfx::Rect emulated_window_rect(0, 0, 980, 1200); |
| 441 |
| 442 blink::WebDeviceEmulationParams emulation_params; |
| 443 emulation_params.screenPosition = blink::WebDeviceEmulationParams::Mobile; |
| 444 emulation_params.viewSize = emulated_window_rect.size(); |
| 445 emulation_params.viewPosition = blink::WebPoint(150, 160); |
| 446 emulation_params.fitToView = true; |
| 447 |
| 448 gfx::Rect parent_window_rect = gfx::Rect(0, 0, 800, 600); |
| 449 |
| 450 ResizeParams resize_params; |
| 451 resize_params.new_size = parent_window_rect.size(); |
| 452 |
| 453 scoped_refptr<PopupRenderWidget> parent_widget( |
| 454 new PopupRenderWidget(&compositor_deps_)); |
| 455 RenderWidgetScreenMetricsEmulator emulator( |
| 456 parent_widget.get(), emulation_params, resize_params, parent_window_rect, |
| 457 parent_window_rect); |
| 458 emulator.Apply(); |
| 459 |
| 460 widget()->SetPopupOriginAdjustmentsForEmulation(&emulator); |
| 461 |
| 462 // Emulation-applied scale factor to fit the emulated device in the window. |
| 463 float scale = |
| 464 (float)parent_window_rect.height() / emulated_window_rect.height(); |
| 465 |
| 466 // Used to center the emulated device in the window. |
| 467 gfx::Point offset( |
| 468 (parent_window_rect.width() - emulated_window_rect.width() * scale) / 2, |
| 469 (parent_window_rect.height() - emulated_window_rect.height() * scale) / |
| 470 2); |
| 471 |
| 472 // Position of the popup as seen by the emulated widget. |
| 473 gfx::Point emulated_position(emulation_params.viewPosition.x + |
| 474 (popup_screen_rect.x - offset.x()) / scale, |
| 475 emulation_params.viewPosition.y + |
| 476 (popup_screen_rect.y - offset.y()) / scale); |
| 477 |
| 478 // Both the window and view rects as read from the accessors should have the |
| 479 // emulation parameters applied. |
| 480 EXPECT_EQ(emulated_position.x(), widget()->windowRect().x); |
| 481 EXPECT_EQ(emulated_position.y(), widget()->windowRect().y); |
| 482 EXPECT_EQ(emulated_position.x(), widget()->viewRect().x); |
| 483 EXPECT_EQ(emulated_position.y(), widget()->viewRect().y); |
| 484 |
| 485 // Setting a new window rect while emulated should remove the emulation |
| 486 // transformation from the given rect so that getting the rect, which applies |
| 487 // the transformation to the raw rect, should result in the same value. |
| 488 blink::WebRect popup_emulated_rect(130, 170, 100, 400); |
| 489 widget()->setWindowRect(popup_emulated_rect); |
| 490 |
| 491 EXPECT_EQ(popup_emulated_rect.x, widget()->windowRect().x); |
| 492 EXPECT_EQ(popup_emulated_rect.y, widget()->windowRect().y); |
| 493 EXPECT_EQ(popup_emulated_rect.x, widget()->viewRect().x); |
| 494 EXPECT_EQ(popup_emulated_rect.y, widget()->viewRect().y); |
| 495 } |
| 496 |
| 369 } // namespace content | 497 } // namespace content |
| OLD | NEW |