• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/WebScreenOrientationType.h"
17 #include "third_party/WebKit/public/platform/WebSize.h"
18 #include "third_party/WebKit/public/web/WebView.h"
19 #include "ui/gfx/codec/jpeg_codec.h"
20 #include "ui/gfx/size.h"
21 #include "ui/surface/transport_dib.h"
22 
23 namespace content {
24 
25 const int RenderWidgetTest::kNumBytesPerPixel = 4;
26 const int RenderWidgetTest::kLargeWidth = 1024;
27 const int RenderWidgetTest::kLargeHeight = 768;
28 const int RenderWidgetTest::kSmallWidth = 600;
29 const int RenderWidgetTest::kSmallHeight = 450;
30 const int RenderWidgetTest::kTextPositionX = 800;
31 const int RenderWidgetTest::kTextPositionY = 600;
32 const uint32 RenderWidgetTest::kRedARGB = 0xFFFF0000;
33 
RenderWidgetTest()34 RenderWidgetTest::RenderWidgetTest() {}
35 
TestOnResize()36 void 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.overdraw_bottom_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