render_widget_test.cc revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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/files/file_path.h" 9#include "base/files/file_util.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/WebKit/public/platform/WebScreenOrientationType.h" 16#include "third_party/WebKit/public/platform/WebSize.h" 17#include "third_party/WebKit/public/web/WebView.h" 18#include "third_party/skia/include/core/SkBitmap.h" 19#include "ui/gfx/codec/jpeg_codec.h" 20#include "ui/gfx/size.h" 21#include "ui/surface/transport_dib.h" 22 23namespace content { 24 25const int RenderWidgetTest::kNumBytesPerPixel = 4; 26const int RenderWidgetTest::kLargeWidth = 1024; 27const int RenderWidgetTest::kLargeHeight = 768; 28const int RenderWidgetTest::kSmallWidth = 600; 29const int RenderWidgetTest::kSmallHeight = 450; 30const int RenderWidgetTest::kTextPositionX = 800; 31const int RenderWidgetTest::kTextPositionY = 600; 32const uint32 RenderWidgetTest::kRedARGB = 0xFFFF0000; 33 34RenderWidgetTest::RenderWidgetTest() {} 35 36void RenderWidgetTest::TestOnResize() { 37 RenderWidget* widget = static_cast<RenderViewImpl*>(view_); 38 39 // The initial bounds is empty, so setting it to the same thing should do 40 // nothing. 41 ViewMsg_Resize_Params resize_params; 42 resize_params.screen_info = blink::WebScreenInfo(); 43 resize_params.new_size = gfx::Size(); 44 resize_params.physical_backing_size = gfx::Size(); 45 resize_params.top_controls_layout_height = 0.f; 46 resize_params.resizer_rect = gfx::Rect(); 47 resize_params.is_fullscreen = false; 48 widget->OnResize(resize_params); 49 EXPECT_FALSE(widget->next_paint_is_resize_ack()); 50 51 // Setting empty physical backing size should not send the ack. 52 resize_params.new_size = gfx::Size(10, 10); 53 widget->OnResize(resize_params); 54 EXPECT_FALSE(widget->next_paint_is_resize_ack()); 55 56 // Setting the bounds to a "real" rect should send the ack. 57 render_thread_->sink().ClearMessages(); 58 gfx::Size size(100, 100); 59 resize_params.new_size = size; 60 resize_params.physical_backing_size = size; 61 widget->OnResize(resize_params); 62 EXPECT_TRUE(widget->next_paint_is_resize_ack()); 63 64 // Clear the flag. 65 // TODO(danakj): How real is this test any more? This flag is only existing 66 // for DCHECKs now. 67 widget->didCompleteSwapBuffers(); 68 69 // Setting the same size again should not send the ack. 70 widget->OnResize(resize_params); 71 EXPECT_FALSE(widget->next_paint_is_resize_ack()); 72 73 // Resetting the rect to empty should not send the ack. 74 resize_params.new_size = gfx::Size(); 75 resize_params.physical_backing_size = gfx::Size(); 76 widget->OnResize(resize_params); 77 EXPECT_FALSE(widget->next_paint_is_resize_ack()); 78 79 // Changing the screen info should not send the ack. 80 resize_params.screen_info.orientationAngle = 90; 81 widget->OnResize(resize_params); 82 EXPECT_FALSE(widget->next_paint_is_resize_ack()); 83 84 resize_params.screen_info.orientationType = 85 blink::WebScreenOrientationPortraitPrimary; 86 widget->OnResize(resize_params); 87 EXPECT_FALSE(widget->next_paint_is_resize_ack()); 88} 89 90} // namespace content 91