OLD | NEW |
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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/shared_memory.h" | 7 #include "base/shared_memory.h" |
8 #include "base/timer.h" | 8 #include "base/timer.h" |
9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
10 #include "content/browser/renderer_host/backing_store.h" | 10 #include "content/browser/renderer_host/backing_store.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 // RenderWidgetHostProcess ----------------------------------------------------- | 265 // RenderWidgetHostProcess ----------------------------------------------------- |
266 | 266 |
267 class RenderWidgetHostProcess : public MockRenderProcessHost { | 267 class RenderWidgetHostProcess : public MockRenderProcessHost { |
268 public: | 268 public: |
269 explicit RenderWidgetHostProcess(BrowserContext* browser_context) | 269 explicit RenderWidgetHostProcess(BrowserContext* browser_context) |
270 : MockRenderProcessHost(browser_context), | 270 : MockRenderProcessHost(browser_context), |
271 current_update_buf_(NULL), | 271 current_update_buf_(NULL), |
272 update_msg_should_reply_(false), | 272 update_msg_should_reply_(false), |
273 update_msg_reply_flags_(0) { | 273 update_msg_reply_flags_(0) { |
274 } | 274 } |
275 ~RenderWidgetHostProcess() { | 275 virtual ~RenderWidgetHostProcess() { |
276 delete current_update_buf_; | 276 delete current_update_buf_; |
277 } | 277 } |
278 | 278 |
279 void set_update_msg_should_reply(bool reply) { | 279 void set_update_msg_should_reply(bool reply) { |
280 update_msg_should_reply_ = reply; | 280 update_msg_should_reply_ = reply; |
281 } | 281 } |
282 void set_update_msg_reply_flags(int flags) { | 282 void set_update_msg_reply_flags(int flags) { |
283 update_msg_reply_flags_ = flags; | 283 update_msg_reply_flags_ = flags; |
284 } | 284 } |
285 | 285 |
286 // Fills the given update parameters with resonable default values. | 286 // Fills the given update parameters with resonable default values. |
287 void InitUpdateRectParams(ViewHostMsg_UpdateRect_Params* params); | 287 void InitUpdateRectParams(ViewHostMsg_UpdateRect_Params* params); |
288 | 288 |
289 virtual bool HasConnection() const { return true; } | 289 virtual bool HasConnection() const OVERRIDE { return true; } |
290 | 290 |
291 protected: | 291 protected: |
292 virtual bool WaitForBackingStoreMsg(int render_widget_id, | 292 virtual bool WaitForBackingStoreMsg(int render_widget_id, |
293 const base::TimeDelta& max_delay, | 293 const base::TimeDelta& max_delay, |
294 IPC::Message* msg); | 294 IPC::Message* msg) OVERRIDE; |
295 | 295 |
296 TransportDIB* current_update_buf_; | 296 TransportDIB* current_update_buf_; |
297 | 297 |
298 // Set to true when WaitForBackingStoreMsg should return a successful update | 298 // Set to true when WaitForBackingStoreMsg should return a successful update |
299 // message reply. False implies timeout. | 299 // message reply. False implies timeout. |
300 bool update_msg_should_reply_; | 300 bool update_msg_should_reply_; |
301 | 301 |
302 // Indicates the flags that should be sent with a repaint request. This | 302 // Indicates the flags that should be sent with a repaint request. This |
303 // only has an effect when update_msg_should_reply_ is true. | 303 // only has an effect when update_msg_should_reply_ is true. |
304 int update_msg_reply_flags_; | 304 int update_msg_reply_flags_; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 class MockPaintingObserver : public NotificationObserver { | 444 class MockPaintingObserver : public NotificationObserver { |
445 public: | 445 public: |
446 void WidgetDidReceivePaintAtSizeAck(RenderWidgetHostImpl* host, | 446 void WidgetDidReceivePaintAtSizeAck(RenderWidgetHostImpl* host, |
447 int tag, | 447 int tag, |
448 const gfx::Size& size) { | 448 const gfx::Size& size) { |
449 host_ = reinterpret_cast<MockRenderWidgetHost*>(host); | 449 host_ = reinterpret_cast<MockRenderWidgetHost*>(host); |
450 tag_ = tag; | 450 tag_ = tag; |
451 size_ = size; | 451 size_ = size; |
452 } | 452 } |
453 | 453 |
454 void Observe(int type, | 454 virtual void Observe(int type, |
455 const NotificationSource& source, | 455 const NotificationSource& source, |
456 const NotificationDetails& details) { | 456 const NotificationDetails& details) OVERRIDE { |
457 if (type == NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK) { | 457 if (type == NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK) { |
458 std::pair<int, gfx::Size>* size_ack_details = | 458 std::pair<int, gfx::Size>* size_ack_details = |
459 Details<std::pair<int, gfx::Size> >(details).ptr(); | 459 Details<std::pair<int, gfx::Size> >(details).ptr(); |
460 WidgetDidReceivePaintAtSizeAck( | 460 WidgetDidReceivePaintAtSizeAck( |
461 RenderWidgetHostImpl::From(Source<RenderWidgetHost>(source).ptr()), | 461 RenderWidgetHostImpl::From(Source<RenderWidgetHost>(source).ptr()), |
462 size_ack_details->first, | 462 size_ack_details->first, |
463 size_ack_details->second); | 463 size_ack_details->second); |
464 } | 464 } |
465 } | 465 } |
466 | 466 |
467 MockRenderWidgetHost* host() const { return host_; } | 467 MockRenderWidgetHost* host() const { return host_; } |
468 int tag() const { return tag_; } | 468 int tag() const { return tag_; } |
469 gfx::Size size() const { return size_; } | 469 gfx::Size size() const { return size_; } |
470 | 470 |
471 private: | 471 private: |
472 MockRenderWidgetHost* host_; | 472 MockRenderWidgetHost* host_; |
473 int tag_; | 473 int tag_; |
474 gfx::Size size_; | 474 gfx::Size size_; |
475 }; | 475 }; |
476 | 476 |
477 | 477 |
478 // RenderWidgetHostTest -------------------------------------------------------- | 478 // RenderWidgetHostTest -------------------------------------------------------- |
479 | 479 |
480 class RenderWidgetHostTest : public testing::Test { | 480 class RenderWidgetHostTest : public testing::Test { |
481 public: | 481 public: |
482 RenderWidgetHostTest() : process_(NULL) { | 482 RenderWidgetHostTest() : process_(NULL) { |
483 } | 483 } |
484 ~RenderWidgetHostTest() { | 484 virtual ~RenderWidgetHostTest() { |
485 } | 485 } |
486 | 486 |
487 protected: | 487 protected: |
488 // testing::Test | 488 // testing::Test |
489 void SetUp() { | 489 virtual void SetUp() { |
490 browser_context_.reset(new TestBrowserContext()); | 490 browser_context_.reset(new TestBrowserContext()); |
491 delegate_.reset(new MockRenderWidgetHostDelegate()); | 491 delegate_.reset(new MockRenderWidgetHostDelegate()); |
492 process_ = new RenderWidgetHostProcess(browser_context_.get()); | 492 process_ = new RenderWidgetHostProcess(browser_context_.get()); |
493 #if defined(USE_AURA) | 493 #if defined(USE_AURA) |
494 screen_.reset(new aura::TestScreen); | 494 screen_.reset(new aura::TestScreen); |
495 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | 495 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
496 #endif | 496 #endif |
497 host_.reset( | 497 host_.reset( |
498 new MockRenderWidgetHost(delegate_.get(), process_, MSG_ROUTING_NONE)); | 498 new MockRenderWidgetHost(delegate_.get(), process_, MSG_ROUTING_NONE)); |
499 view_.reset(new TestView(host_.get())); | 499 view_.reset(new TestView(host_.get())); |
500 host_->SetView(view_.get()); | 500 host_->SetView(view_.get()); |
501 host_->Init(); | 501 host_->Init(); |
502 } | 502 } |
503 void TearDown() { | 503 virtual void TearDown() { |
504 view_.reset(); | 504 view_.reset(); |
505 host_.reset(); | 505 host_.reset(); |
506 delegate_.reset(); | 506 delegate_.reset(); |
507 process_ = NULL; | 507 process_ = NULL; |
508 browser_context_.reset(); | 508 browser_context_.reset(); |
509 | 509 |
510 #if defined(USE_AURA) | 510 #if defined(USE_AURA) |
511 aura::Env::DeleteInstance(); | 511 aura::Env::DeleteInstance(); |
512 screen_.reset(); | 512 screen_.reset(); |
513 #endif | 513 #endif |
(...skipping 3108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3622 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize()); | 3622 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize()); |
3623 | 3623 |
3624 SendInputEventACK(WebKit::WebInputEvent::GestureScrollEnd, | 3624 SendInputEventACK(WebKit::WebInputEvent::GestureScrollEnd, |
3625 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 3625 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
3626 EXPECT_EQ(0U, process_->sink().message_count()); | 3626 EXPECT_EQ(0U, process_->sink().message_count()); |
3627 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); | 3627 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); |
3628 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize()); | 3628 EXPECT_EQ(0U, host_->GestureEventDebouncingQueueSize()); |
3629 } | 3629 } |
3630 | 3630 |
3631 } // namespace content | 3631 } // namespace content |
OLD | NEW |