Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / autofill / popup_controller_common_unittest.cc
blob5e755ae713f7e8df732e97c900a80d563e112520
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"
13 namespace autofill {
15 class PopupControllerBaseTest : public ChromeRenderViewHostTestHarness {
16 public:
17 PopupControllerBaseTest() {}
18 ~PopupControllerBaseTest() override {}
20 private:
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 struct {
33 gfx::RectF element_bounds;
34 gfx::Rect expected_popup_bounds_ltr;
35 // Non-empty only when it differs from the ltr expectation.
36 gfx::Rect expected_popup_bounds_rtl;
37 } test_cases[] = {
38 // The popup grows down and to the end.
39 {gfx::RectF(38, 0, 5, 0),
40 gfx::Rect(38, 0, desired_width, desired_height),
41 gfx::Rect(3, 0, desired_width, desired_height)},
43 // The popup grows down and to the left when there's no room on the right.
44 {gfx::RectF(2 * desired_width, 0, 5, 0),
45 gfx::Rect(desired_width, 0, desired_width, desired_height)},
47 // The popup grows up and to the right.
48 {gfx::RectF(0, 2 * desired_height, 5, 0),
49 gfx::Rect(0, desired_height, desired_width, desired_height)},
51 // The popup grows up and to the left.
52 {gfx::RectF(2 * desired_width, 2 * desired_height, 5, 0),
53 gfx::Rect(desired_width, desired_height, desired_width, desired_height)},
55 // The popup would be partial off the top and left side of the screen.
56 {gfx::RectF(-desired_width / 2, -desired_height / 2, 5, 0),
57 gfx::Rect(0, 0, desired_width, desired_height)},
59 // The popup would be partially off the bottom and the right side of
60 // the screen.
61 {gfx::RectF(desired_width * 1.5, desired_height * 1.5, 5, 0),
62 gfx::Rect((desired_width * 1.5 + 5 - desired_width),
63 (desired_height * 1.5 - desired_height), desired_width,
64 desired_height)},
67 for (size_t i = 0; i < arraysize(test_cases); ++i) {
68 scoped_ptr<TestPopupControllerCommon> popup_controller(
69 new TestPopupControllerCommon(test_cases[i].element_bounds,
70 base::i18n::LEFT_TO_RIGHT));
71 popup_controller->set_display(display);
72 gfx::Rect actual_popup_bounds =
73 popup_controller->GetPopupBounds(desired_width, desired_height);
74 EXPECT_EQ(test_cases[i].expected_popup_bounds_ltr.ToString(),
75 actual_popup_bounds.ToString())
76 << "Popup bounds failed to match for ltr test " << i;
78 popup_controller.reset(new TestPopupControllerCommon(
79 test_cases[i].element_bounds, base::i18n::RIGHT_TO_LEFT));
80 popup_controller->set_display(display);
81 actual_popup_bounds =
82 popup_controller->GetPopupBounds(desired_width, desired_height);
83 gfx::Rect expected_popup_bounds = test_cases[i].expected_popup_bounds_rtl;
84 if (expected_popup_bounds.IsEmpty())
85 expected_popup_bounds = test_cases[i].expected_popup_bounds_ltr;
86 EXPECT_EQ(expected_popup_bounds.ToString(), actual_popup_bounds.ToString())
87 << "Popup bounds failed to match for rtl test " << i;
91 } // namespace autofill