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

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

Issue 6010004: Refactor RenderWidgetHost::set_paint_observer() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove helper classes per review Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
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 "app/keyboard_codes.h" 5 #include "app/keyboard_codes.h"
6 #include "base/basictypes.h" 6 #include "base/basictypes.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"
13 #include "chrome/browser/renderer_host/test/test_render_view_host.h" 12 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
13 #include "chrome/common/notification_details.h"
14 #include "chrome/common/notification_source.h"
14 #include "chrome/common/render_messages.h" 15 #include "chrome/common/render_messages.h"
15 #include "chrome/common/render_messages_params.h" 16 #include "chrome/common/render_messages_params.h"
16 #include "chrome/test/testing_profile.h" 17 #include "chrome/test/testing_profile.h"
17 #include "gfx/canvas_skia.h" 18 #include "gfx/canvas_skia.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 using base::TimeDelta; 21 using base::TimeDelta;
21 22
22 using WebKit::WebInputEvent; 23 using WebKit::WebInputEvent;
23 using WebKit::WebMouseWheelEvent; 24 using WebKit::WebMouseWheelEvent;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 WebInputEvent::Type prehandle_keyboard_event_type_; 194 WebInputEvent::Type prehandle_keyboard_event_type_;
194 195
195 bool unhandled_keyboard_event_called_; 196 bool unhandled_keyboard_event_called_;
196 WebInputEvent::Type unhandled_keyboard_event_type_; 197 WebInputEvent::Type unhandled_keyboard_event_type_;
197 198
198 bool unresponsive_timer_fired_; 199 bool unresponsive_timer_fired_;
199 }; 200 };
200 201
201 // MockPaintingObserver -------------------------------------------------------- 202 // MockPaintingObserver --------------------------------------------------------
202 203
203 class MockPaintingObserver : public RenderWidgetHostPaintingObserver { 204 class MockPaintingObserver : public NotificationObserver {
204 public: 205 public:
205 void WidgetWillDestroyBackingStore(RenderWidgetHost* widget,
206 BackingStore* backing_store) {}
207 void WidgetDidUpdateBackingStore(RenderWidgetHost* widget) {}
208 void WidgetDidReceivePaintAtSizeAck(RenderWidgetHost* host, 206 void WidgetDidReceivePaintAtSizeAck(RenderWidgetHost* host,
209 int tag, 207 int tag,
210 const gfx::Size& size) { 208 const gfx::Size& size) {
211 host_ = reinterpret_cast<MockRenderWidgetHost*>(host); 209 host_ = reinterpret_cast<MockRenderWidgetHost*>(host);
212 tag_ = tag; 210 tag_ = tag;
213 size_ = size; 211 size_ = size;
214 } 212 }
215 213
214 void Observe(NotificationType type,
215 const NotificationSource& source,
216 const NotificationDetails& details) {
217 if (type ==
218 NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK) {
219 RenderWidgetHost::PaintAtSizeAckDetails* size_ack_details =
220 Details<RenderWidgetHost::PaintAtSizeAckDetails>(details).ptr();
221 WidgetDidReceivePaintAtSizeAck(
222 Source<RenderWidgetHost>(source).ptr(),
223 size_ack_details->tag,
224 size_ack_details->size);
225 }
226 }
227
216 MockRenderWidgetHost* host() const { return host_; } 228 MockRenderWidgetHost* host() const { return host_; }
217 int tag() const { return tag_; } 229 int tag() const { return tag_; }
218 gfx::Size size() const { return size_; } 230 gfx::Size size() const { return size_; }
219 231
220 private: 232 private:
221 MockRenderWidgetHost* host_; 233 MockRenderWidgetHost* host_;
222 int tag_; 234 int tag_;
223 gfx::Size size_; 235 gfx::Size size_;
224 }; 236 };
225 237
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 EXPECT_TRUE(needs_repaint.a); 554 EXPECT_TRUE(needs_repaint.a);
543 } 555 }
544 556
545 TEST_F(RenderWidgetHostTest, PaintAtSize) { 557 TEST_F(RenderWidgetHostTest, PaintAtSize) {
546 const int kPaintAtSizeTag = 42; 558 const int kPaintAtSizeTag = 42;
547 host_->PaintAtSize(TransportDIB::GetFakeHandleForTest(), kPaintAtSizeTag, 559 host_->PaintAtSize(TransportDIB::GetFakeHandleForTest(), kPaintAtSizeTag,
548 gfx::Size(40, 60), gfx::Size(20, 30)); 560 gfx::Size(40, 60), gfx::Size(20, 30));
549 EXPECT_TRUE( 561 EXPECT_TRUE(
550 process_->sink().GetUniqueMessageMatching(ViewMsg_PaintAtSize::ID)); 562 process_->sink().GetUniqueMessageMatching(ViewMsg_PaintAtSize::ID));
551 563
564 NotificationRegistrar registrar;
552 MockPaintingObserver observer; 565 MockPaintingObserver observer;
553 host_->set_painting_observer(&observer); 566 registrar.Add(
567 &observer,
568 NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK,
569 Source<RenderWidgetHost>(host_.get()));
554 570
555 host_->OnMsgPaintAtSizeAck(kPaintAtSizeTag, gfx::Size(20, 30)); 571 host_->OnMsgPaintAtSizeAck(kPaintAtSizeTag, gfx::Size(20, 30));
556 EXPECT_EQ(host_.get(), observer.host()); 572 EXPECT_EQ(host_.get(), observer.host());
557 EXPECT_EQ(kPaintAtSizeTag, observer.tag()); 573 EXPECT_EQ(kPaintAtSizeTag, observer.tag());
558 EXPECT_EQ(20, observer.size().width()); 574 EXPECT_EQ(20, observer.size().width());
559 EXPECT_EQ(30, observer.size().height()); 575 EXPECT_EQ(30, observer.size().height());
560 host_->set_painting_observer(NULL);
561 } 576 }
562 577
563 TEST_F(RenderWidgetHostTest, HandleKeyEventsWeSent) { 578 TEST_F(RenderWidgetHostTest, HandleKeyEventsWeSent) {
564 // Simulate a keyboard event. 579 // Simulate a keyboard event.
565 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); 580 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
566 581
567 // Make sure we sent the input event to the renderer. 582 // Make sure we sent the input event to the renderer.
568 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 583 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
569 ViewMsg_HandleInputEvent::ID)); 584 ViewMsg_HandleInputEvent::ID));
570 process_->sink().ClearMessages(); 585 process_->sink().ClearMessages();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 // Start it again to ensure it still works. 719 // Start it again to ensure it still works.
705 EXPECT_FALSE(host_->unresponsive_timer_fired()); 720 EXPECT_FALSE(host_->unresponsive_timer_fired());
706 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); 721 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10));
707 722
708 // Wait long enough for first timeout and see if it fired. 723 // Wait long enough for first timeout and see if it fired.
709 MessageLoop::current()->PostDelayedTask(FROM_HERE, 724 MessageLoop::current()->PostDelayedTask(FROM_HERE,
710 new MessageLoop::QuitTask(), 10); 725 new MessageLoop::QuitTask(), 10);
711 MessageLoop::current()->Run(); 726 MessageLoop::current()->Run();
712 EXPECT_TRUE(host_->unresponsive_timer_fired()); 727 EXPECT_TRUE(host_->unresponsive_timer_fired());
713 } 728 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698