| 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" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 public: | 46 public: |
| 47 MOCK_METHOD1(handleInputEvent, | 47 MOCK_METHOD1(handleInputEvent, |
| 48 blink::WebInputEventResult(const blink::WebInputEvent&)); | 48 blink::WebInputEventResult(const blink::WebInputEvent&)); |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 class InteractiveRenderWidget : public RenderWidget { | 53 class InteractiveRenderWidget : public RenderWidget { |
| 54 public: | 54 public: |
| 55 explicit InteractiveRenderWidget(CompositorDependencies* compositor_deps) | 55 explicit InteractiveRenderWidget(CompositorDependencies* compositor_deps) |
| 56 : RenderWidget(compositor_deps, | 56 : RenderWidget(++next_routing_id_, |
| 57 compositor_deps, |
| 57 blink::WebPopupTypeNone, | 58 blink::WebPopupTypeNone, |
| 58 ScreenInfo(), | 59 ScreenInfo(), |
| 59 false, | 60 false, |
| 60 false, | 61 false, |
| 61 false), | 62 false), |
| 62 always_overscroll_(false) { | 63 always_overscroll_(false) { |
| 63 webwidget_internal_ = &mock_webwidget_; | 64 Init(MSG_ROUTING_NONE, mock_webwidget()); |
| 64 InitRoutingID(++next_routing_id_); | |
| 65 } | 65 } |
| 66 | 66 |
| 67 void SetTouchRegion(const std::vector<gfx::Rect>& rects) { | 67 void SetTouchRegion(const std::vector<gfx::Rect>& rects) { |
| 68 rects_ = rects; | 68 rects_ = rects; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void SendInputEvent(const blink::WebInputEvent& event) { | 71 void SendInputEvent(const blink::WebInputEvent& event) { |
| 72 OnHandleInputEvent( | 72 OnHandleInputEvent( |
| 73 &event, ui::LatencyInfo(), | 73 &event, ui::LatencyInfo(), |
| 74 ui::WebInputEventTraits::ShouldBlockEventStream(event) | 74 ui::WebInputEventTraits::ShouldBlockEventStream(event) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 static int next_routing_id_; | 127 static int next_routing_id_; |
| 128 | 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(InteractiveRenderWidget); | 129 DISALLOW_COPY_AND_ASSIGN(InteractiveRenderWidget); |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 int InteractiveRenderWidget::next_routing_id_ = 0; | 132 int InteractiveRenderWidget::next_routing_id_ = 0; |
| 133 | 133 |
| 134 class RenderWidgetUnittest : public testing::Test { | 134 class RenderWidgetUnittest : public testing::Test { |
| 135 public: | 135 public: |
| 136 RenderWidgetUnittest() | 136 RenderWidgetUnittest() |
| 137 : widget_(new InteractiveRenderWidget(&compositor_deps_)) {} | 137 : widget_(new InteractiveRenderWidget(&compositor_deps_)) { |
| 138 // RenderWidget::Init does an AddRef that's balanced by a browser-initiated |
| 139 // Close IPC. That Close will never happen in this test, so do a Release |
| 140 // here to ensure |widget_| is properly freed. |
| 141 widget_->Release(); |
| 142 DCHECK(widget_->HasOneRef()); |
| 143 } |
| 138 ~RenderWidgetUnittest() override {} | 144 ~RenderWidgetUnittest() override {} |
| 139 | 145 |
| 140 InteractiveRenderWidget* widget() const { return widget_.get(); } | 146 InteractiveRenderWidget* widget() const { return widget_.get(); } |
| 141 | 147 |
| 142 const base::HistogramTester& histogram_tester() const { | 148 const base::HistogramTester& histogram_tester() const { |
| 143 return histogram_tester_; | 149 return histogram_tester_; |
| 144 } | 150 } |
| 145 | 151 |
| 146 private: | 152 private: |
| 147 MockRenderProcess render_process_; | 153 MockRenderProcess render_process_; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 touch.MovePoint(0, 30, 30); | 369 touch.MovePoint(0, 30, 30); |
| 364 touch.touchStartOrFirstTouchMove = false; | 370 touch.touchStartOrFirstTouchMove = false; |
| 365 widget()->SendInputEvent(touch); | 371 widget()->SendInputEvent(touch); |
| 366 histogram_tester().ExpectTotalCount("Event.Touch.TouchLatencyOutsideFling", | 372 histogram_tester().ExpectTotalCount("Event.Touch.TouchLatencyOutsideFling", |
| 367 2); | 373 2); |
| 368 } | 374 } |
| 369 | 375 |
| 370 class PopupRenderWidget : public RenderWidget { | 376 class PopupRenderWidget : public RenderWidget { |
| 371 public: | 377 public: |
| 372 explicit PopupRenderWidget(CompositorDependencies* compositor_deps) | 378 explicit PopupRenderWidget(CompositorDependencies* compositor_deps) |
| 373 : RenderWidget(compositor_deps, | 379 : RenderWidget(1, |
| 380 compositor_deps, |
| 374 blink::WebPopupTypePage, | 381 blink::WebPopupTypePage, |
| 375 ScreenInfo(), | 382 ScreenInfo(), |
| 376 false, | 383 false, |
| 377 false, | 384 false, |
| 378 false) { | 385 false) { |
| 379 webwidget_internal_ = &mock_webwidget_; | 386 Init(MSG_ROUTING_NONE, mock_webwidget()); |
| 380 InitRoutingID(1); | |
| 381 did_show_ = true; | 387 did_show_ = true; |
| 382 } | 388 } |
| 383 | 389 |
| 384 IPC::TestSink* sink() { return &sink_; } | 390 IPC::TestSink* sink() { return &sink_; } |
| 385 | 391 |
| 386 MockWebWidget* mock_webwidget() { return &mock_webwidget_; } | 392 MockWebWidget* mock_webwidget() { return &mock_webwidget_; } |
| 387 | 393 |
| 388 void SetScreenMetricsEmulationParameters( | 394 void SetScreenMetricsEmulationParameters( |
| 389 bool, | 395 bool, |
| 390 const blink::WebDeviceEmulationParams&) override {} | 396 const blink::WebDeviceEmulationParams&) override {} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 401 private: | 407 private: |
| 402 IPC::TestSink sink_; | 408 IPC::TestSink sink_; |
| 403 MockWebWidget mock_webwidget_; | 409 MockWebWidget mock_webwidget_; |
| 404 | 410 |
| 405 DISALLOW_COPY_AND_ASSIGN(PopupRenderWidget); | 411 DISALLOW_COPY_AND_ASSIGN(PopupRenderWidget); |
| 406 }; | 412 }; |
| 407 | 413 |
| 408 class RenderWidgetPopupUnittest : public testing::Test { | 414 class RenderWidgetPopupUnittest : public testing::Test { |
| 409 public: | 415 public: |
| 410 RenderWidgetPopupUnittest() | 416 RenderWidgetPopupUnittest() |
| 411 : widget_(new PopupRenderWidget(&compositor_deps_)) {} | 417 : widget_(new PopupRenderWidget(&compositor_deps_)) { |
| 418 // RenderWidget::Init does an AddRef that's balanced by a browser-initiated |
| 419 // Close IPC. That Close will never happen in this test, so do a Release |
| 420 // here to ensure |widget_| is properly freed. |
| 421 widget_->Release(); |
| 422 DCHECK(widget_->HasOneRef()); |
| 423 } |
| 412 ~RenderWidgetPopupUnittest() override {} | 424 ~RenderWidgetPopupUnittest() override {} |
| 413 | 425 |
| 414 PopupRenderWidget* widget() const { return widget_.get(); } | 426 PopupRenderWidget* widget() const { return widget_.get(); } |
| 415 FakeCompositorDependencies compositor_deps_; | 427 FakeCompositorDependencies compositor_deps_; |
| 416 | 428 |
| 417 private: | 429 private: |
| 418 MockRenderProcess render_process_; | 430 MockRenderProcess render_process_; |
| 419 MockRenderThread render_thread_; | 431 MockRenderThread render_thread_; |
| 420 scoped_refptr<PopupRenderWidget> widget_; | 432 scoped_refptr<PopupRenderWidget> widget_; |
| 421 | 433 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 442 emulation_params.viewPosition = blink::WebPoint(150, 160); | 454 emulation_params.viewPosition = blink::WebPoint(150, 160); |
| 443 emulation_params.fitToView = true; | 455 emulation_params.fitToView = true; |
| 444 | 456 |
| 445 gfx::Rect parent_window_rect = gfx::Rect(0, 0, 800, 600); | 457 gfx::Rect parent_window_rect = gfx::Rect(0, 0, 800, 600); |
| 446 | 458 |
| 447 ResizeParams resize_params; | 459 ResizeParams resize_params; |
| 448 resize_params.new_size = parent_window_rect.size(); | 460 resize_params.new_size = parent_window_rect.size(); |
| 449 | 461 |
| 450 scoped_refptr<PopupRenderWidget> parent_widget( | 462 scoped_refptr<PopupRenderWidget> parent_widget( |
| 451 new PopupRenderWidget(&compositor_deps_)); | 463 new PopupRenderWidget(&compositor_deps_)); |
| 464 parent_widget->Release(); // Balance Init(). |
| 452 RenderWidgetScreenMetricsEmulator emulator( | 465 RenderWidgetScreenMetricsEmulator emulator( |
| 453 parent_widget.get(), emulation_params, resize_params, parent_window_rect, | 466 parent_widget.get(), emulation_params, resize_params, parent_window_rect, |
| 454 parent_window_rect); | 467 parent_window_rect); |
| 455 emulator.Apply(); | 468 emulator.Apply(); |
| 456 | 469 |
| 457 widget()->SetPopupOriginAdjustmentsForEmulation(&emulator); | 470 widget()->SetPopupOriginAdjustmentsForEmulation(&emulator); |
| 458 | 471 |
| 459 // Emulation-applied scale factor to fit the emulated device in the window. | 472 // Emulation-applied scale factor to fit the emulated device in the window. |
| 460 float scale = | 473 float scale = |
| 461 (float)parent_window_rect.height() / emulated_window_rect.height(); | 474 (float)parent_window_rect.height() / emulated_window_rect.height(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 485 blink::WebRect popup_emulated_rect(130, 170, 100, 400); | 498 blink::WebRect popup_emulated_rect(130, 170, 100, 400); |
| 486 widget()->setWindowRect(popup_emulated_rect); | 499 widget()->setWindowRect(popup_emulated_rect); |
| 487 | 500 |
| 488 EXPECT_EQ(popup_emulated_rect.x, widget()->windowRect().x); | 501 EXPECT_EQ(popup_emulated_rect.x, widget()->windowRect().x); |
| 489 EXPECT_EQ(popup_emulated_rect.y, widget()->windowRect().y); | 502 EXPECT_EQ(popup_emulated_rect.y, widget()->windowRect().y); |
| 490 EXPECT_EQ(popup_emulated_rect.x, widget()->viewRect().x); | 503 EXPECT_EQ(popup_emulated_rect.x, widget()->viewRect().x); |
| 491 EXPECT_EQ(popup_emulated_rect.y, widget()->viewRect().y); | 504 EXPECT_EQ(popup_emulated_rect.y, widget()->viewRect().y); |
| 492 } | 505 } |
| 493 | 506 |
| 494 } // namespace content | 507 } // namespace content |
| OLD | NEW |