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 "base/strings/utf_string_conversions.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/accessibility/ax_text_utils.h"
11 TEST(AXTextUtils
, FindAccessibleTextBoundaryLine
) {
12 const base::string16 text
= base::UTF8ToUTF16("Line 1.\nLine 2\n");
13 const size_t text_length
= text
.length();
14 std::vector
<int> line_breaks
;
15 line_breaks
.push_back(7);
16 line_breaks
.push_back(14);
21 result
= FindAccessibleTextBoundary(text
, line_breaks
, LINE_BOUNDARY
, 5,
23 EXPECT_EQ(7UL, result
);
24 result
= FindAccessibleTextBoundary(text
, line_breaks
, LINE_BOUNDARY
, 9,
26 EXPECT_EQ(7UL, result
);
27 result
= FindAccessibleTextBoundary(text
, line_breaks
, LINE_BOUNDARY
, 10,
29 EXPECT_EQ(14UL, result
);
34 result
= FindAccessibleTextBoundary(text
, line_breaks
, LINE_BOUNDARY
,
35 text_length
, BACKWARDS_DIRECTION
);
36 EXPECT_EQ(14UL, result
);
38 // When the start_offset is on a line break and we are searching backwards,
39 // it should return the previous line break.
40 result
= FindAccessibleTextBoundary(text
, line_breaks
, LINE_BOUNDARY
, 14,
42 EXPECT_EQ(7UL, result
);
44 // When the start_offset is on a line break and we are searching forwards,
45 // it should return the next line break.
46 result
= FindAccessibleTextBoundary(text
, line_breaks
, LINE_BOUNDARY
, 7,
48 EXPECT_EQ(14UL, result
);
50 // When there is no previous line break and we are searching backwards,
51 // it should return 0.
52 result
= FindAccessibleTextBoundary(text
, line_breaks
, LINE_BOUNDARY
, 4,
54 EXPECT_EQ(0UL, result
);
56 // When we are on the last line break and we are searching forwards.
57 // it should return the text length.
58 result
= FindAccessibleTextBoundary(text
, line_breaks
, LINE_BOUNDARY
, 14,
60 EXPECT_EQ(text_length
, result
);