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

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

Powered by Google App Engine
This is Rietveld 408576698