Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: chrome/browser/ui/autofill/popup_view_common_unittest.cc

Issue 1570783003: [Autofill] Move functions from the AutofillPopupController to AutofillPopupLayoutModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed nit Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/autofill/popup_controller_common.h" 5 #include "chrome/browser/ui/autofill/popup_view_common.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/ui/autofill/test_popup_controller_common.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
12 #include "content/public/browser/web_contents.h"
13 #include "ui/gfx/display.h" 13 #include "ui/gfx/display.h"
14 #include "ui/gfx/geometry/rect.h" 14 #include "ui/gfx/geometry/rect.h"
15 15
16 namespace autofill { 16 namespace autofill {
17 17
18 class PopupControllerBaseTest : public ChromeRenderViewHostTestHarness { 18 namespace {
19
20 // Test class which overrides specific behavior for testing.
21 class TestPopupViewCommon : public PopupViewCommon {
19 public: 22 public:
20 PopupControllerBaseTest() {} 23 explicit TestPopupViewCommon(const gfx::Display& display)
21 ~PopupControllerBaseTest() override {} 24 : display_(display) {}
25
26 gfx::Display GetDisplayNearestPoint(const gfx::Point& point,
27 gfx::NativeView container_view) override {
28 return display_;
29 }
22 30
23 private: 31 private:
24 DISALLOW_COPY_AND_ASSIGN(PopupControllerBaseTest); 32 gfx::Display display_;
25 }; 33 };
26 34
27 TEST_F(PopupControllerBaseTest, GetPopupBoundsTest) { 35 } // namespace
36
37 class PopupViewCommonTest : public ChromeRenderViewHostTestHarness {
38 public:
39 PopupViewCommonTest() {}
40 ~PopupViewCommonTest() override {}
41
42 private:
43 DISALLOW_COPY_AND_ASSIGN(PopupViewCommonTest);
44 };
45
46 TEST_F(PopupViewCommonTest, CalculatePopupBounds) {
28 int desired_width = 40; 47 int desired_width = 40;
29 int desired_height = 16; 48 int desired_height = 16;
30 49
31 // Set up the visible screen space. 50 // Set up the visible screen space.
32 gfx::Display display(0, 51 gfx::Display display(0,
33 gfx::Rect(0, 0, 2 * desired_width, 2 * desired_height)); 52 gfx::Rect(0, 0, 2 * desired_width, 2 * desired_height));
53 TestPopupViewCommon view_common(display);
34 54
35 struct { 55 struct {
36 gfx::RectF element_bounds; 56 gfx::Rect element_bounds;
37 gfx::Rect expected_popup_bounds_ltr; 57 gfx::Rect expected_popup_bounds_ltr;
38 // Non-empty only when it differs from the ltr expectation. 58 // Non-empty only when it differs from the ltr expectation.
39 gfx::Rect expected_popup_bounds_rtl; 59 gfx::Rect expected_popup_bounds_rtl;
40 } test_cases[] = { 60 } test_cases[] = {
41 // The popup grows down and to the end. 61 // The popup grows down and to the end.
42 {gfx::RectF(38, 0, 5, 0), 62 {gfx::Rect(38, 0, 5, 0), gfx::Rect(38, 0, desired_width, desired_height),
43 gfx::Rect(38, 0, desired_width, desired_height),
44 gfx::Rect(3, 0, desired_width, desired_height)}, 63 gfx::Rect(3, 0, desired_width, desired_height)},
45 64
46 // The popup grows down and to the left when there's no room on the right. 65 // The popup grows down and to the left when there's no room on the right.
47 {gfx::RectF(2 * desired_width, 0, 5, 0), 66 {gfx::Rect(2 * desired_width, 0, 5, 0),
48 gfx::Rect(desired_width, 0, desired_width, desired_height)}, 67 gfx::Rect(desired_width, 0, desired_width, desired_height)},
49 68
50 // The popup grows up and to the right. 69 // The popup grows up and to the right.
51 {gfx::RectF(0, 2 * desired_height, 5, 0), 70 {gfx::Rect(0, 2 * desired_height, 5, 0),
52 gfx::Rect(0, desired_height, desired_width, desired_height)}, 71 gfx::Rect(0, desired_height, desired_width, desired_height)},
53 72
54 // The popup grows up and to the left. 73 // The popup grows up and to the left.
55 {gfx::RectF(2 * desired_width, 2 * desired_height, 5, 0), 74 {gfx::Rect(2 * desired_width, 2 * desired_height, 5, 0),
56 gfx::Rect(desired_width, desired_height, desired_width, desired_height)}, 75 gfx::Rect(desired_width, desired_height, desired_width, desired_height)},
57 76
58 // The popup would be partial off the top and left side of the screen. 77 // The popup would be partial off the top and left side of the screen.
59 {gfx::RectF(-desired_width / 2, -desired_height / 2, 5, 0), 78 {gfx::Rect(-desired_width / 2, -desired_height / 2, 5, 0),
60 gfx::Rect(0, 0, desired_width, desired_height)}, 79 gfx::Rect(0, 0, desired_width, desired_height)},
61 80
62 // The popup would be partially off the bottom and the right side of 81 // The popup would be partially off the bottom and the right side of
63 // the screen. 82 // the screen.
64 {gfx::RectF(desired_width * 1.5, desired_height * 1.5, 5, 0), 83 {gfx::Rect(desired_width * 1.5, desired_height * 1.5, 5, 0),
65 gfx::Rect((desired_width * 1.5 + 5 - desired_width), 84 gfx::Rect((desired_width * 1.5 + 5 - desired_width),
66 (desired_height * 1.5 - desired_height), desired_width, 85 (desired_height * 1.5 - desired_height), desired_width,
67 desired_height)}, 86 desired_height)},
68 }; 87 };
69 88
70 for (size_t i = 0; i < arraysize(test_cases); ++i) { 89 for (size_t i = 0; i < arraysize(test_cases); ++i) {
71 scoped_ptr<TestPopupControllerCommon> popup_controller( 90 gfx::Rect actual_popup_bounds = view_common.CalculatePopupBounds(
72 new TestPopupControllerCommon(test_cases[i].element_bounds, 91 desired_width, desired_height, test_cases[i].element_bounds,
73 base::i18n::LEFT_TO_RIGHT)); 92 web_contents()->GetNativeView(), /* is_rtl= */ false);
74 popup_controller->set_display(display);
75 gfx::Rect actual_popup_bounds =
76 popup_controller->GetPopupBounds(desired_width, desired_height);
77 EXPECT_EQ(test_cases[i].expected_popup_bounds_ltr.ToString(), 93 EXPECT_EQ(test_cases[i].expected_popup_bounds_ltr.ToString(),
78 actual_popup_bounds.ToString()) 94 actual_popup_bounds.ToString())
79 << "Popup bounds failed to match for ltr test " << i; 95 << "Popup bounds failed to match for ltr test " << i;
80 96
81 popup_controller.reset(new TestPopupControllerCommon( 97 actual_popup_bounds = view_common.CalculatePopupBounds(
82 test_cases[i].element_bounds, base::i18n::RIGHT_TO_LEFT)); 98 desired_width, desired_height, test_cases[i].element_bounds,
83 popup_controller->set_display(display); 99 web_contents()->GetNativeView(), /* is_rtl= */ true);
84 actual_popup_bounds =
85 popup_controller->GetPopupBounds(desired_width, desired_height);
86 gfx::Rect expected_popup_bounds = test_cases[i].expected_popup_bounds_rtl; 100 gfx::Rect expected_popup_bounds = test_cases[i].expected_popup_bounds_rtl;
87 if (expected_popup_bounds.IsEmpty()) 101 if (expected_popup_bounds.IsEmpty())
88 expected_popup_bounds = test_cases[i].expected_popup_bounds_ltr; 102 expected_popup_bounds = test_cases[i].expected_popup_bounds_ltr;
89 EXPECT_EQ(expected_popup_bounds.ToString(), actual_popup_bounds.ToString()) 103 EXPECT_EQ(expected_popup_bounds.ToString(), actual_popup_bounds.ToString())
90 << "Popup bounds failed to match for rtl test " << i; 104 << "Popup bounds failed to match for rtl test " << i;
91 } 105 }
92 } 106 }
93 107
94 } // namespace autofill 108 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/popup_view_common.cc ('k') | chrome/browser/ui/autofill/test_popup_controller_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698