| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/accessibility/ax_text_utils.h" | 9 #include "ui/accessibility/ax_text_utils.h" |
| 10 | 10 |
| 11 namespace ui { | 11 namespace ui { |
| 12 | 12 |
| 13 TEST(AXTextUtils, FindAccessibleTextBoundaryWord) { |
| 14 const base::string16 text = |
| 15 base::UTF8ToUTF16("Hello there.This/is\ntesting."); |
| 16 const size_t text_length = text.length(); |
| 17 std::vector<int> line_start_offsets; |
| 18 line_start_offsets.push_back(19); |
| 19 size_t result; |
| 20 |
| 21 result = FindAccessibleTextBoundary(text, line_start_offsets, WORD_BOUNDARY, |
| 22 0, FORWARDS_DIRECTION); |
| 23 EXPECT_EQ(6UL, result); |
| 24 result = FindAccessibleTextBoundary(text, line_start_offsets, WORD_BOUNDARY, |
| 25 5, BACKWARDS_DIRECTION); |
| 26 EXPECT_EQ(0UL, result); |
| 27 result = FindAccessibleTextBoundary(text, line_start_offsets, WORD_BOUNDARY, |
| 28 6, FORWARDS_DIRECTION); |
| 29 EXPECT_EQ(12UL, result); |
| 30 result = FindAccessibleTextBoundary(text, line_start_offsets, WORD_BOUNDARY, |
| 31 11, BACKWARDS_DIRECTION); |
| 32 EXPECT_EQ(6UL, result); |
| 33 result = FindAccessibleTextBoundary(text, line_start_offsets, WORD_BOUNDARY, |
| 34 12, BACKWARDS_DIRECTION); |
| 35 EXPECT_EQ(12UL, result); |
| 36 result = FindAccessibleTextBoundary(text, line_start_offsets, WORD_BOUNDARY, |
| 37 15, FORWARDS_DIRECTION); |
| 38 EXPECT_EQ(17UL, result); |
| 39 result = FindAccessibleTextBoundary(text, line_start_offsets, WORD_BOUNDARY, |
| 40 15, BACKWARDS_DIRECTION); |
| 41 EXPECT_EQ(12UL, result); |
| 42 result = FindAccessibleTextBoundary(text, line_start_offsets, WORD_BOUNDARY, |
| 43 16, FORWARDS_DIRECTION); |
| 44 EXPECT_EQ(17UL, result); |
| 45 result = FindAccessibleTextBoundary(text, line_start_offsets, WORD_BOUNDARY, |
| 46 17, FORWARDS_DIRECTION); |
| 47 EXPECT_EQ(20UL, result); |
| 48 result = FindAccessibleTextBoundary(text, line_start_offsets, WORD_BOUNDARY, |
| 49 20, FORWARDS_DIRECTION); |
| 50 EXPECT_EQ(text_length, result); |
| 51 result = FindAccessibleTextBoundary(text, line_start_offsets, WORD_BOUNDARY, |
| 52 text_length, BACKWARDS_DIRECTION); |
| 53 EXPECT_EQ(20UL, result); |
| 54 } |
| 55 |
| 13 TEST(AXTextUtils, FindAccessibleTextBoundaryLine) { | 56 TEST(AXTextUtils, FindAccessibleTextBoundaryLine) { |
| 14 const base::string16 text = base::UTF8ToUTF16("Line 1.\nLine 2\n\t"); | 57 const base::string16 text = base::UTF8ToUTF16("Line 1.\nLine 2\n\t"); |
| 15 const size_t text_length = text.length(); | 58 const size_t text_length = text.length(); |
| 16 std::vector<int> line_start_offsets; | 59 std::vector<int> line_start_offsets; |
| 17 line_start_offsets.push_back(8); | 60 line_start_offsets.push_back(8); |
| 18 line_start_offsets.push_back(15); | 61 line_start_offsets.push_back(15); |
| 19 size_t result; | 62 size_t result; |
| 20 | 63 |
| 21 | |
| 22 // Basic cases. | 64 // Basic cases. |
| 23 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, | 65 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 24 5, FORWARDS_DIRECTION); | 66 5, FORWARDS_DIRECTION); |
| 25 EXPECT_EQ(8UL, result); | 67 EXPECT_EQ(8UL, result); |
| 26 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, | 68 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 27 9, BACKWARDS_DIRECTION); | 69 9, BACKWARDS_DIRECTION); |
| 28 EXPECT_EQ(8UL, result); | 70 EXPECT_EQ(8UL, result); |
| 29 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, | 71 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 30 10, FORWARDS_DIRECTION); | 72 10, FORWARDS_DIRECTION); |
| 31 EXPECT_EQ(15UL, result); | 73 EXPECT_EQ(15UL, result); |
| 32 | 74 |
| 33 | |
| 34 // Edge cases. | 75 // Edge cases. |
| 35 | |
| 36 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, | 76 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 37 text_length, BACKWARDS_DIRECTION); | 77 text_length, BACKWARDS_DIRECTION); |
| 38 EXPECT_EQ(15UL, result); | 78 EXPECT_EQ(15UL, result); |
| 39 | 79 |
| 40 // When the start_offset is at the start of the next line and we are searching | 80 // When the start_offset is at the start of the next line and we are searching |
| 41 // backwards, it should not move. | 81 // backwards, it should not move. |
| 42 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, | 82 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 43 15, BACKWARDS_DIRECTION); | 83 15, BACKWARDS_DIRECTION); |
| 44 EXPECT_EQ(15UL, result); | 84 EXPECT_EQ(15UL, result); |
| 45 | 85 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 61 4, BACKWARDS_DIRECTION); | 101 4, BACKWARDS_DIRECTION); |
| 62 EXPECT_EQ(0UL, result); | 102 EXPECT_EQ(0UL, result); |
| 63 | 103 |
| 64 // When we are at the start of the last line and we are searching forwards. | 104 // When we are at the start of the last line and we are searching forwards. |
| 65 // it should return the text length. | 105 // it should return the text length. |
| 66 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, | 106 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, |
| 67 15, FORWARDS_DIRECTION); | 107 15, FORWARDS_DIRECTION); |
| 68 EXPECT_EQ(text_length, result); | 108 EXPECT_EQ(text_length, result); |
| 69 } | 109 } |
| 70 | 110 |
| 71 } // Namespace ui. | 111 } // namespace ui |
| OLD | NEW |