OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/keyboard_codes.h" | 6 #include "base/keyboard_codes.h" |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/shared_memory.h" | 8 #include "base/shared_memory.h" |
9 #include "base/timer.h" | 9 #include "base/timer.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/renderer_host/backing_store.h" | 11 #include "chrome/browser/renderer_host/backing_store.h" |
| 12 #include "chrome/browser/renderer_host/render_widget_host_painting_observer.h" |
12 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 13 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
13 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
14 #include "gfx/canvas.h" | 15 #include "gfx/canvas.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 using base::TimeDelta; | 18 using base::TimeDelta; |
18 | 19 |
19 using WebKit::WebInputEvent; | 20 using WebKit::WebInputEvent; |
20 using WebKit::WebMouseWheelEvent; | 21 using WebKit::WebMouseWheelEvent; |
21 | 22 |
| 23 namespace gfx { |
| 24 class Size; |
| 25 } |
| 26 |
22 // RenderWidgetHostProcess ----------------------------------------------------- | 27 // RenderWidgetHostProcess ----------------------------------------------------- |
23 | 28 |
24 class RenderWidgetHostProcess : public MockRenderProcessHost { | 29 class RenderWidgetHostProcess : public MockRenderProcessHost { |
25 public: | 30 public: |
26 explicit RenderWidgetHostProcess(Profile* profile) | 31 explicit RenderWidgetHostProcess(Profile* profile) |
27 : MockRenderProcessHost(profile), | 32 : MockRenderProcessHost(profile), |
28 current_update_buf_(NULL), | 33 current_update_buf_(NULL), |
29 update_msg_should_reply_(false), | 34 update_msg_should_reply_(false), |
30 update_msg_reply_flags_(0) { | 35 update_msg_reply_flags_(0) { |
31 // DANGER! This is a hack. The RenderWidgetHost checks the channel to see | 36 // DANGER! This is a hack. The RenderWidgetHost checks the channel to see |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 bool prehandle_keyboard_event_; | 189 bool prehandle_keyboard_event_; |
185 bool prehandle_keyboard_event_called_; | 190 bool prehandle_keyboard_event_called_; |
186 WebInputEvent::Type prehandle_keyboard_event_type_; | 191 WebInputEvent::Type prehandle_keyboard_event_type_; |
187 | 192 |
188 bool unhandled_keyboard_event_called_; | 193 bool unhandled_keyboard_event_called_; |
189 WebInputEvent::Type unhandled_keyboard_event_type_; | 194 WebInputEvent::Type unhandled_keyboard_event_type_; |
190 | 195 |
191 bool unresponsive_timer_fired_; | 196 bool unresponsive_timer_fired_; |
192 }; | 197 }; |
193 | 198 |
| 199 // MockPaintingObserver -------------------------------------------------------- |
| 200 |
| 201 class MockPaintingObserver : public RenderWidgetHostPaintingObserver { |
| 202 public: |
| 203 void WidgetWillDestroyBackingStore(RenderWidgetHost* widget, |
| 204 BackingStore* backing_store) {} |
| 205 void WidgetDidUpdateBackingStore(RenderWidgetHost* widget) {} |
| 206 void WidgetDidReceivePaintAtSizeAck(RenderWidgetHost* host, |
| 207 const TransportDIB::Handle& dib_handle, |
| 208 const gfx::Size& size) { |
| 209 host_ = reinterpret_cast<MockRenderWidgetHost*>(host); |
| 210 dib_handle_ = dib_handle; |
| 211 size_ = size; |
| 212 } |
| 213 |
| 214 MockRenderWidgetHost* host() const { return host_; } |
| 215 TransportDIB::Handle dib_handle() const { return dib_handle_; } |
| 216 gfx::Size size() const { return size_; } |
| 217 |
| 218 private: |
| 219 MockRenderWidgetHost* host_; |
| 220 TransportDIB::Handle dib_handle_; |
| 221 gfx::Size size_; |
| 222 }; |
| 223 |
| 224 |
194 // RenderWidgetHostTest -------------------------------------------------------- | 225 // RenderWidgetHostTest -------------------------------------------------------- |
195 | 226 |
196 class RenderWidgetHostTest : public testing::Test { | 227 class RenderWidgetHostTest : public testing::Test { |
197 public: | 228 public: |
198 RenderWidgetHostTest() : process_(NULL) { | 229 RenderWidgetHostTest() : process_(NULL) { |
199 } | 230 } |
200 ~RenderWidgetHostTest() { | 231 ~RenderWidgetHostTest() { |
201 } | 232 } |
202 | 233 |
203 protected: | 234 protected: |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 | 528 |
498 // It should have sent out a restored message with a request to paint. | 529 // It should have sent out a restored message with a request to paint. |
499 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching( | 530 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching( |
500 ViewMsg_WasRestored::ID); | 531 ViewMsg_WasRestored::ID); |
501 ASSERT_TRUE(restored); | 532 ASSERT_TRUE(restored); |
502 Tuple1<bool> needs_repaint; | 533 Tuple1<bool> needs_repaint; |
503 ViewMsg_WasRestored::Read(restored, &needs_repaint); | 534 ViewMsg_WasRestored::Read(restored, &needs_repaint); |
504 EXPECT_TRUE(needs_repaint.a); | 535 EXPECT_TRUE(needs_repaint.a); |
505 } | 536 } |
506 | 537 |
| 538 TEST_F(RenderWidgetHostTest, PaintAtSize) { |
| 539 host_->PaintAtSize(TransportDIB::GetFakeHandleForTest(), gfx::Size(20, 30)); |
| 540 EXPECT_TRUE( |
| 541 process_->sink().GetUniqueMessageMatching(ViewMsg_PaintAtSize::ID)); |
| 542 |
| 543 MockPaintingObserver observer; |
| 544 host_->set_painting_observer(&observer); |
| 545 |
| 546 // Need to generate a fake handle value on all platforms. |
| 547 TransportDIB::Handle handle = TransportDIB::GetFakeHandleForTest(); |
| 548 host_->OnMsgPaintAtSizeAck(handle, gfx::Size(20, 30)); |
| 549 EXPECT_TRUE(host_ == observer.host()); |
| 550 EXPECT_TRUE(handle == observer.dib_handle()); |
| 551 EXPECT_EQ(20, observer.size().width()); |
| 552 EXPECT_EQ(30, observer.size().height()); |
| 553 host_->set_painting_observer(NULL); |
| 554 } |
| 555 |
507 TEST_F(RenderWidgetHostTest, HandleKeyEventsWeSent) { | 556 TEST_F(RenderWidgetHostTest, HandleKeyEventsWeSent) { |
508 // Simulate a keyboard event. | 557 // Simulate a keyboard event. |
509 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 558 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
510 | 559 |
511 // Make sure we sent the input event to the renderer. | 560 // Make sure we sent the input event to the renderer. |
512 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 561 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
513 ViewMsg_HandleInputEvent::ID)); | 562 ViewMsg_HandleInputEvent::ID)); |
514 process_->sink().ClearMessages(); | 563 process_->sink().ClearMessages(); |
515 | 564 |
516 // Send the simulated response from the renderer back. | 565 // Send the simulated response from the renderer back. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 // Start it again to ensure it still works. | 691 // Start it again to ensure it still works. |
643 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 692 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
644 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 693 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
645 | 694 |
646 // Wait long enough for first timeout and see if it fired. | 695 // Wait long enough for first timeout and see if it fired. |
647 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 696 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
648 new MessageLoop::QuitTask(), 10); | 697 new MessageLoop::QuitTask(), 10); |
649 MessageLoop::current()->Run(); | 698 MessageLoop::current()->Run(); |
650 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 699 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
651 } | 700 } |
652 | |
OLD | NEW |