Update implementations of webrtc::SetSessionDescriptionObserver to use the new OnComp...
[chromium-blink-merge.git] / ui / gfx / text_utils_unittest.cc
blob0c0127fc12399b690708ab50ec8afb2d0506b13d
1 // Copyright (c) 2011 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 "ui/gfx/text_utils.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/font_list.h"
11 namespace gfx {
12 namespace {
14 const base::char16 kAcceleratorChar = '&';
16 TEST(TextUtilsTest, RemoveAcceleratorChar) {
17 struct TestData {
18 const char* input;
19 int accelerated_char_pos;
20 int accelerated_char_span;
21 const char* output;
22 } cases[] = {
23 { "", -1, 0, "" },
24 { "&", -1, 0, "" },
25 { "no accelerator", -1, 0, "no accelerator" },
26 { "&one accelerator", 0, 1, "one accelerator" },
27 { "one &accelerator", 4, 1, "one accelerator" },
28 { "one_accelerator&", -1, 0, "one_accelerator" },
29 { "&two &accelerators", 4, 1, "two accelerators" },
30 { "two &accelerators&", 4, 1, "two accelerators" },
31 { "two& &accelerators", 4, 1, "two accelerators" },
32 { "&&escaping", -1, 0, "&escaping" },
33 { "escap&&ing", -1, 0, "escap&ing" },
34 { "escaping&&", -1, 0, "escaping&" },
35 { "&mix&&ed", 0, 1, "mix&ed" },
36 { "&&m&ix&&e&d&", 6, 1, "&mix&ed" },
37 { "&&m&&ix&ed&&", 5, 1, "&m&ixed&" },
38 { "&m&&ix&ed&&", 4, 1, "m&ixed&" },
39 // U+1D49C MATHEMATICAL SCRIPT CAPITAL A, which occupies two |char16|'s.
40 { "&\xF0\x9D\x92\x9C", 0, 2, "\xF0\x9D\x92\x9C" },
41 { "Test&\xF0\x9D\x92\x9Cing", 4, 2, "Test\xF0\x9D\x92\x9Cing" },
42 { "Test\xF0\x9D\x92\x9C&ing", 6, 1, "Test\xF0\x9D\x92\x9Cing" },
43 { "Test&\xF0\x9D\x92\x9C&ing", 6, 1, "Test\xF0\x9D\x92\x9Cing" },
44 { "Test&\xF0\x9D\x92\x9C&&ing", 4, 2, "Test\xF0\x9D\x92\x9C&ing" },
45 { "Test&\xF0\x9D\x92\x9C&\xF0\x9D\x92\x9Cing", 6, 2,
46 "Test\xF0\x9D\x92\x9C\xF0\x9D\x92\x9Cing" },
49 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
50 int accelerated_char_pos;
51 int accelerated_char_span;
52 base::string16 result = RemoveAcceleratorChar(
53 base::UTF8ToUTF16(cases[i].input),
54 kAcceleratorChar,
55 &accelerated_char_pos,
56 &accelerated_char_span);
57 EXPECT_EQ(result, base::UTF8ToUTF16(cases[i].output));
58 EXPECT_EQ(accelerated_char_pos, cases[i].accelerated_char_pos);
59 EXPECT_EQ(accelerated_char_span, cases[i].accelerated_char_span);
63 // Disabled on Ozone since there are no fonts: crbug.com/320050
64 #if defined(USE_OZONE)
65 #define MAYBE_GetStringWidth DISABLED_GetStringWidth
66 #else
67 #define MAYBE_GetStringWidth GetStringWidth
68 #endif
69 TEST(TextUtilsTest, MAYBE_GetStringWidth) {
70 FontList font_list;
71 EXPECT_EQ(GetStringWidth(base::string16(), font_list), 0);
72 EXPECT_GT(GetStringWidth(base::ASCIIToUTF16("a"), font_list),
73 GetStringWidth(base::string16(), font_list));
74 EXPECT_GT(GetStringWidth(base::ASCIIToUTF16("ab"), font_list),
75 GetStringWidth(base::ASCIIToUTF16("a"), font_list));
76 EXPECT_GT(GetStringWidth(base::ASCIIToUTF16("abc"), font_list),
77 GetStringWidth(base::ASCIIToUTF16("ab"), font_list));
80 } // namespace
81 } // namespace gfx