| 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/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
| 7 #include "base/shared_memory.h" | 7 #include "base/shared_memory.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/renderer_host/test_render_view_host.h" | 9 #include "chrome/browser/renderer_host/test_render_view_host.h" |
| 10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 #if defined(OS_POSIX) | |
| 14 #include "skia/ext/platform_canvas.h" | |
| 15 #endif | |
| 16 | |
| 17 namespace { | 13 namespace { |
| 18 | 14 |
| 19 // RenderWidgetHostProcess ----------------------------------------------------- | 15 // RenderWidgetHostProcess ----------------------------------------------------- |
| 20 | 16 |
| 21 class RenderWidgetHostProcess : public MockRenderProcessHost { | 17 class RenderWidgetHostProcess : public MockRenderProcessHost { |
| 22 public: | 18 public: |
| 23 explicit RenderWidgetHostProcess(Profile* profile) | 19 explicit RenderWidgetHostProcess(Profile* profile) |
| 24 : MockRenderProcessHost(profile), | 20 : MockRenderProcessHost(profile), |
| 25 #if defined(OS_WIN) | |
| 26 current_paint_buf_(NULL), | 21 current_paint_buf_(NULL), |
| 27 #endif | |
| 28 paint_msg_should_reply_(false), | 22 paint_msg_should_reply_(false), |
| 29 paint_msg_reply_flags_(0) { | 23 paint_msg_reply_flags_(0) { |
| 30 // DANGER! This is a hack. The RenderWidgetHost checks the channel to see | 24 // DANGER! This is a hack. The RenderWidgetHost checks the channel to see |
| 31 // if the process is still alive, but it doesn't actually dereference it. | 25 // if the process is still alive, but it doesn't actually dereference it. |
| 32 // An IPC::SyncChannel is nontrivial, so we just fake it here. If you end up | 26 // An IPC::SyncChannel is nontrivial, so we just fake it here. If you end up |
| 33 // crashing by dereferencing 1, then you'll have to make a real channel. | 27 // crashing by dereferencing 1, then you'll have to make a real channel. |
| 34 channel_.reset(reinterpret_cast<IPC::SyncChannel*>(0x1)); | 28 channel_.reset(reinterpret_cast<IPC::SyncChannel*>(0x1)); |
| 35 } | 29 } |
| 36 ~RenderWidgetHostProcess() { | 30 ~RenderWidgetHostProcess() { |
| 37 // We don't want to actually delete the channel, since it's not a real | 31 // We don't want to actually delete the channel, since it's not a real |
| 38 // pointer. | 32 // pointer. |
| 39 channel_.release(); | 33 channel_.release(); |
| 40 } | 34 } |
| 41 | 35 |
| 42 void set_paint_msg_should_reply(bool reply) { | 36 void set_paint_msg_should_reply(bool reply) { |
| 43 paint_msg_should_reply_ = reply; | 37 paint_msg_should_reply_ = reply; |
| 44 } | 38 } |
| 45 void set_paint_msg_reply_flags(int flags) { | 39 void set_paint_msg_reply_flags(int flags) { |
| 46 paint_msg_reply_flags_ = flags; | 40 paint_msg_reply_flags_ = flags; |
| 47 } | 41 } |
| 48 | 42 |
| 49 // Fills the given paint parameters with resonable default values. | 43 // Fills the given paint parameters with resonable default values. |
| 50 void InitPaintRectParams(ViewHostMsg_PaintRect_Params* params); | 44 void InitPaintRectParams(ViewHostMsg_PaintRect_Params* params); |
| 51 | 45 |
| 52 protected: | 46 protected: |
| 53 virtual bool WaitForPaintMsg(int render_widget_id, | 47 virtual bool WaitForPaintMsg(int render_widget_id, |
| 54 const base::TimeDelta& max_delay, | 48 const base::TimeDelta& max_delay, |
| 55 IPC::Message* msg); | 49 IPC::Message* msg); |
| 56 | 50 |
| 57 #if defined(OS_WIN) | 51 TransportDIB* current_paint_buf_; |
| 58 scoped_ptr<base::SharedMemory> current_paint_buf_; | |
| 59 #elif defined(OS_POSIX) | |
| 60 skia::PlatformCanvas canvas; | |
| 61 #endif | |
| 62 | 52 |
| 63 // Set to true when WaitForPaintMsg should return a successful paint messaage | 53 // Set to true when WaitForPaintMsg should return a successful paint messaage |
| 64 // reply. False implies timeout. | 54 // reply. False implies timeout. |
| 65 bool paint_msg_should_reply_; | 55 bool paint_msg_should_reply_; |
| 66 | 56 |
| 67 // Indicates the flags that should be sent with a the repaint request. This | 57 // Indicates the flags that should be sent with a the repaint request. This |
| 68 // only has an effect when paint_msg_should_reply_ is true. | 58 // only has an effect when paint_msg_should_reply_ is true. |
| 69 int paint_msg_reply_flags_; | 59 int paint_msg_reply_flags_; |
| 70 | 60 |
| 71 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess); | 61 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess); |
| 72 }; | 62 }; |
| 73 | 63 |
| 74 void RenderWidgetHostProcess::InitPaintRectParams( | 64 void RenderWidgetHostProcess::InitPaintRectParams( |
| 75 ViewHostMsg_PaintRect_Params* params) { | 65 ViewHostMsg_PaintRect_Params* params) { |
| 76 // Create the shared backing store. | 66 // Create the shared backing store. |
| 77 const int w = 100, h = 100; | 67 const int w = 100, h = 100; |
| 68 const size_t pixel_size = w * h * 4; |
| 78 | 69 |
| 79 #if defined(OS_WIN) | 70 current_paint_buf_ = TransportDIB::Create(pixel_size, 0); |
| 80 int pixel_size = w * h * 4; | 71 params->bitmap = current_paint_buf_->id(); |
| 81 | |
| 82 current_paint_buf_.reset(new base::SharedMemory()); | |
| 83 ASSERT_TRUE(current_paint_buf_->Create(std::wstring(), false, true, | |
| 84 pixel_size)); | |
| 85 | |
| 86 params->bitmap = current_paint_buf_->handle(); | |
| 87 #elif defined(OS_POSIX) | |
| 88 ASSERT_TRUE(canvas.initialize(w, h, true)); | |
| 89 params->bitmap = canvas.getDevice()->accessBitmap(false); | |
| 90 #endif | |
| 91 | |
| 92 params->bitmap_rect = gfx::Rect(0, 0, w, h); | 72 params->bitmap_rect = gfx::Rect(0, 0, w, h); |
| 93 params->view_size = gfx::Size(w, h); | 73 params->view_size = gfx::Size(w, h); |
| 94 params->flags = paint_msg_reply_flags_; | 74 params->flags = paint_msg_reply_flags_; |
| 95 } | 75 } |
| 96 | 76 |
| 97 bool RenderWidgetHostProcess::WaitForPaintMsg(int render_widget_id, | 77 bool RenderWidgetHostProcess::WaitForPaintMsg(int render_widget_id, |
| 98 const base::TimeDelta& max_delay, | 78 const base::TimeDelta& max_delay, |
| 99 IPC::Message* msg) { | 79 IPC::Message* msg) { |
| 100 if (!paint_msg_should_reply_) | 80 if (!paint_msg_should_reply_) |
| 101 return false; | 81 return false; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 EXPECT_FALSE(host_->is_hidden_); | 289 EXPECT_FALSE(host_->is_hidden_); |
| 310 | 290 |
| 311 // It should have sent out a restored message with a request to paint. | 291 // It should have sent out a restored message with a request to paint. |
| 312 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching( | 292 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching( |
| 313 ViewMsg_WasRestored::ID); | 293 ViewMsg_WasRestored::ID); |
| 314 ASSERT_TRUE(restored); | 294 ASSERT_TRUE(restored); |
| 315 bool needs_repaint; | 295 bool needs_repaint; |
| 316 ViewMsg_WasRestored::Read(restored, &needs_repaint); | 296 ViewMsg_WasRestored::Read(restored, &needs_repaint); |
| 317 EXPECT_TRUE(needs_repaint); | 297 EXPECT_TRUE(needs_repaint); |
| 318 } | 298 } |
| OLD | NEW |