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 "app/gfx/canvas.h" | 5 #include "app/gfx/canvas.h" |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "base/keyboard_codes.h" | 7 #include "base/keyboard_codes.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "base/shared_memory.h" | 9 #include "base/shared_memory.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 }; | 210 }; |
211 | 211 |
212 // ----------------------------------------------------------------------------- | 212 // ----------------------------------------------------------------------------- |
213 | 213 |
214 TEST_F(RenderWidgetHostTest, Resize) { | 214 TEST_F(RenderWidgetHostTest, Resize) { |
215 // The initial bounds is the empty rect, so setting it to the same thing | 215 // The initial bounds is the empty rect, so setting it to the same thing |
216 // should do nothing. | 216 // should do nothing. |
217 view_->set_bounds(gfx::Rect()); | 217 view_->set_bounds(gfx::Rect()); |
218 host_->WasResized(); | 218 host_->WasResized(); |
219 EXPECT_FALSE(host_->resize_ack_pending_); | 219 EXPECT_FALSE(host_->resize_ack_pending_); |
| 220 EXPECT_EQ(gfx::Size(), host_->in_flight_size_); |
220 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 221 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
221 | 222 |
222 // Setting the bounds to a "real" rect should send out the notification. | 223 // Setting the bounds to a "real" rect should send out the notification. |
223 gfx::Rect original_size(0, 0, 100, 100); | 224 gfx::Rect original_size(0, 0, 100, 100); |
224 process_->sink().ClearMessages(); | 225 process_->sink().ClearMessages(); |
225 view_->set_bounds(original_size); | 226 view_->set_bounds(original_size); |
226 host_->WasResized(); | 227 host_->WasResized(); |
227 EXPECT_TRUE(host_->resize_ack_pending_); | 228 EXPECT_TRUE(host_->resize_ack_pending_); |
| 229 EXPECT_EQ(original_size.size(), host_->in_flight_size_); |
228 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 230 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
229 | 231 |
230 // Send out a paint that's not a resize ack. This should not clean the | 232 // Send out a paint that's not a resize ack. This should not clean the |
231 // resize ack pending flag. | 233 // resize ack pending flag. |
232 ViewHostMsg_PaintRect_Params params; | 234 ViewHostMsg_PaintRect_Params params; |
233 process_->InitPaintRectParams(¶ms); | 235 process_->InitPaintRectParams(¶ms); |
234 host_->OnMsgPaintRect(params); | 236 host_->OnMsgPaintRect(params); |
235 EXPECT_TRUE(host_->resize_ack_pending_); | 237 EXPECT_TRUE(host_->resize_ack_pending_); |
| 238 EXPECT_EQ(original_size.size(), host_->in_flight_size_); |
236 | 239 |
237 // Sending out a new notification should NOT send out a new IPC message since | 240 // Sending out a new notification should NOT send out a new IPC message since |
238 // a resize ACK is pending. | 241 // a resize ACK is pending. |
239 gfx::Rect second_size(0, 0, 90, 90); | 242 gfx::Rect second_size(0, 0, 90, 90); |
240 process_->sink().ClearMessages(); | 243 process_->sink().ClearMessages(); |
241 view_->set_bounds(second_size); | 244 view_->set_bounds(second_size); |
242 host_->WasResized(); | 245 host_->WasResized(); |
243 EXPECT_TRUE(host_->resize_ack_pending_); | 246 EXPECT_TRUE(host_->resize_ack_pending_); |
| 247 EXPECT_EQ(original_size.size(), host_->in_flight_size_); |
244 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 248 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
245 | 249 |
246 // Send a paint that's a resize ack, but for the original_size we sent. Since | 250 // Send a paint that's a resize ack, but for the original_size we sent. Since |
247 // this isn't the second_size, the message handler should immediately send | 251 // this isn't the second_size, the message handler should immediately send |
248 // a new resize message for the new size to the renderer. | 252 // a new resize message for the new size to the renderer. |
249 process_->sink().ClearMessages(); | 253 process_->sink().ClearMessages(); |
250 params.flags = ViewHostMsg_PaintRect_Flags::IS_RESIZE_ACK; | 254 params.flags = ViewHostMsg_PaintRect_Flags::IS_RESIZE_ACK; |
251 params.view_size = original_size.size(); | 255 params.view_size = original_size.size(); |
252 host_->OnMsgPaintRect(params); | 256 host_->OnMsgPaintRect(params); |
253 EXPECT_TRUE(host_->resize_ack_pending_); | 257 EXPECT_TRUE(host_->resize_ack_pending_); |
| 258 EXPECT_EQ(second_size.size(), host_->in_flight_size_); |
254 ASSERT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 259 ASSERT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
255 | 260 |
256 // Send the resize ack for the latest size. | 261 // Send the resize ack for the latest size. |
257 process_->sink().ClearMessages(); | 262 process_->sink().ClearMessages(); |
258 params.view_size = second_size.size(); | 263 params.view_size = second_size.size(); |
259 host_->OnMsgPaintRect(params); | 264 host_->OnMsgPaintRect(params); |
260 EXPECT_FALSE(host_->resize_ack_pending_); | 265 EXPECT_FALSE(host_->resize_ack_pending_); |
| 266 EXPECT_EQ(gfx::Size(), host_->in_flight_size_); |
261 ASSERT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); | 267 ASSERT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); |
262 | 268 |
263 // Now clearing the bounds should send out a notification but we shouldn't | 269 // Now clearing the bounds should send out a notification but we shouldn't |
264 // expect a resize ack (since the renderer won't ack empty sizes). The message | 270 // expect a resize ack (since the renderer won't ack empty sizes). The message |
265 // should contain the new size (0x0) and not the previous one that we skipped | 271 // should contain the new size (0x0) and not the previous one that we skipped |
266 process_->sink().ClearMessages(); | 272 process_->sink().ClearMessages(); |
267 view_->set_bounds(gfx::Rect()); | 273 view_->set_bounds(gfx::Rect()); |
268 host_->WasResized(); | 274 host_->WasResized(); |
269 EXPECT_FALSE(host_->resize_ack_pending_); | 275 EXPECT_FALSE(host_->resize_ack_pending_); |
| 276 EXPECT_EQ(gfx::Size(), host_->in_flight_size_); |
270 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 277 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
271 | 278 |
272 // Send a rect that has no area but has either width or height set. | 279 // Send a rect that has no area but has either width or height set. |
273 process_->sink().ClearMessages(); | 280 process_->sink().ClearMessages(); |
274 view_->set_bounds(gfx::Rect(0, 0, 0, 30)); | 281 view_->set_bounds(gfx::Rect(0, 0, 0, 30)); |
275 host_->WasResized(); | 282 host_->WasResized(); |
276 EXPECT_FALSE(host_->resize_ack_pending_); | 283 EXPECT_FALSE(host_->resize_ack_pending_); |
| 284 EXPECT_EQ(gfx::Size(0, 30), host_->in_flight_size_); |
277 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 285 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
278 | 286 |
279 // Set the same size again. It should not be sent again. | 287 // Set the same size again. It should not be sent again. |
280 process_->sink().ClearMessages(); | 288 process_->sink().ClearMessages(); |
281 host_->WasResized(); | 289 host_->WasResized(); |
282 EXPECT_FALSE(host_->resize_ack_pending_); | 290 EXPECT_FALSE(host_->resize_ack_pending_); |
| 291 EXPECT_EQ(gfx::Size(0, 30), host_->in_flight_size_); |
283 EXPECT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); | 292 EXPECT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); |
284 | 293 |
285 // A different size should be sent again, however. | 294 // A different size should be sent again, however. |
286 view_->set_bounds(gfx::Rect(0, 0, 0, 31)); | 295 view_->set_bounds(gfx::Rect(0, 0, 0, 31)); |
287 host_->WasResized(); | 296 host_->WasResized(); |
288 EXPECT_FALSE(host_->resize_ack_pending_); | 297 EXPECT_FALSE(host_->resize_ack_pending_); |
| 298 EXPECT_EQ(gfx::Size(0, 31), host_->in_flight_size_); |
289 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 299 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
290 } | 300 } |
291 | 301 |
| 302 // Test for crbug.com/25097. If a renderer crashes between a resize and the |
| 303 // corresponding paint message, we must be sure to clear the resize ack logic. |
| 304 TEST_F(RenderWidgetHostTest, ResizeThenCrash) { |
| 305 // Setting the bounds to a "real" rect should send out the notification. |
| 306 gfx::Rect original_size(0, 0, 100, 100); |
| 307 view_->set_bounds(original_size); |
| 308 host_->WasResized(); |
| 309 EXPECT_TRUE(host_->resize_ack_pending_); |
| 310 EXPECT_EQ(original_size.size(), host_->in_flight_size_); |
| 311 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
| 312 |
| 313 // Simulate a renderer crash before the paint message. Ensure all the resize |
| 314 // ack logic is cleared. |
| 315 host_->RendererExited(); |
| 316 EXPECT_FALSE(host_->resize_ack_pending_); |
| 317 EXPECT_EQ(gfx::Size(), host_->in_flight_size_); |
| 318 |
| 319 // Reset the view so we can exit the test cleanly. |
| 320 view_.reset(new TestView(host_.get())); |
| 321 } |
| 322 |
292 // Tests setting custom background | 323 // Tests setting custom background |
293 TEST_F(RenderWidgetHostTest, Background) { | 324 TEST_F(RenderWidgetHostTest, Background) { |
294 #if defined(OS_WIN) || defined(OS_LINUX) | 325 #if defined(OS_WIN) || defined(OS_LINUX) |
295 scoped_ptr<RenderWidgetHostView> view( | 326 scoped_ptr<RenderWidgetHostView> view( |
296 RenderWidgetHostView::CreateViewForWidget(host_.get())); | 327 RenderWidgetHostView::CreateViewForWidget(host_.get())); |
297 host_->set_view(view.get()); | 328 host_->set_view(view.get()); |
298 | 329 |
299 // Create a checkerboard background to test with. | 330 // Create a checkerboard background to test with. |
300 gfx::Canvas canvas(4, 4, true); | 331 gfx::Canvas canvas(4, 4, true); |
301 canvas.FillRectInt(SK_ColorBLACK, 0, 0, 2, 2); | 332 canvas.FillRectInt(SK_ColorBLACK, 0, 0, 2, 2); |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 SendInputEventACK(WebInputEvent::Char, false); | 722 SendInputEventACK(WebInputEvent::Char, false); |
692 EXPECT_TRUE(host_->unhandled_keyboard_event_called()); | 723 EXPECT_TRUE(host_->unhandled_keyboard_event_called()); |
693 EXPECT_EQ(WebInputEvent::Char, host_->unhandled_keyboard_event_type()); | 724 EXPECT_EQ(WebInputEvent::Char, host_->unhandled_keyboard_event_type()); |
694 | 725 |
695 // Send the simulated response of the KeyUp event from the renderer back. | 726 // Send the simulated response of the KeyUp event from the renderer back. |
696 SendInputEventACK(WebInputEvent::KeyUp, false); | 727 SendInputEventACK(WebInputEvent::KeyUp, false); |
697 EXPECT_TRUE(host_->unhandled_keyboard_event_called()); | 728 EXPECT_TRUE(host_->unhandled_keyboard_event_called()); |
698 EXPECT_EQ(WebInputEvent::KeyUp, host_->unhandled_keyboard_event_type()); | 729 EXPECT_EQ(WebInputEvent::KeyUp, host_->unhandled_keyboard_event_type()); |
699 } | 730 } |
700 } | 731 } |
OLD | NEW |