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

Side by Side Diff: content/browser/renderer_host/render_widget_host_unittest.cc

Issue 2122023002: Cross-process frames should be notified of device scale factor changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix RenderWidgetHostTest.ResizeScreenInfo. Created 4 years, 4 months 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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <tuple> 9 #include <tuple>
10 10
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 int gesture_event_type() const { return gesture_event_type_; } 269 int gesture_event_type() const { return gesture_event_type_; }
270 InputEventAckState ack_result() const { return ack_result_; } 270 InputEventAckState ack_result() const { return ack_result_; }
271 271
272 void SetMockPhysicalBackingSize(const gfx::Size& mock_physical_backing_size) { 272 void SetMockPhysicalBackingSize(const gfx::Size& mock_physical_backing_size) {
273 use_fake_physical_backing_size_ = true; 273 use_fake_physical_backing_size_ = true;
274 mock_physical_backing_size_ = mock_physical_backing_size; 274 mock_physical_backing_size_ = mock_physical_backing_size;
275 } 275 }
276 void ClearMockPhysicalBackingSize() { 276 void ClearMockPhysicalBackingSize() {
277 use_fake_physical_backing_size_ = false; 277 use_fake_physical_backing_size_ = false;
278 } 278 }
279 void SetScreenInfo(const blink::WebScreenInfo& screen_info) {
280 screen_info_ = screen_info;
281 }
282 279
283 // RenderWidgetHostView override. 280 // RenderWidgetHostView override.
284 gfx::Rect GetViewBounds() const override { return bounds_; } 281 gfx::Rect GetViewBounds() const override { return bounds_; }
285 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch, 282 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch,
286 InputEventAckState ack_result) override { 283 InputEventAckState ack_result) override {
287 acked_event_ = touch.event; 284 acked_event_ = touch.event;
288 ++acked_event_count_; 285 ++acked_event_count_;
289 } 286 }
290 void WheelEventAck(const WebMouseWheelEvent& event, 287 void WheelEventAck(const WebMouseWheelEvent& event,
291 InputEventAckState ack_result) override { 288 InputEventAckState ack_result) override {
292 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) 289 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED)
293 return; 290 return;
294 unhandled_wheel_event_count_++; 291 unhandled_wheel_event_count_++;
295 unhandled_wheel_event_ = event; 292 unhandled_wheel_event_ = event;
296 } 293 }
297 void GestureEventAck(const WebGestureEvent& event, 294 void GestureEventAck(const WebGestureEvent& event,
298 InputEventAckState ack_result) override { 295 InputEventAckState ack_result) override {
299 gesture_event_type_ = event.type; 296 gesture_event_type_ = event.type;
300 ack_result_ = ack_result; 297 ack_result_ = ack_result;
301 } 298 }
302 gfx::Size GetPhysicalBackingSize() const override { 299 gfx::Size GetPhysicalBackingSize() const override {
303 if (use_fake_physical_backing_size_) 300 if (use_fake_physical_backing_size_)
304 return mock_physical_backing_size_; 301 return mock_physical_backing_size_;
305 return TestRenderWidgetHostView::GetPhysicalBackingSize(); 302 return TestRenderWidgetHostView::GetPhysicalBackingSize();
306 } 303 }
307 void GetScreenInfo(blink::WebScreenInfo* screen_info) override {
308 *screen_info = screen_info_;
309 }
310 #if defined(USE_AURA) 304 #if defined(USE_AURA)
311 ~TestView() override { 305 ~TestView() override {
312 // Simulate the mouse exit event dispatched when an aura window is 306 // Simulate the mouse exit event dispatched when an aura window is
313 // destroyed. (MakeWebMouseEventFromAuraEvent translates ET_MOUSE_EXITED 307 // destroyed. (MakeWebMouseEventFromAuraEvent translates ET_MOUSE_EXITED
314 // into WebInputEvent::MouseMove.) 308 // into WebInputEvent::MouseMove.)
315 WebMouseEvent event = 309 WebMouseEvent event =
316 SyntheticWebMouseEventBuilder::Build(WebInputEvent::MouseMove); 310 SyntheticWebMouseEventBuilder::Build(WebInputEvent::MouseMove);
317 event.timeStampSeconds = 311 event.timeStampSeconds =
318 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); 312 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
319 rwh_->input_router()->SendMouseEvent( 313 rwh_->input_router()->SendMouseEvent(
320 MouseEventWithLatencyInfo(event, ui::LatencyInfo())); 314 MouseEventWithLatencyInfo(event, ui::LatencyInfo()));
321 } 315 }
322 #endif 316 #endif
323 317
324 protected: 318 protected:
325 WebMouseWheelEvent unhandled_wheel_event_; 319 WebMouseWheelEvent unhandled_wheel_event_;
326 int unhandled_wheel_event_count_; 320 int unhandled_wheel_event_count_;
327 WebTouchEvent acked_event_; 321 WebTouchEvent acked_event_;
328 int acked_event_count_; 322 int acked_event_count_;
329 int gesture_event_type_; 323 int gesture_event_type_;
330 gfx::Rect bounds_; 324 gfx::Rect bounds_;
331 bool use_fake_physical_backing_size_; 325 bool use_fake_physical_backing_size_;
332 gfx::Size mock_physical_backing_size_; 326 gfx::Size mock_physical_backing_size_;
333 InputEventAckState ack_result_; 327 InputEventAckState ack_result_;
334 blink::WebScreenInfo screen_info_;
335 328
336 private: 329 private:
337 DISALLOW_COPY_AND_ASSIGN(TestView); 330 DISALLOW_COPY_AND_ASSIGN(TestView);
338 }; 331 };
339 332
340 // MockRenderWidgetHostDelegate -------------------------------------------- 333 // MockRenderWidgetHostDelegate --------------------------------------------
341 334
342 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { 335 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate {
343 public: 336 public:
344 MockRenderWidgetHostDelegate() 337 MockRenderWidgetHostDelegate()
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 373 }
381 374
382 void set_prehandle_keyboard_event_is_shortcut(bool is_shortcut) { 375 void set_prehandle_keyboard_event_is_shortcut(bool is_shortcut) {
383 prehandle_keyboard_event_is_shortcut_ = is_shortcut; 376 prehandle_keyboard_event_is_shortcut_ = is_shortcut;
384 } 377 }
385 378
386 bool handle_wheel_event_called() const { return handle_wheel_event_called_; } 379 bool handle_wheel_event_called() const { return handle_wheel_event_called_; }
387 380
388 bool unresponsive_timer_fired() const { return unresponsive_timer_fired_; } 381 bool unresponsive_timer_fired() const { return unresponsive_timer_fired_; }
389 382
383 void SetScreenInfo(const blink::WebScreenInfo& screen_info) {
384 screen_info_ = screen_info;
385 }
386
387 // RenderWidgetHostDelegate overrides.
388 void GetScreenInfo(blink::WebScreenInfo* web_screen_info) override {
389 *web_screen_info = screen_info_;
390 }
391
390 protected: 392 protected:
391 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 393 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
392 bool* is_keyboard_shortcut) override { 394 bool* is_keyboard_shortcut) override {
393 prehandle_keyboard_event_type_ = event.type; 395 prehandle_keyboard_event_type_ = event.type;
394 prehandle_keyboard_event_called_ = true; 396 prehandle_keyboard_event_called_ = true;
395 *is_keyboard_shortcut = prehandle_keyboard_event_is_shortcut_; 397 *is_keyboard_shortcut = prehandle_keyboard_event_is_shortcut_;
396 return prehandle_keyboard_event_; 398 return prehandle_keyboard_event_;
397 } 399 }
398 400
399 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) override { 401 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) override {
(...skipping 22 matching lines...) Expand all
422 bool prehandle_keyboard_event_called_; 424 bool prehandle_keyboard_event_called_;
423 WebInputEvent::Type prehandle_keyboard_event_type_; 425 WebInputEvent::Type prehandle_keyboard_event_type_;
424 426
425 bool unhandled_keyboard_event_called_; 427 bool unhandled_keyboard_event_called_;
426 WebInputEvent::Type unhandled_keyboard_event_type_; 428 WebInputEvent::Type unhandled_keyboard_event_type_;
427 429
428 bool handle_wheel_event_; 430 bool handle_wheel_event_;
429 bool handle_wheel_event_called_; 431 bool handle_wheel_event_called_;
430 432
431 bool unresponsive_timer_fired_; 433 bool unresponsive_timer_fired_;
434
435 blink::WebScreenInfo screen_info_;
432 }; 436 };
433 437
434 // RenderWidgetHostTest -------------------------------------------------------- 438 // RenderWidgetHostTest --------------------------------------------------------
435 439
436 class RenderWidgetHostTest : public testing::Test { 440 class RenderWidgetHostTest : public testing::Test {
437 public: 441 public:
438 RenderWidgetHostTest() 442 RenderWidgetHostTest()
439 : process_(NULL), 443 : process_(NULL),
440 handle_key_press_event_(false), 444 handle_key_press_event_(false),
441 handle_mouse_event_(false), 445 handle_mouse_event_(false),
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 // Test that a resize event is sent if WasResized() is called after a 781 // Test that a resize event is sent if WasResized() is called after a
778 // WebScreenInfo change. 782 // WebScreenInfo change.
779 TEST_F(RenderWidgetHostTest, ResizeScreenInfo) { 783 TEST_F(RenderWidgetHostTest, ResizeScreenInfo) {
780 blink::WebScreenInfo screen_info; 784 blink::WebScreenInfo screen_info;
781 screen_info.deviceScaleFactor = 1.f; 785 screen_info.deviceScaleFactor = 1.f;
782 screen_info.rect = blink::WebRect(0, 0, 800, 600); 786 screen_info.rect = blink::WebRect(0, 0, 800, 600);
783 screen_info.availableRect = blink::WebRect(0, 0, 800, 600); 787 screen_info.availableRect = blink::WebRect(0, 0, 800, 600);
784 screen_info.orientationAngle = 0; 788 screen_info.orientationAngle = 0;
785 screen_info.orientationType = blink::WebScreenOrientationPortraitPrimary; 789 screen_info.orientationType = blink::WebScreenOrientationPortraitPrimary;
786 790
787 view_->SetScreenInfo(screen_info); 791 auto host_delegate =
792 static_cast<MockRenderWidgetHostDelegate*>(host_->delegate());
793
794 host_delegate->SetScreenInfo(screen_info);
788 host_->WasResized(); 795 host_->WasResized();
789 EXPECT_FALSE(host_->resize_ack_pending_); 796 EXPECT_FALSE(host_->resize_ack_pending_);
790 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 797 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
791 process_->sink().ClearMessages(); 798 process_->sink().ClearMessages();
792 799
793 screen_info.orientationAngle = 180; 800 screen_info.orientationAngle = 180;
794 screen_info.orientationType = blink::WebScreenOrientationLandscapePrimary; 801 screen_info.orientationType = blink::WebScreenOrientationLandscapePrimary;
795 802
796 view_->SetScreenInfo(screen_info); 803 host_delegate->SetScreenInfo(screen_info);
797 host_->WasResized(); 804 host_->WasResized();
798 EXPECT_FALSE(host_->resize_ack_pending_); 805 EXPECT_FALSE(host_->resize_ack_pending_);
799 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 806 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
800 process_->sink().ClearMessages(); 807 process_->sink().ClearMessages();
801 808
802 screen_info.deviceScaleFactor = 2.f; 809 screen_info.deviceScaleFactor = 2.f;
803 810
804 view_->SetScreenInfo(screen_info); 811 host_delegate->SetScreenInfo(screen_info);
805 host_->WasResized(); 812 host_->WasResized();
806 EXPECT_FALSE(host_->resize_ack_pending_); 813 EXPECT_FALSE(host_->resize_ack_pending_);
807 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 814 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
808 process_->sink().ClearMessages(); 815 process_->sink().ClearMessages();
809 816
810 // No screen change. 817 // No screen change.
811 view_->SetScreenInfo(screen_info); 818 host_delegate->SetScreenInfo(screen_info);
812 host_->WasResized(); 819 host_->WasResized();
813 EXPECT_FALSE(host_->resize_ack_pending_); 820 EXPECT_FALSE(host_->resize_ack_pending_);
814 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 821 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
815 } 822 }
816 823
817 // Test for crbug.com/25097. If a renderer crashes between a resize and the 824 // Test for crbug.com/25097. If a renderer crashes between a resize and the
818 // corresponding update message, we must be sure to clear the resize ack logic. 825 // corresponding update message, we must be sure to clear the resize ack logic.
819 TEST_F(RenderWidgetHostTest, ResizeThenCrash) { 826 TEST_F(RenderWidgetHostTest, ResizeThenCrash) {
820 // Clear the first Resize message that carried screen info. 827 // Clear the first Resize message that carried screen info.
821 process_->sink().ClearMessages(); 828 process_->sink().ClearMessages();
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 ui::LatencyInfo()); 1695 ui::LatencyInfo());
1689 1696
1690 1697
1691 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). 1698 // Tests RWHI::ForwardWheelEventWithLatencyInfo().
1692 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); 1699 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo());
1693 1700
1694 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); 1701 ASSERT_FALSE(host_->input_router()->HasPendingEvents());
1695 } 1702 }
1696 1703
1697 } // namespace content 1704 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698