OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_controller_common.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/ui/autofill/test_popup_controller_common.h" | 8 #include "chrome/browser/ui/autofill/test_popup_controller_common.h" |
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
10 #include "ui/gfx/display.h" | 10 #include "ui/gfx/display.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 }; | 22 }; |
23 | 23 |
24 TEST_F(PopupControllerBaseTest, GetPopupBoundsTest) { | 24 TEST_F(PopupControllerBaseTest, GetPopupBoundsTest) { |
25 int desired_width = 40; | 25 int desired_width = 40; |
26 int desired_height = 16; | 26 int desired_height = 16; |
27 | 27 |
28 // Set up the visible screen space. | 28 // Set up the visible screen space. |
29 gfx::Display display(0, | 29 gfx::Display display(0, |
30 gfx::Rect(0, 0, 2 * desired_width, 2 * desired_height)); | 30 gfx::Rect(0, 0, 2 * desired_width, 2 * desired_height)); |
31 | 31 |
32 // Store the possible element bounds and the popup bounds they should result | 32 struct { |
33 // in. | 33 gfx::RectF element_bounds; |
34 std::vector<gfx::RectF> element_bounds; | 34 gfx::Rect expected_popup_bounds_ltr; |
35 std::vector<gfx::Rect> expected_popup_bounds; | 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)}, |
36 | 42 |
37 // The popup grows down and to the right. | 43 // The popup grows down and to the left when there's no room on the right. |
38 element_bounds.push_back(gfx::RectF(0, 0, 0, 0)); | 44 {gfx::RectF(2 * desired_width, 0, 5, 0), |
39 expected_popup_bounds.push_back( | 45 gfx::Rect(desired_width, 0, desired_width, desired_height)}, |
40 gfx::Rect(0, 0, desired_width, desired_height)); | |
41 | 46 |
42 // The popup grows down and to the left. | 47 // The popup grows up and to the right. |
43 element_bounds.push_back(gfx::RectF(2 * desired_width, 0, 0, 0)); | 48 {gfx::RectF(0, 2 * desired_height, 5, 0), |
44 expected_popup_bounds.push_back( | 49 gfx::Rect(0, desired_height, desired_width, desired_height)}, |
45 gfx::Rect(desired_width, 0, desired_width, desired_height)); | |
46 | 50 |
47 // The popup grows up and to the right. | 51 // The popup grows up and to the left. |
48 element_bounds.push_back(gfx::RectF(0, 2 * desired_height, 0, 0)); | 52 {gfx::RectF(2 * desired_width, 2 * desired_height, 5, 0), |
49 expected_popup_bounds.push_back( | 53 gfx::Rect(desired_width, desired_height, desired_width, desired_height)}, |
50 gfx::Rect(0, desired_height, desired_width, desired_height)); | |
51 | 54 |
52 // The popup grows up and to the left. | 55 // The popup would be partial off the top and left side of the screen. |
53 element_bounds.push_back( | 56 {gfx::RectF(-desired_width / 2, -desired_height / 2, 5, 0), |
54 gfx::RectF(2 * desired_width, 2 * desired_height, 0, 0)); | 57 gfx::Rect(0, 0, desired_width, desired_height)}, |
55 expected_popup_bounds.push_back( | |
56 gfx::Rect(desired_width, desired_height, desired_width, desired_height)); | |
57 | 58 |
58 // The popup would be partial off the top and left side of the screen. | 59 // The popup would be partially off the bottom and the right side of |
59 element_bounds.push_back( | 60 // the screen. |
60 gfx::RectF(-desired_width / 2, -desired_height / 2, 0, 0)); | 61 {gfx::RectF(desired_width * 1.5, desired_height * 1.5, 5, 0), |
61 expected_popup_bounds.push_back( | 62 gfx::Rect((desired_width * 1.5 + 5 - desired_width), |
62 gfx::Rect(0, 0, desired_width, desired_height)); | 63 (desired_height * 1.5 - desired_height), desired_width, |
| 64 desired_height)}, |
| 65 }; |
63 | 66 |
64 // The popup would be partially off the bottom and the right side of | 67 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
65 // the screen. | |
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)); | |
71 | |
72 for (size_t i = 0; i < element_bounds.size(); ++i) { | |
73 scoped_ptr<TestPopupControllerCommon> popup_controller( | 68 scoped_ptr<TestPopupControllerCommon> popup_controller( |
74 new TestPopupControllerCommon(element_bounds[i])); | 69 new TestPopupControllerCommon(test_cases[i].element_bounds, |
| 70 base::i18n::LEFT_TO_RIGHT)); |
75 popup_controller->set_display(display); | 71 popup_controller->set_display(display); |
76 gfx::Rect actual_popup_bounds = | 72 gfx::Rect actual_popup_bounds = |
77 popup_controller->GetPopupBounds(desired_width, desired_height); | 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 | 77 |
79 EXPECT_EQ(expected_popup_bounds[i].ToString(), | 78 popup_controller.reset(new TestPopupControllerCommon( |
80 actual_popup_bounds.ToString()) << | 79 test_cases[i].element_bounds, base::i18n::RIGHT_TO_LEFT)); |
81 "Popup bounds failed to match for test " << i; | 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; |
82 } | 88 } |
83 } | 89 } |
84 | 90 |
85 } // namespace autofill | 91 } // namespace autofill |
OLD | NEW |