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

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

Issue 118420: Adds kind-of-live thumbnail generation for a potential tab switcher. This... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months 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"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 ViewHostMsg_PaintRect message(render_widget_id, params); 93 ViewHostMsg_PaintRect message(render_widget_id, params);
94 *msg = message; 94 *msg = message;
95 return true; 95 return true;
96 } 96 }
97 97
98 // TestView -------------------------------------------------------------------- 98 // TestView --------------------------------------------------------------------
99 99
100 // This test view allows us to specify the size. 100 // This test view allows us to specify the size.
101 class TestView : public TestRenderWidgetHostView { 101 class TestView : public TestRenderWidgetHostView {
102 public: 102 public:
103 TestView() {} 103 TestView(RenderWidgetHost* rwh) : TestRenderWidgetHostView(rwh) {}
104 104
105 // Sets the bounds returned by GetViewBounds. 105 // Sets the bounds returned by GetViewBounds.
106 void set_bounds(const gfx::Rect& bounds) { 106 void set_bounds(const gfx::Rect& bounds) {
107 bounds_ = bounds; 107 bounds_ = bounds;
108 } 108 }
109 109
110 // RenderWidgetHostView override. 110 // RenderWidgetHostView override.
111 virtual gfx::Rect GetViewBounds() const { 111 virtual gfx::Rect GetViewBounds() const {
112 return bounds_; 112 return bounds_;
113 } 113 }
114 114
115 BackingStore* AllocBackingStore(const gfx::Size& size) {
116 return new BackingStore(size);
117 }
118
119 protected: 115 protected:
120 gfx::Rect bounds_; 116 gfx::Rect bounds_;
121 DISALLOW_COPY_AND_ASSIGN(TestView); 117 DISALLOW_COPY_AND_ASSIGN(TestView);
122 }; 118 };
123 119
124 // MockRenderWidgetHostTest ---------------------------------------------------- 120 // MockRenderWidgetHostTest ----------------------------------------------------
125 121
126 class MockRenderWidgetHost : public RenderWidgetHost { 122 class MockRenderWidgetHost : public RenderWidgetHost {
127 public: 123 public:
128 MockRenderWidgetHost(RenderProcessHost* process, int routing_id) 124 MockRenderWidgetHost(RenderProcessHost* process, int routing_id)
(...skipping 24 matching lines...) Expand all
153 } 149 }
154 ~RenderWidgetHostTest() { 150 ~RenderWidgetHostTest() {
155 } 151 }
156 152
157 protected: 153 protected:
158 // testing::Test 154 // testing::Test
159 void SetUp() { 155 void SetUp() {
160 profile_.reset(new TestingProfile()); 156 profile_.reset(new TestingProfile());
161 process_ = new RenderWidgetHostProcess(profile_.get()); 157 process_ = new RenderWidgetHostProcess(profile_.get());
162 host_.reset(new MockRenderWidgetHost(process_, 1)); 158 host_.reset(new MockRenderWidgetHost(process_, 1));
163 view_.reset(new TestView); 159 view_.reset(new TestView(host_.get()));
164 host_->set_view(view_.get()); 160 host_->set_view(view_.get());
165 host_->Init(); 161 host_->Init();
166 } 162 }
167 void TearDown() { 163 void TearDown() {
168 view_.reset(); 164 view_.reset();
169 host_.reset(); 165 host_.reset();
170 process_ = NULL; 166 process_ = NULL;
171 profile_.reset(); 167 profile_.reset();
172 168
173 // Process all pending tasks to avoid leaks. 169 // Process all pending tasks to avoid leaks.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // could test that, but it appears that would mean painting everything twice 292 // could test that, but it appears that would mean painting everything twice
297 // since windows HDC structures are opaque. 293 // since windows HDC structures are opaque.
298 } 294 }
299 295
300 // Tests getting the backing store with the renderer not setting repaint ack 296 // Tests getting the backing store with the renderer not setting repaint ack
301 // flags. 297 // flags.
302 TEST_F(RenderWidgetHostTest, GetBackingStore_NoRepaintAck) { 298 TEST_F(RenderWidgetHostTest, GetBackingStore_NoRepaintAck) {
303 // We don't currently have a backing store, and if the renderer doesn't send 299 // We don't currently have a backing store, and if the renderer doesn't send
304 // one in time, we should get nothing. 300 // one in time, we should get nothing.
305 process_->set_paint_msg_should_reply(false); 301 process_->set_paint_msg_should_reply(false);
306 BackingStore* backing = host_->GetBackingStore(); 302 BackingStore* backing = host_->GetBackingStore(true);
307 EXPECT_FALSE(backing); 303 EXPECT_FALSE(backing);
308 // The widget host should have sent a request for a repaint, and there should 304 // The widget host should have sent a request for a repaint, and there should
309 // be no paint ACK. 305 // be no paint ACK.
310 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); 306 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID));
311 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching( 307 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(
312 ViewMsg_PaintRect_ACK::ID)); 308 ViewMsg_PaintRect_ACK::ID));
313 309
314 // Allowing the renderer to reply in time should give is a backing store. 310 // Allowing the renderer to reply in time should give is a backing store.
315 process_->sink().ClearMessages(); 311 process_->sink().ClearMessages();
316 process_->set_paint_msg_should_reply(true); 312 process_->set_paint_msg_should_reply(true);
317 process_->set_paint_msg_reply_flags(0); 313 process_->set_paint_msg_reply_flags(0);
318 backing = host_->GetBackingStore(); 314 backing = host_->GetBackingStore(true);
319 EXPECT_TRUE(backing); 315 EXPECT_TRUE(backing);
320 // The widget host should NOT have sent a request for a repaint, since there 316 // The widget host should NOT have sent a request for a repaint, since there
321 // was an ACK already pending. 317 // was an ACK already pending.
322 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); 318 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID));
323 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 319 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
324 ViewMsg_PaintRect_ACK::ID)); 320 ViewMsg_PaintRect_ACK::ID));
325 } 321 }
326 322
327 // Tests getting the backing store with the renderer sending a repaint ack. 323 // Tests getting the backing store with the renderer sending a repaint ack.
328 TEST_F(RenderWidgetHostTest, GetBackingStore_RepaintAck) { 324 TEST_F(RenderWidgetHostTest, GetBackingStore_RepaintAck) {
329 // Doing a request request with the paint message allowed should work and 325 // Doing a request request with the paint message allowed should work and
330 // the repaint ack should work. 326 // the repaint ack should work.
331 process_->set_paint_msg_should_reply(true); 327 process_->set_paint_msg_should_reply(true);
332 process_->set_paint_msg_reply_flags( 328 process_->set_paint_msg_reply_flags(
333 ViewHostMsg_PaintRect_Flags::IS_REPAINT_ACK); 329 ViewHostMsg_PaintRect_Flags::IS_REPAINT_ACK);
334 BackingStore* backing = host_->GetBackingStore(); 330 BackingStore* backing = host_->GetBackingStore(true);
335 EXPECT_TRUE(backing); 331 EXPECT_TRUE(backing);
336 // We still should not have sent out a repaint request since the last flags 332 // We still should not have sent out a repaint request since the last flags
337 // didn't have the repaint ack set, and the pending flag will still be set. 333 // didn't have the repaint ack set, and the pending flag will still be set.
338 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); 334 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID));
339 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 335 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
340 ViewMsg_PaintRect_ACK::ID)); 336 ViewMsg_PaintRect_ACK::ID));
341 337
342 // Asking again for the backing store should just re-use the existing one 338 // Asking again for the backing store should just re-use the existing one
343 // and not send any messagse. 339 // and not send any messagse.
344 process_->sink().ClearMessages(); 340 process_->sink().ClearMessages();
345 backing = host_->GetBackingStore(); 341 backing = host_->GetBackingStore(true);
346 EXPECT_TRUE(backing); 342 EXPECT_TRUE(backing);
347 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); 343 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID));
348 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching( 344 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(
349 ViewMsg_PaintRect_ACK::ID)); 345 ViewMsg_PaintRect_ACK::ID));
350 } 346 }
351 347
352 // Test that we don't paint when we're hidden, but we still send the ACK. Most 348 // Test that we don't paint when we're hidden, but we still send the ACK. Most
353 // of the rest of the painting is tested in the GetBackingStore* ones. 349 // of the rest of the painting is tested in the GetBackingStore* ones.
354 TEST_F(RenderWidgetHostTest, HiddenPaint) { 350 TEST_F(RenderWidgetHostTest, HiddenPaint) {
355 // Hide the widget, it should have sent out a message to the renderer. 351 // Hide the widget, it should have sent out a message to the renderer.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 TEST_F(RenderWidgetHostTest, IgnoreKeyEventsWeDidntSend) { 404 TEST_F(RenderWidgetHostTest, IgnoreKeyEventsWeDidntSend) {
409 // Send a simulated, unrequested key response. We should ignore this. 405 // Send a simulated, unrequested key response. We should ignore this.
410 scoped_ptr<IPC::Message> response( 406 scoped_ptr<IPC::Message> response(
411 new ViewHostMsg_HandleInputEvent_ACK(0)); 407 new ViewHostMsg_HandleInputEvent_ACK(0));
412 response->WriteInt(WebInputEvent::KeyDown); 408 response->WriteInt(WebInputEvent::KeyDown);
413 response->WriteBool(false); 409 response->WriteBool(false);
414 host_->OnMessageReceived(*response); 410 host_->OnMessageReceived(*response);
415 411
416 EXPECT_FALSE(host_->unhandled_keyboard_event_called()); 412 EXPECT_FALSE(host_->unhandled_keyboard_event_called());
417 } 413 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698