| 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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "ui/accessibility/ax_text_utils.h" | 7 #include "ui/accessibility/ax_text_utils.h" |
| 8 | 8 |
| 9 namespace ui { | 9 namespace ui { |
| 10 | 10 |
| 11 TEST(AXTextUtils, FindAccessibleTextBoundaryLine) { | 11 TEST(AXTextUtils, FindAccessibleTextBoundaryLine) { |
| 12 const base::string16 text = base::UTF8ToUTF16("Line 1.\nLine 2\n"); | 12 const base::string16 text = base::UTF8ToUTF16("Line 1.\nLine 2\n\t"); |
| 13 const size_t text_length = text.length(); | 13 const size_t text_length = text.length(); |
| 14 std::vector<int> line_breaks; | 14 std::vector<int> line_start_offsets; |
| 15 line_breaks.push_back(7); | 15 line_start_offsets.push_back(8); |
| 16 line_breaks.push_back(14); | 16 line_start_offsets.push_back(15); |
| 17 size_t result; | 17 size_t result; |
| 18 | 18 |
| 19 | 19 |
| 20 // Basic cases. | 20 // Basic cases. |
| 21 result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 5, | 21 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 22 FORWARDS_DIRECTION); | 22 5, FORWARDS_DIRECTION); |
| 23 EXPECT_EQ(7UL, result); | 23 EXPECT_EQ(8UL, result); |
| 24 result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 9, | 24 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 25 BACKWARDS_DIRECTION); | 25 9, BACKWARDS_DIRECTION); |
| 26 EXPECT_EQ(7UL, result); | 26 EXPECT_EQ(8UL, result); |
| 27 result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 10, | 27 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 28 FORWARDS_DIRECTION); | 28 10, FORWARDS_DIRECTION); |
| 29 EXPECT_EQ(14UL, result); | 29 EXPECT_EQ(15UL, result); |
| 30 | 30 |
| 31 | 31 |
| 32 // Edge cases. | 32 // Edge cases. |
| 33 | 33 |
| 34 result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, | 34 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 35 text_length, BACKWARDS_DIRECTION); | 35 text_length, BACKWARDS_DIRECTION); |
| 36 EXPECT_EQ(14UL, result); | 36 EXPECT_EQ(15UL, result); |
| 37 | 37 |
| 38 // When the start_offset is on a line break and we are searching backwards, | 38 // When the start_offset is at the start of the next line and we are searching |
| 39 // it should return the previous line break. | 39 // backwards, it should not move. |
| 40 result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 14, | 40 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 41 BACKWARDS_DIRECTION); | 41 15, BACKWARDS_DIRECTION); |
| 42 EXPECT_EQ(7UL, result); | 42 EXPECT_EQ(15UL, result); |
| 43 | 43 |
| 44 // When the start_offset is on a line break and we are searching forwards, | 44 // When the start_offset is at a hard line break and we are searching |
| 45 // it should return the next line break. | 45 // backwards, it should return the start of the previous line. |
| 46 result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 7, | 46 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 47 FORWARDS_DIRECTION); | 47 14, BACKWARDS_DIRECTION); |
| 48 EXPECT_EQ(14UL, result); | 48 EXPECT_EQ(8UL, result); |
| 49 |
| 50 // When the start_offset is at the start of a line and we are searching |
| 51 // forwards, it should return the start of the next line. |
| 52 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 53 8, FORWARDS_DIRECTION); |
| 54 EXPECT_EQ(15UL, result); |
| 49 | 55 |
| 50 // When there is no previous line break and we are searching backwards, | 56 // When there is no previous line break and we are searching backwards, |
| 51 // it should return 0. | 57 // it should return 0. |
| 52 result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 4, | 58 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 53 BACKWARDS_DIRECTION); | 59 4, BACKWARDS_DIRECTION); |
| 54 EXPECT_EQ(0UL, result); | 60 EXPECT_EQ(0UL, result); |
| 55 | 61 |
| 56 // When we are on the last line break and we are searching forwards. | 62 // When we are at the start of the last line and we are searching forwards. |
| 57 // it should return the text length. | 63 // it should return the text length. |
| 58 result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 14, | 64 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 59 FORWARDS_DIRECTION); | 65 15, FORWARDS_DIRECTION); |
| 60 EXPECT_EQ(text_length, result); | 66 EXPECT_EQ(text_length, result); |
| 61 } | 67 } |
| 62 | 68 |
| 63 } // Namespace ui. | 69 } // Namespace ui. |
| OLD | NEW |