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

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

Issue 506075: Revert 34951 - Combine ViewHostMsg_{Paint,Scroll}Rect into one IPC.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years 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/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"
11 #include "chrome/browser/renderer_host/backing_store.h" 11 #include "chrome/browser/renderer_host/backing_store.h"
12 #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/render_messages.h" 13 #include "chrome/common/render_messages.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using WebKit::WebInputEvent; 16 using WebKit::WebInputEvent;
17 17
18 // RenderWidgetHostProcess ----------------------------------------------------- 18 // RenderWidgetHostProcess -----------------------------------------------------
19 19
20 class RenderWidgetHostProcess : public MockRenderProcessHost { 20 class RenderWidgetHostProcess : public MockRenderProcessHost {
21 public: 21 public:
22 explicit RenderWidgetHostProcess(Profile* profile) 22 explicit RenderWidgetHostProcess(Profile* profile)
23 : MockRenderProcessHost(profile), 23 : MockRenderProcessHost(profile),
24 current_update_buf_(NULL), 24 current_paint_buf_(NULL),
25 update_msg_should_reply_(false), 25 paint_msg_should_reply_(false),
26 update_msg_reply_flags_(0) { 26 paint_msg_reply_flags_(0) {
27 // DANGER! This is a hack. The RenderWidgetHost checks the channel to see 27 // DANGER! This is a hack. The RenderWidgetHost checks the channel to see
28 // if the process is still alive, but it doesn't actually dereference it. 28 // if the process is still alive, but it doesn't actually dereference it.
29 // An IPC::SyncChannel is nontrivial, so we just fake it here. If you end up 29 // An IPC::SyncChannel is nontrivial, so we just fake it here. If you end up
30 // crashing by dereferencing 1, then you'll have to make a real channel. 30 // crashing by dereferencing 1, then you'll have to make a real channel.
31 channel_.reset(reinterpret_cast<IPC::SyncChannel*>(0x1)); 31 channel_.reset(reinterpret_cast<IPC::SyncChannel*>(0x1));
32 } 32 }
33 ~RenderWidgetHostProcess() { 33 ~RenderWidgetHostProcess() {
34 // We don't want to actually delete the channel, since it's not a real 34 // We don't want to actually delete the channel, since it's not a real
35 // pointer. 35 // pointer.
36 channel_.release(); 36 channel_.release();
37 delete current_update_buf_; 37 if (current_paint_buf_)
38 delete current_paint_buf_;
38 } 39 }
39 40
40 void set_update_msg_should_reply(bool reply) { 41 void set_paint_msg_should_reply(bool reply) {
41 update_msg_should_reply_ = reply; 42 paint_msg_should_reply_ = reply;
42 } 43 }
43 void set_update_msg_reply_flags(int flags) { 44 void set_paint_msg_reply_flags(int flags) {
44 update_msg_reply_flags_ = flags; 45 paint_msg_reply_flags_ = flags;
45 } 46 }
46 47
47 // Fills the given paint parameters with resonable default values. 48 // Fills the given paint parameters with resonable default values.
48 void InitUpdateRectParams(ViewHostMsg_UpdateRect_Params* params); 49 void InitPaintRectParams(ViewHostMsg_PaintRect_Params* params);
49 50
50 protected: 51 protected:
51 virtual bool WaitForUpdateMsg(int render_widget_id, 52 virtual bool WaitForPaintMsg(int render_widget_id,
52 const base::TimeDelta& max_delay, 53 const base::TimeDelta& max_delay,
53 IPC::Message* msg); 54 IPC::Message* msg);
54 55
55 TransportDIB* current_update_buf_; 56 TransportDIB* current_paint_buf_;
56 57
57 // Set to true when WaitForPaintMsg should return a successful paint messaage 58 // Set to true when WaitForPaintMsg should return a successful paint messaage
58 // reply. False implies timeout. 59 // reply. False implies timeout.
59 bool update_msg_should_reply_; 60 bool paint_msg_should_reply_;
60 61
61 // Indicates the flags that should be sent with a the repaint request. This 62 // Indicates the flags that should be sent with a the repaint request. This
62 // only has an effect when paint_msg_should_reply_ is true. 63 // only has an effect when paint_msg_should_reply_ is true.
63 int update_msg_reply_flags_; 64 int paint_msg_reply_flags_;
64 65
65 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess); 66 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess);
66 }; 67 };
67 68
68 void RenderWidgetHostProcess::InitUpdateRectParams( 69 void RenderWidgetHostProcess::InitPaintRectParams(
69 ViewHostMsg_UpdateRect_Params* params) { 70 ViewHostMsg_PaintRect_Params* params) {
70 // Create the shared backing store. 71 // Create the shared backing store.
71 const int w = 100, h = 100; 72 const int w = 100, h = 100;
72 const size_t pixel_size = w * h * 4; 73 const size_t pixel_size = w * h * 4;
73 74
74 if (!current_update_buf_) 75 if (!current_paint_buf_)
75 current_update_buf_ = TransportDIB::Create(pixel_size, 0); 76 current_paint_buf_ = TransportDIB::Create(pixel_size, 0);
76 params->bitmap = current_update_buf_->id(); 77 params->bitmap = current_paint_buf_->id();
77 params->bitmap_rect = gfx::Rect(0, 0, w, h); 78 params->bitmap_rect = gfx::Rect(0, 0, w, h);
78 params->dx = 0; 79 params->update_rects.push_back(params->bitmap_rect);
79 params->dy = 0;
80 params->copy_rects.push_back(params->bitmap_rect);
81 params->view_size = gfx::Size(w, h); 80 params->view_size = gfx::Size(w, h);
82 params->flags = update_msg_reply_flags_; 81 params->flags = paint_msg_reply_flags_;
83 } 82 }
84 83
85 bool RenderWidgetHostProcess::WaitForUpdateMsg(int render_widget_id, 84 bool RenderWidgetHostProcess::WaitForPaintMsg(int render_widget_id,
86 const base::TimeDelta& max_delay, 85 const base::TimeDelta& max_delay,
87 IPC::Message* msg) { 86 IPC::Message* msg) {
88 if (!update_msg_should_reply_) 87 if (!paint_msg_should_reply_)
89 return false; 88 return false;
90 89
91 // Construct a fake paint reply. 90 // Construct a fake paint reply.
92 ViewHostMsg_UpdateRect_Params params; 91 ViewHostMsg_PaintRect_Params params;
93 InitUpdateRectParams(&params); 92 InitPaintRectParams(&params);
94 93
95 ViewHostMsg_UpdateRect message(render_widget_id, params); 94 ViewHostMsg_PaintRect message(render_widget_id, params);
96 *msg = message; 95 *msg = message;
97 return true; 96 return true;
98 } 97 }
99 98
100 // TestView -------------------------------------------------------------------- 99 // TestView --------------------------------------------------------------------
101 100
102 // This test view allows us to specify the size. 101 // This test view allows us to specify the size.
103 class TestView : public TestRenderWidgetHostView { 102 class TestView : public TestRenderWidgetHostView {
104 public: 103 public:
105 explicit TestView(RenderWidgetHost* rwh) : TestRenderWidgetHostView(rwh) {} 104 explicit TestView(RenderWidgetHost* rwh) : TestRenderWidgetHostView(rwh) {}
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 gfx::Rect original_size(0, 0, 100, 100); 244 gfx::Rect original_size(0, 0, 100, 100);
246 process_->sink().ClearMessages(); 245 process_->sink().ClearMessages();
247 view_->set_bounds(original_size); 246 view_->set_bounds(original_size);
248 host_->WasResized(); 247 host_->WasResized();
249 EXPECT_TRUE(host_->resize_ack_pending_); 248 EXPECT_TRUE(host_->resize_ack_pending_);
250 EXPECT_EQ(original_size.size(), host_->in_flight_size_); 249 EXPECT_EQ(original_size.size(), host_->in_flight_size_);
251 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 250 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
252 251
253 // Send out a paint that's not a resize ack. This should not clean the 252 // Send out a paint that's not a resize ack. This should not clean the
254 // resize ack pending flag. 253 // resize ack pending flag.
255 ViewHostMsg_UpdateRect_Params params; 254 ViewHostMsg_PaintRect_Params params;
256 process_->InitUpdateRectParams(&params); 255 process_->InitPaintRectParams(&params);
257 host_->OnMsgUpdateRect(params); 256 host_->OnMsgPaintRect(params);
258 EXPECT_TRUE(host_->resize_ack_pending_); 257 EXPECT_TRUE(host_->resize_ack_pending_);
259 EXPECT_EQ(original_size.size(), host_->in_flight_size_); 258 EXPECT_EQ(original_size.size(), host_->in_flight_size_);
260 259
261 // Sending out a new notification should NOT send out a new IPC message since 260 // Sending out a new notification should NOT send out a new IPC message since
262 // a resize ACK is pending. 261 // a resize ACK is pending.
263 gfx::Rect second_size(0, 0, 90, 90); 262 gfx::Rect second_size(0, 0, 90, 90);
264 process_->sink().ClearMessages(); 263 process_->sink().ClearMessages();
265 view_->set_bounds(second_size); 264 view_->set_bounds(second_size);
266 host_->WasResized(); 265 host_->WasResized();
267 EXPECT_TRUE(host_->resize_ack_pending_); 266 EXPECT_TRUE(host_->resize_ack_pending_);
268 EXPECT_EQ(original_size.size(), host_->in_flight_size_); 267 EXPECT_EQ(original_size.size(), host_->in_flight_size_);
269 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 268 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
270 269
271 // Send a paint that's a resize ack, but for the original_size we sent. Since 270 // Send a paint that's a resize ack, but for the original_size we sent. Since
272 // this isn't the second_size, the message handler should immediately send 271 // this isn't the second_size, the message handler should immediately send
273 // a new resize message for the new size to the renderer. 272 // a new resize message for the new size to the renderer.
274 process_->sink().ClearMessages(); 273 process_->sink().ClearMessages();
275 params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; 274 params.flags = ViewHostMsg_PaintRect_Flags::IS_RESIZE_ACK;
276 params.view_size = original_size.size(); 275 params.view_size = original_size.size();
277 host_->OnMsgUpdateRect(params); 276 host_->OnMsgPaintRect(params);
278 EXPECT_TRUE(host_->resize_ack_pending_); 277 EXPECT_TRUE(host_->resize_ack_pending_);
279 EXPECT_EQ(second_size.size(), host_->in_flight_size_); 278 EXPECT_EQ(second_size.size(), host_->in_flight_size_);
280 ASSERT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 279 ASSERT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
281 280
282 // Send the resize ack for the latest size. 281 // Send the resize ack for the latest size.
283 process_->sink().ClearMessages(); 282 process_->sink().ClearMessages();
284 params.view_size = second_size.size(); 283 params.view_size = second_size.size();
285 host_->OnMsgUpdateRect(params); 284 host_->OnMsgPaintRect(params);
286 EXPECT_FALSE(host_->resize_ack_pending_); 285 EXPECT_FALSE(host_->resize_ack_pending_);
287 EXPECT_EQ(gfx::Size(), host_->in_flight_size_); 286 EXPECT_EQ(gfx::Size(), host_->in_flight_size_);
288 ASSERT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); 287 ASSERT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID));
289 288
290 // Now clearing the bounds should send out a notification but we shouldn't 289 // Now clearing the bounds should send out a notification but we shouldn't
291 // expect a resize ack (since the renderer won't ack empty sizes). The message 290 // expect a resize ack (since the renderer won't ack empty sizes). The message
292 // should contain the new size (0x0) and not the previous one that we skipped 291 // should contain the new size (0x0) and not the previous one that we skipped
293 process_->sink().ClearMessages(); 292 process_->sink().ClearMessages();
294 view_->set_bounds(gfx::Rect()); 293 view_->set_bounds(gfx::Rect());
295 host_->WasResized(); 294 host_->WasResized();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 // TODO(aa): It would be nice to factor out the painting logic so that we 391 // TODO(aa): It would be nice to factor out the painting logic so that we
393 // could test that, but it appears that would mean painting everything twice 392 // could test that, but it appears that would mean painting everything twice
394 // since windows HDC structures are opaque. 393 // since windows HDC structures are opaque.
395 } 394 }
396 395
397 // Tests getting the backing store with the renderer not setting repaint ack 396 // Tests getting the backing store with the renderer not setting repaint ack
398 // flags. 397 // flags.
399 TEST_F(RenderWidgetHostTest, GetBackingStore_NoRepaintAck) { 398 TEST_F(RenderWidgetHostTest, GetBackingStore_NoRepaintAck) {
400 // We don't currently have a backing store, and if the renderer doesn't send 399 // We don't currently have a backing store, and if the renderer doesn't send
401 // one in time, we should get nothing. 400 // one in time, we should get nothing.
402 process_->set_update_msg_should_reply(false); 401 process_->set_paint_msg_should_reply(false);
403 BackingStore* backing = host_->GetBackingStore(true); 402 BackingStore* backing = host_->GetBackingStore(true);
404 EXPECT_FALSE(backing); 403 EXPECT_FALSE(backing);
405 // The widget host should have sent a request for a repaint, and there should 404 // The widget host should have sent a request for a repaint, and there should
406 // be no paint ACK. 405 // be no paint ACK.
407 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); 406 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID));
408 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching( 407 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(
409 ViewMsg_UpdateRect_ACK::ID)); 408 ViewMsg_PaintRect_ACK::ID));
410 409
411 // Allowing the renderer to reply in time should give is a backing store. 410 // Allowing the renderer to reply in time should give is a backing store.
412 process_->sink().ClearMessages(); 411 process_->sink().ClearMessages();
413 process_->set_update_msg_should_reply(true); 412 process_->set_paint_msg_should_reply(true);
414 process_->set_update_msg_reply_flags(0); 413 process_->set_paint_msg_reply_flags(0);
415 backing = host_->GetBackingStore(true); 414 backing = host_->GetBackingStore(true);
416 EXPECT_TRUE(backing); 415 EXPECT_TRUE(backing);
417 // The widget host should NOT have sent a request for a repaint, since there 416 // The widget host should NOT have sent a request for a repaint, since there
418 // was an ACK already pending. 417 // was an ACK already pending.
419 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); 418 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID));
420 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 419 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
421 ViewMsg_UpdateRect_ACK::ID)); 420 ViewMsg_PaintRect_ACK::ID));
422 } 421 }
423 422
424 // Tests getting the backing store with the renderer sending a repaint ack. 423 // Tests getting the backing store with the renderer sending a repaint ack.
425 TEST_F(RenderWidgetHostTest, GetBackingStore_RepaintAck) { 424 TEST_F(RenderWidgetHostTest, GetBackingStore_RepaintAck) {
426 // Doing a request request with the paint message allowed should work and 425 // Doing a request request with the paint message allowed should work and
427 // the repaint ack should work. 426 // the repaint ack should work.
428 process_->set_update_msg_should_reply(true); 427 process_->set_paint_msg_should_reply(true);
429 process_->set_update_msg_reply_flags( 428 process_->set_paint_msg_reply_flags(
430 ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK); 429 ViewHostMsg_PaintRect_Flags::IS_REPAINT_ACK);
431 BackingStore* backing = host_->GetBackingStore(true); 430 BackingStore* backing = host_->GetBackingStore(true);
432 EXPECT_TRUE(backing); 431 EXPECT_TRUE(backing);
433 // We still should not have sent out a repaint request since the last flags 432 // We still should not have sent out a repaint request since the last flags
434 // didn't have the repaint ack set, and the pending flag will still be set. 433 // didn't have the repaint ack set, and the pending flag will still be set.
435 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); 434 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID));
436 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 435 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
437 ViewMsg_UpdateRect_ACK::ID)); 436 ViewMsg_PaintRect_ACK::ID));
438 437
439 // Asking again for the backing store should just re-use the existing one 438 // Asking again for the backing store should just re-use the existing one
440 // and not send any messagse. 439 // and not send any messagse.
441 process_->sink().ClearMessages(); 440 process_->sink().ClearMessages();
442 backing = host_->GetBackingStore(true); 441 backing = host_->GetBackingStore(true);
443 EXPECT_TRUE(backing); 442 EXPECT_TRUE(backing);
444 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); 443 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID));
445 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching( 444 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(
446 ViewMsg_UpdateRect_ACK::ID)); 445 ViewMsg_PaintRect_ACK::ID));
447 } 446 }
448 447
449 // Test that we don't paint when we're hidden, but we still send the ACK. Most 448 // Test that we don't paint when we're hidden, but we still send the ACK. Most
450 // of the rest of the painting is tested in the GetBackingStore* ones. 449 // of the rest of the painting is tested in the GetBackingStore* ones.
451 TEST_F(RenderWidgetHostTest, HiddenPaint) { 450 TEST_F(RenderWidgetHostTest, HiddenPaint) {
452 // Hide the widget, it should have sent out a message to the renderer. 451 // Hide the widget, it should have sent out a message to the renderer.
453 EXPECT_FALSE(host_->is_hidden_); 452 EXPECT_FALSE(host_->is_hidden_);
454 host_->WasHidden(); 453 host_->WasHidden();
455 EXPECT_TRUE(host_->is_hidden_); 454 EXPECT_TRUE(host_->is_hidden_);
456 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_WasHidden::ID)); 455 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_WasHidden::ID));
457 456
458 // Send it a paint as from the renderer. 457 // Send it a paint as from the renderer.
459 process_->sink().ClearMessages(); 458 process_->sink().ClearMessages();
460 ViewHostMsg_UpdateRect_Params params; 459 ViewHostMsg_PaintRect_Params params;
461 process_->InitUpdateRectParams(&params); 460 process_->InitPaintRectParams(&params);
462 host_->OnMsgUpdateRect(params); 461 host_->OnMsgPaintRect(params);
463 462
464 // It should have sent out the ACK. 463 // It should have sent out the ACK.
465 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 464 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
466 ViewMsg_UpdateRect_ACK::ID)); 465 ViewMsg_PaintRect_ACK::ID));
467 466
468 // Now unhide. 467 // Now unhide.
469 process_->sink().ClearMessages(); 468 process_->sink().ClearMessages();
470 host_->WasRestored(); 469 host_->WasRestored();
471 EXPECT_FALSE(host_->is_hidden_); 470 EXPECT_FALSE(host_->is_hidden_);
472 471
473 // It should have sent out a restored message with a request to paint. 472 // It should have sent out a restored message with a request to paint.
474 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching( 473 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching(
475 ViewMsg_WasRestored::ID); 474 ViewMsg_WasRestored::ID);
476 ASSERT_TRUE(restored); 475 ASSERT_TRUE(restored);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 EXPECT_EQ(ViewMsg_HandleInputEvent::ID, 547 EXPECT_EQ(ViewMsg_HandleInputEvent::ID,
549 process_->sink().GetMessageAt(0)->type()); 548 process_->sink().GetMessageAt(0)->type());
550 process_->sink().ClearMessages(); 549 process_->sink().ClearMessages();
551 550
552 // Send the simulated response from the renderer back. 551 // Send the simulated response from the renderer back.
553 SendInputEventACK(WebInputEvent::KeyUp, false); 552 SendInputEventACK(WebInputEvent::KeyUp, false);
554 553
555 EXPECT_TRUE(host_->unhandled_keyboard_event_called()); 554 EXPECT_TRUE(host_->unhandled_keyboard_event_called());
556 EXPECT_EQ(WebInputEvent::KeyUp, host_->unhandled_keyboard_event_type()); 555 EXPECT_EQ(WebInputEvent::KeyUp, host_->unhandled_keyboard_event_type());
557 } 556 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host.cc ('k') | chrome/browser/renderer_host/render_widget_host_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698