Move VariationsRegistrySyncerWin to ChromeVariationsServiceClient
[chromium-blink-merge.git] / ui / accessibility / ax_text_utils_unittest.cc
blob806401bfd91a0a8b42e94105c4d929c0b4639fb9
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"
9 namespace ui {
11 TEST(AXTextUtils, FindAccessibleTextBoundaryLine) {
12 const base::string16 text = base::UTF8ToUTF16("Line 1.\nLine 2\n\t");
13 const size_t text_length = text.length();
14 std::vector<int> line_start_offsets;
15 line_start_offsets.push_back(8);
16 line_start_offsets.push_back(15);
17 size_t result;
20 // Basic cases.
21 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY,
22 5, FORWARDS_DIRECTION);
23 EXPECT_EQ(8UL, result);
24 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY,
25 9, BACKWARDS_DIRECTION);
26 EXPECT_EQ(8UL, result);
27 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY,
28 10, FORWARDS_DIRECTION);
29 EXPECT_EQ(15UL, result);
32 // Edge cases.
34 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY,
35 text_length, BACKWARDS_DIRECTION);
36 EXPECT_EQ(15UL, result);
38 // When the start_offset is at the start of the next line and we are searching
39 // backwards, it should not move.
40 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY,
41 15, BACKWARDS_DIRECTION);
42 EXPECT_EQ(15UL, result);
44 // When the start_offset is at a hard line break and we are searching
45 // backwards, it should return the start of the previous line.
46 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY,
47 14, BACKWARDS_DIRECTION);
48 EXPECT_EQ(8UL, result);
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);
56 // When there is no previous line break and we are searching backwards,
57 // it should return 0.
58 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY,
59 4, BACKWARDS_DIRECTION);
60 EXPECT_EQ(0UL, result);
62 // When we are at the start of the last line and we are searching forwards.
63 // it should return the text length.
64 result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY,
65 15, FORWARDS_DIRECTION);
66 EXPECT_EQ(text_length, result);
69 } // Namespace ui.