render_widget_test.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 3// found in the LICENSE file. 4 5#include "content/public/test/render_widget_test.h" 6 7#include "base/basictypes.h" 8#include "base/file_util.h" 9#include "base/files/file_path.h" 10#include "base/memory/ref_counted_memory.h" 11#include "base/strings/stringprintf.h" 12#include "content/common/view_messages.h" 13#include "content/renderer/render_view_impl.h" 14#include "testing/gtest/include/gtest/gtest.h" 15#include "third_party/skia/include/core/SkBitmap.h" 16#include "third_party/WebKit/public/platform/WebSize.h" 17#include "third_party/WebKit/public/web/WebView.h" 18#include "ui/gfx/codec/jpeg_codec.h" 19#include "ui/gfx/size.h" 20#include "ui/surface/transport_dib.h" 21 22namespace content { 23 24const int RenderWidgetTest::kNumBytesPerPixel = 4; 25const int RenderWidgetTest::kLargeWidth = 1024; 26const int RenderWidgetTest::kLargeHeight = 768; 27const int RenderWidgetTest::kSmallWidth = 600; 28const int RenderWidgetTest::kSmallHeight = 450; 29const int RenderWidgetTest::kTextPositionX = 800; 30const int RenderWidgetTest::kTextPositionY = 600; 31const uint32 RenderWidgetTest::kRedARGB = 0xFFFF0000; 32 33RenderWidgetTest::RenderWidgetTest() {} 34 35void RenderWidgetTest::TestOnResize() { 36 RenderWidget* widget = static_cast<RenderViewImpl*>(view_); 37 38 // The initial bounds is empty, so setting it to the same thing should do 39 // nothing. 40 ViewMsg_Resize_Params resize_params; 41 resize_params.screen_info = blink::WebScreenInfo(); 42 resize_params.new_size = gfx::Size(); 43 resize_params.physical_backing_size = gfx::Size(); 44 resize_params.overdraw_bottom_height = 0.f; 45 resize_params.resizer_rect = gfx::Rect(); 46 resize_params.is_fullscreen = false; 47 widget->OnResize(resize_params); 48 EXPECT_FALSE(widget->next_paint_is_resize_ack()); 49 50 // Setting empty physical backing size should not send the ack. 51 resize_params.new_size = gfx::Size(10, 10); 52 widget->OnResize(resize_params); 53 EXPECT_FALSE(widget->next_paint_is_resize_ack()); 54 55 // Setting the bounds to a "real" rect should send the ack. 56 render_thread_->sink().ClearMessages(); 57 gfx::Size size(100, 100); 58 resize_params.new_size = size; 59 resize_params.physical_backing_size = size; 60 widget->OnResize(resize_params); 61 EXPECT_TRUE(widget->next_paint_is_resize_ack()); 62 widget->DoDeferredUpdate(); 63 ProcessPendingMessages(); 64 65 const ViewHostMsg_UpdateRect* msg = 66 static_cast<const ViewHostMsg_UpdateRect*>( 67 render_thread_->sink().GetUniqueMessageMatching( 68 ViewHostMsg_UpdateRect::ID)); 69 ASSERT_TRUE(msg); 70 ViewHostMsg_UpdateRect::Schema::Param update_rect_params; 71 EXPECT_TRUE(ViewHostMsg_UpdateRect::Read(msg, &update_rect_params)); 72 EXPECT_TRUE(ViewHostMsg_UpdateRect_Flags::is_resize_ack( 73 update_rect_params.a.flags)); 74 EXPECT_EQ(size, 75 update_rect_params.a.view_size); 76 render_thread_->sink().ClearMessages(); 77 78 // Setting the same size again should not send the ack. 79 widget->OnResize(resize_params); 80 EXPECT_FALSE(widget->next_paint_is_resize_ack()); 81 82 // Resetting the rect to empty should not send the ack. 83 resize_params.new_size = gfx::Size(); 84 resize_params.physical_backing_size = gfx::Size(); 85 widget->OnResize(resize_params); 86 EXPECT_FALSE(widget->next_paint_is_resize_ack()); 87} 88 89} // namespace content 90