1 // Copyright 2014 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.
5 #include "chrome/browser/ui/autofill/popup_controller_common.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/ui/autofill/test_popup_controller_common.h"
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
10 #include "ui/gfx/display.h"
11 #include "ui/gfx/geometry/rect.h"
15 class PopupControllerBaseTest
: public ChromeRenderViewHostTestHarness
{
17 PopupControllerBaseTest() {}
18 ~PopupControllerBaseTest() override
{}
21 DISALLOW_COPY_AND_ASSIGN(PopupControllerBaseTest
);
24 TEST_F(PopupControllerBaseTest
, GetPopupBoundsTest
) {
25 int desired_width
= 40;
26 int desired_height
= 16;
28 // Set up the visible screen space.
29 gfx::Display
display(0,
30 gfx::Rect(0, 0, 2 * desired_width
, 2 * desired_height
));
32 // Store the possible element bounds and the popup bounds they should result
34 std::vector
<gfx::RectF
> element_bounds
;
35 std::vector
<gfx::Rect
> expected_popup_bounds
;
37 // The popup grows down and to the right.
38 element_bounds
.push_back(gfx::RectF(0, 0, 0, 0));
39 expected_popup_bounds
.push_back(
40 gfx::Rect(0, 0, desired_width
, desired_height
));
42 // The popup grows down and to the left.
43 element_bounds
.push_back(gfx::RectF(2 * desired_width
, 0, 0, 0));
44 expected_popup_bounds
.push_back(
45 gfx::Rect(desired_width
, 0, desired_width
, desired_height
));
47 // The popup grows up and to the right.
48 element_bounds
.push_back(gfx::RectF(0, 2 * desired_height
, 0, 0));
49 expected_popup_bounds
.push_back(
50 gfx::Rect(0, desired_height
, desired_width
, desired_height
));
52 // The popup grows up and to the left.
53 element_bounds
.push_back(
54 gfx::RectF(2 * desired_width
, 2 * desired_height
, 0, 0));
55 expected_popup_bounds
.push_back(
56 gfx::Rect(desired_width
, desired_height
, desired_width
, desired_height
));
58 // The popup would be partial off the top and left side of the screen.
59 element_bounds
.push_back(
60 gfx::RectF(-desired_width
/ 2, -desired_height
/ 2, 0, 0));
61 expected_popup_bounds
.push_back(
62 gfx::Rect(0, 0, desired_width
, desired_height
));
64 // The popup would be partially off the bottom and the right side of
66 element_bounds
.push_back(
67 gfx::RectF(desired_width
* 1.5, desired_height
* 1.5, 0, 0));
68 expected_popup_bounds
.push_back(
69 gfx::Rect((desired_width
+ 1) / 2, (desired_height
+ 1) / 2,
70 desired_width
, desired_height
));
72 for (size_t i
= 0; i
< element_bounds
.size(); ++i
) {
73 scoped_ptr
<TestPopupControllerCommon
> popup_controller(
74 new TestPopupControllerCommon(element_bounds
[i
]));
75 popup_controller
->set_display(display
);
76 gfx::Rect actual_popup_bounds
=
77 popup_controller
->GetPopupBounds(desired_width
, desired_height
);
79 EXPECT_EQ(expected_popup_bounds
[i
].ToString(),
80 actual_popup_bounds
.ToString()) <<
81 "Popup bounds failed to match for test " << i
;
85 } // namespace autofill