WebSocket header continuations test case.
[chromium-blink-merge.git] / ui / accessibility / ax_text_utils_unittest.cc
blob7163ef841d2d38c9fba78b51934405dcdfc312fd
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");
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);
17 size_t result;
20 // Basic cases.
21 result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 5,
22 FORWARDS_DIRECTION);
23 EXPECT_EQ(7UL, result);
24 result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 9,
25 BACKWARDS_DIRECTION);
26 EXPECT_EQ(7UL, result);
27 result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 10,
28 FORWARDS_DIRECTION);
29 EXPECT_EQ(14UL, result);
32 // Edge cases.
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,
41 BACKWARDS_DIRECTION);
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,
47 FORWARDS_DIRECTION);
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,
53 BACKWARDS_DIRECTION);
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,
59 FORWARDS_DIRECTION);
60 EXPECT_EQ(text_length, result);
63 } // Namespace ui.