| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 virtual bool WaitForBackingStoreMsg(int render_widget_id, | 76 virtual bool WaitForBackingStoreMsg(int render_widget_id, |
| 77 const base::TimeDelta& max_delay, | 77 const base::TimeDelta& max_delay, |
| 78 IPC::Message* msg); | 78 IPC::Message* msg); |
| 79 | 79 |
| 80 TransportDIB* current_update_buf_; | 80 TransportDIB* current_update_buf_; |
| 81 | 81 |
| 82 // Set to true when WaitForBackingStoreMsg should return a successful update | 82 // Set to true when WaitForBackingStoreMsg should return a successful update |
| 83 // message reply. False implies timeout. | 83 // message reply. False implies timeout. |
| 84 bool update_msg_should_reply_; | 84 bool update_msg_should_reply_; |
| 85 | 85 |
| 86 // Indicates the flags that should be sent with a the repaint request. This | 86 // Indicates the flags that should be sent with a repaint request. This |
| 87 // only has an effect when update_msg_should_reply_ is true. | 87 // only has an effect when update_msg_should_reply_ is true. |
| 88 int update_msg_reply_flags_; | 88 int update_msg_reply_flags_; |
| 89 | 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess); | 90 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess); |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 void RenderWidgetHostProcess::InitUpdateRectParams( | 93 void RenderWidgetHostProcess::InitUpdateRectParams( |
| 94 ViewHostMsg_UpdateRect_Params* params) { | 94 ViewHostMsg_UpdateRect_Params* params) { |
| 95 // Create the shared backing store. | 95 // Create the shared backing store. |
| 96 const int w = 100, h = 100; | 96 const int w = 100, h = 100; |
| 97 const size_t pixel_size = w * h * 4; | 97 const size_t pixel_size = w * h * 4; |
| 98 | 98 |
| 99 if (!current_update_buf_) | 99 if (!current_update_buf_) |
| 100 current_update_buf_ = TransportDIB::Create(pixel_size, 0); | 100 current_update_buf_ = TransportDIB::Create(pixel_size, 0); |
| 101 params->bitmap = current_update_buf_->id(); | 101 params->bitmap = current_update_buf_->id(); |
| 102 params->bitmap_rect = gfx::Rect(0, 0, w, h); | 102 params->bitmap_rect = gfx::Rect(0, 0, w, h); |
| 103 params->dx = 0; | 103 params->dx = 0; |
| 104 params->dy = 0; | 104 params->dy = 0; |
| 105 params->copy_rects.push_back(params->bitmap_rect); | 105 params->copy_rects.push_back(params->bitmap_rect); |
| 106 params->view_size = gfx::Size(w, h); | 106 params->view_size = gfx::Size(w, h); |
| 107 params->flags = update_msg_reply_flags_; | 107 params->flags = update_msg_reply_flags_; |
| 108 params->needs_ack = true; | 108 params->needs_ack = true; |
| 109 params->scale_factor = 1; |
| 109 } | 110 } |
| 110 | 111 |
| 111 bool RenderWidgetHostProcess::WaitForBackingStoreMsg( | 112 bool RenderWidgetHostProcess::WaitForBackingStoreMsg( |
| 112 int render_widget_id, | 113 int render_widget_id, |
| 113 const base::TimeDelta& max_delay, | 114 const base::TimeDelta& max_delay, |
| 114 IPC::Message* msg) { | 115 IPC::Message* msg) { |
| 115 if (!update_msg_should_reply_) | 116 if (!update_msg_should_reply_) |
| 116 return false; | 117 return false; |
| 117 | 118 |
| 118 // Construct a fake update reply. | 119 // Construct a fake update reply. |
| (...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1085 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
| 1085 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1086 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
| 1086 SendInputEventACK(WebInputEvent::RawKeyDown, true); | 1087 SendInputEventACK(WebInputEvent::RawKeyDown, true); |
| 1087 | 1088 |
| 1088 // Wait long enough for first timeout and see if it fired. | 1089 // Wait long enough for first timeout and see if it fired. |
| 1089 MessageLoop::current()->PostDelayedTask( | 1090 MessageLoop::current()->PostDelayedTask( |
| 1090 FROM_HERE, MessageLoop::QuitClosure(), TimeDelta::FromMilliseconds(40)); | 1091 FROM_HERE, MessageLoop::QuitClosure(), TimeDelta::FromMilliseconds(40)); |
| 1091 MessageLoop::current()->Run(); | 1092 MessageLoop::current()->Run(); |
| 1092 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1093 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 1093 } | 1094 } |
| 1095 |
| 1096 // This test is not valid for Windows because getting the shared memory |
| 1097 // size doesn't work. |
| 1098 #if !defined(OS_WIN) |
| 1099 TEST_F(RenderWidgetHostTest, IncorrectBitmapScaleFactor) { |
| 1100 ViewHostMsg_UpdateRect_Params params; |
| 1101 process_->InitUpdateRectParams(¶ms); |
| 1102 params.scale_factor = params.scale_factor * 2; |
| 1103 |
| 1104 EXPECT_EQ(0, process_->bad_msg_count()); |
| 1105 host_->OnMsgUpdateRect(params); |
| 1106 EXPECT_EQ(1, process_->bad_msg_count()); |
| 1107 } |
| 1108 #endif |
| OLD | NEW |