1 // Copyright (c) 2010 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/chromeos/ui/accessibility_focus_ring_controller.h"
7 #include "testing/gtest/include/gtest/gtest.h"
11 class TestableAccessibilityFocusRingController
12 : public AccessibilityFocusRingController
{
14 TestableAccessibilityFocusRingController() {
15 // By default use an easy round number for testing.
18 ~TestableAccessibilityFocusRingController() override
{}
20 void RectsToRings(const std::vector
<gfx::Rect
>& rects
,
21 std::vector
<AccessibilityFocusRing
>* rings
) const {
22 AccessibilityFocusRingController::RectsToRings(rects
, rings
);
25 int GetMargin() const override
{ return margin_
; }
31 class AccessibilityFocusRingControllerTest
: public testing::Test
{
33 AccessibilityFocusRingControllerTest() {}
34 ~AccessibilityFocusRingControllerTest() override
{}
37 gfx::Rect
AddMargin(gfx::Rect r
) {
38 r
.Inset(-controller_
.GetMargin(), -controller_
.GetMargin());
42 TestableAccessibilityFocusRingController controller_
;
45 TEST_F(AccessibilityFocusRingControllerTest
, RectsToRingsSimpleBoundsCheck
) {
46 // Easy sanity check. Given a single rectangle, make sure we get back
47 // a focus ring with the same bounds.
48 std::vector
<gfx::Rect
> rects
;
49 rects
.push_back(gfx::Rect(10, 30, 70, 150));
50 std::vector
<AccessibilityFocusRing
> rings
;
51 controller_
.RectsToRings(rects
, &rings
);
52 ASSERT_EQ(1U, rings
.size());
53 ASSERT_EQ(AddMargin(rects
[0]), rings
[0].GetBounds());
56 TEST_F(AccessibilityFocusRingControllerTest
, RectsToRingsVerticalStack
) {
57 // Given two rects, one on top of each other, we should get back a
58 // focus ring that surrounds them both.
59 std::vector
<gfx::Rect
> rects
;
60 rects
.push_back(gfx::Rect(10, 10, 60, 30));
61 rects
.push_back(gfx::Rect(10, 40, 60, 30));
62 std::vector
<AccessibilityFocusRing
> rings
;
63 controller_
.RectsToRings(rects
, &rings
);
64 ASSERT_EQ(1U, rings
.size());
65 ASSERT_EQ(AddMargin(gfx::Rect(10, 10, 60, 60)), rings
[0].GetBounds());
68 TEST_F(AccessibilityFocusRingControllerTest
, RectsToRingsHorizontalStack
) {
69 // Given two rects, one next to the other horizontally, we should get back a
70 // focus ring that surrounds them both.
71 std::vector
<gfx::Rect
> rects
;
72 rects
.push_back(gfx::Rect(10, 10, 60, 30));
73 rects
.push_back(gfx::Rect(70, 10, 60, 30));
74 std::vector
<AccessibilityFocusRing
> rings
;
75 controller_
.RectsToRings(rects
, &rings
);
76 ASSERT_EQ(1U, rings
.size());
77 ASSERT_EQ(AddMargin(gfx::Rect(10, 10, 120, 30)), rings
[0].GetBounds());
80 TEST_F(AccessibilityFocusRingControllerTest
, RectsToRingsParagraphShape
) {
81 // Given a simple paragraph shape, make sure we get something that
82 // outlines it correctly.
83 std::vector
<gfx::Rect
> rects
;
84 rects
.push_back(gfx::Rect(10, 10, 180, 80));
85 rects
.push_back(gfx::Rect(10, 110, 580, 280));
86 rects
.push_back(gfx::Rect(410, 410, 180, 80));
87 std::vector
<AccessibilityFocusRing
> rings
;
88 controller_
.RectsToRings(rects
, &rings
);
89 ASSERT_EQ(1U, rings
.size());
90 EXPECT_EQ(gfx::Rect(0, 0, 600, 500), rings
[0].GetBounds());
92 const gfx::Point
* points
= rings
[0].points
;
93 EXPECT_EQ(gfx::Point(0, 90), points
[0]);
94 EXPECT_EQ(gfx::Point(0, 10), points
[1]);
95 EXPECT_EQ(gfx::Point(0, 0), points
[2]);
96 EXPECT_EQ(gfx::Point(10, 0), points
[3]);
97 EXPECT_EQ(gfx::Point(190, 0), points
[4]);
98 EXPECT_EQ(gfx::Point(200, 0), points
[5]);
99 EXPECT_EQ(gfx::Point(200, 10), points
[6]);
100 EXPECT_EQ(gfx::Point(200, 90), points
[7]);
101 EXPECT_EQ(gfx::Point(200, 100), points
[8]);
102 EXPECT_EQ(gfx::Point(210, 100), points
[9]);
103 EXPECT_EQ(gfx::Point(590, 100), points
[10]);
104 EXPECT_EQ(gfx::Point(600, 100), points
[11]);
105 EXPECT_EQ(gfx::Point(600, 110), points
[12]);
106 EXPECT_EQ(gfx::Point(600, 390), points
[13]);
107 EXPECT_EQ(gfx::Point(600, 400), points
[14]);
108 EXPECT_EQ(gfx::Point(600, 400), points
[15]);
109 EXPECT_EQ(gfx::Point(600, 400), points
[16]);
110 EXPECT_EQ(gfx::Point(600, 400), points
[17]);
111 EXPECT_EQ(gfx::Point(600, 410), points
[18]);
112 EXPECT_EQ(gfx::Point(600, 490), points
[19]);
113 EXPECT_EQ(gfx::Point(600, 500), points
[20]);
114 EXPECT_EQ(gfx::Point(590, 500), points
[21]);
115 EXPECT_EQ(gfx::Point(410, 500), points
[22]);
116 EXPECT_EQ(gfx::Point(400, 500), points
[23]);
117 EXPECT_EQ(gfx::Point(400, 490), points
[24]);
118 EXPECT_EQ(gfx::Point(400, 410), points
[25]);
119 EXPECT_EQ(gfx::Point(400, 400), points
[26]);
120 EXPECT_EQ(gfx::Point(390, 400), points
[27]);
121 EXPECT_EQ(gfx::Point(10, 400), points
[28]);
122 EXPECT_EQ(gfx::Point(0, 400), points
[29]);
123 EXPECT_EQ(gfx::Point(0, 390), points
[30]);
124 EXPECT_EQ(gfx::Point(0, 110), points
[31]);
125 EXPECT_EQ(gfx::Point(0, 100), points
[32]);
126 EXPECT_EQ(gfx::Point(0, 100), points
[33]);
127 EXPECT_EQ(gfx::Point(0, 100), points
[34]);
128 EXPECT_EQ(gfx::Point(0, 100), points
[35]);
131 } // namespace chromeos