| 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" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 // MockPaintingObserver -------------------------------------------------------- | 199 // MockPaintingObserver -------------------------------------------------------- |
| 200 | 200 |
| 201 class MockPaintingObserver : public RenderWidgetHostPaintingObserver { | 201 class MockPaintingObserver : public RenderWidgetHostPaintingObserver { |
| 202 public: | 202 public: |
| 203 void WidgetWillDestroyBackingStore(RenderWidgetHost* widget, | 203 void WidgetWillDestroyBackingStore(RenderWidgetHost* widget, |
| 204 BackingStore* backing_store) {} | 204 BackingStore* backing_store) {} |
| 205 void WidgetDidUpdateBackingStore(RenderWidgetHost* widget) {} | 205 void WidgetDidUpdateBackingStore(RenderWidgetHost* widget) {} |
| 206 void WidgetDidReceivePaintAtSizeAck(RenderWidgetHost* host, | 206 void WidgetDidReceivePaintAtSizeAck(RenderWidgetHost* host, |
| 207 const TransportDIB::Handle& dib_handle, | 207 int tag, |
| 208 const gfx::Size& size) { | 208 const gfx::Size& size) { |
| 209 host_ = reinterpret_cast<MockRenderWidgetHost*>(host); | 209 host_ = reinterpret_cast<MockRenderWidgetHost*>(host); |
| 210 dib_handle_ = dib_handle; | 210 tag_ = tag; |
| 211 size_ = size; | 211 size_ = size; |
| 212 } | 212 } |
| 213 | 213 |
| 214 MockRenderWidgetHost* host() const { return host_; } | 214 MockRenderWidgetHost* host() const { return host_; } |
| 215 TransportDIB::Handle dib_handle() const { return dib_handle_; } | 215 int tag() const { return tag_; } |
| 216 gfx::Size size() const { return size_; } | 216 gfx::Size size() const { return size_; } |
| 217 | 217 |
| 218 private: | 218 private: |
| 219 MockRenderWidgetHost* host_; | 219 MockRenderWidgetHost* host_; |
| 220 TransportDIB::Handle dib_handle_; | 220 int tag_; |
| 221 gfx::Size size_; | 221 gfx::Size size_; |
| 222 }; | 222 }; |
| 223 | 223 |
| 224 | 224 |
| 225 // RenderWidgetHostTest -------------------------------------------------------- | 225 // RenderWidgetHostTest -------------------------------------------------------- |
| 226 | 226 |
| 227 class RenderWidgetHostTest : public testing::Test { | 227 class RenderWidgetHostTest : public testing::Test { |
| 228 public: | 228 public: |
| 229 RenderWidgetHostTest() : process_(NULL) { | 229 RenderWidgetHostTest() : process_(NULL) { |
| 230 } | 230 } |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 // 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. |
| 530 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching( | 530 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching( |
| 531 ViewMsg_WasRestored::ID); | 531 ViewMsg_WasRestored::ID); |
| 532 ASSERT_TRUE(restored); | 532 ASSERT_TRUE(restored); |
| 533 Tuple1<bool> needs_repaint; | 533 Tuple1<bool> needs_repaint; |
| 534 ViewMsg_WasRestored::Read(restored, &needs_repaint); | 534 ViewMsg_WasRestored::Read(restored, &needs_repaint); |
| 535 EXPECT_TRUE(needs_repaint.a); | 535 EXPECT_TRUE(needs_repaint.a); |
| 536 } | 536 } |
| 537 | 537 |
| 538 TEST_F(RenderWidgetHostTest, PaintAtSize) { | 538 TEST_F(RenderWidgetHostTest, PaintAtSize) { |
| 539 host_->PaintAtSize(TransportDIB::GetFakeHandleForTest(), gfx::Size(40, 60), | 539 const int kPaintAtSizeTag = 42; |
| 540 gfx::Size(20, 30)); | 540 host_->PaintAtSize(TransportDIB::GetFakeHandleForTest(), kPaintAtSizeTag, |
| 541 gfx::Size(40, 60), gfx::Size(20, 30)); |
| 541 EXPECT_TRUE( | 542 EXPECT_TRUE( |
| 542 process_->sink().GetUniqueMessageMatching(ViewMsg_PaintAtSize::ID)); | 543 process_->sink().GetUniqueMessageMatching(ViewMsg_PaintAtSize::ID)); |
| 543 | 544 |
| 544 MockPaintingObserver observer; | 545 MockPaintingObserver observer; |
| 545 host_->set_painting_observer(&observer); | 546 host_->set_painting_observer(&observer); |
| 546 | 547 |
| 547 // Need to generate a fake handle value on all platforms. | 548 host_->OnMsgPaintAtSizeAck(kPaintAtSizeTag, gfx::Size(20, 30)); |
| 548 TransportDIB::Handle handle = TransportDIB::GetFakeHandleForTest(); | 549 EXPECT_EQ(host_.get(), observer.host()); |
| 549 host_->OnMsgPaintAtSizeAck(handle, gfx::Size(20, 30)); | 550 EXPECT_EQ(kPaintAtSizeTag, observer.tag()); |
| 550 EXPECT_TRUE(host_ == observer.host()); | |
| 551 EXPECT_TRUE(handle == observer.dib_handle()); | |
| 552 EXPECT_EQ(20, observer.size().width()); | 551 EXPECT_EQ(20, observer.size().width()); |
| 553 EXPECT_EQ(30, observer.size().height()); | 552 EXPECT_EQ(30, observer.size().height()); |
| 554 host_->set_painting_observer(NULL); | 553 host_->set_painting_observer(NULL); |
| 555 } | 554 } |
| 556 | 555 |
| 557 TEST_F(RenderWidgetHostTest, HandleKeyEventsWeSent) { | 556 TEST_F(RenderWidgetHostTest, HandleKeyEventsWeSent) { |
| 558 // Simulate a keyboard event. | 557 // Simulate a keyboard event. |
| 559 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 558 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
| 560 | 559 |
| 561 // Make sure we sent the input event to the renderer. | 560 // Make sure we sent the input event to the renderer. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 // Start it again to ensure it still works. | 697 // Start it again to ensure it still works. |
| 699 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 698 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 700 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 699 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
| 701 | 700 |
| 702 // Wait long enough for first timeout and see if it fired. | 701 // Wait long enough for first timeout and see if it fired. |
| 703 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 702 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 704 new MessageLoop::QuitTask(), 10); | 703 new MessageLoop::QuitTask(), 10); |
| 705 MessageLoop::current()->Run(); | 704 MessageLoop::current()->Run(); |
| 706 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 705 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 707 } | 706 } |
| OLD | NEW |