OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/dom/custom/CustomElement.h" | 5 #include "core/dom/custom/CustomElement.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 static void testIsPotentialCustomElementName(const AtomicString& str, bool expec
ted) | 11 static void testIsPotentialCustomElementName(const AtomicString& str, bool expec
ted) |
12 { | 12 { |
13 if (expected) { | 13 if (expected) { |
14 EXPECT_TRUE(CustomElement::isPotentialCustomElementName(str)) | 14 EXPECT_TRUE(CustomElement::isValidName(str)) |
15 << str << " should be PotentialCustomElementName."; | 15 << str << " should be a valid custom element name."; |
16 } else { | 16 } else { |
17 EXPECT_FALSE(CustomElement::isPotentialCustomElementName(str)) | 17 EXPECT_FALSE(CustomElement::isValidName(str)) |
18 << str << " should NOT be PotentialCustomElementName."; | 18 << str << " should NOT be a valid custom element name."; |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
22 static void testIsPotentialCustomElementNameChar(UChar32 c, bool expected) | 22 static void testIsPotentialCustomElementNameChar(UChar32 c, bool expected) |
23 { | 23 { |
24 LChar str8[] = "a-X"; | 24 LChar str8[] = "a-X"; |
25 UChar str16[] = { 'a', '-', 'X', '\0', '\0' }; | 25 UChar str16[] = { 'a', '-', 'X', '\0', '\0' }; |
26 AtomicString str; | 26 AtomicString str; |
27 if (c <= 0xFF) { | 27 if (c <= 0xFF) { |
28 str8[2] = c; | 28 str8[2] = c; |
29 str = str8; | 29 str = str8; |
30 } else { | 30 } else { |
31 size_t i = 2; | 31 size_t i = 2; |
32 U16_APPEND_UNSAFE(str16, i, c); | 32 U16_APPEND_UNSAFE(str16, i, c); |
33 str16[i] = 0; | 33 str16[i] = 0; |
34 str = str16; | 34 str = str16; |
35 } | 35 } |
36 testIsPotentialCustomElementName(str, expected); | 36 testIsPotentialCustomElementName(str, expected); |
37 } | 37 } |
38 | 38 |
39 TEST(CustomElementTest, TestIsPotentialCustomElementName) | 39 TEST(CustomElementTest, TestIsValidNamePotentialCustomElementName) |
40 { | 40 { |
41 struct { | 41 struct { |
42 bool expected; | 42 bool expected; |
43 AtomicString str; | 43 AtomicString str; |
44 } tests[] = { | 44 } tests[] = { |
45 { false, "" }, | 45 { false, "" }, |
46 { false, "a" }, | 46 { false, "a" }, |
47 { false, "A" }, | 47 { false, "A" }, |
48 | 48 |
49 { false, "A-" }, | 49 { false, "A-" }, |
50 { false, "0-" }, | 50 { false, "0-" }, |
51 | 51 |
52 { true, "a-" }, | 52 { true, "a-" }, |
53 { true, "a-a" }, | 53 { true, "a-a" }, |
54 { true, "aa-" }, | 54 { true, "aa-" }, |
55 { true, "aa-a" }, | 55 { true, "aa-a" }, |
56 { true, reinterpret_cast<const UChar*>(u"aa-\x6F22\x5B57") }, // Two CJK
Unified Ideographs | 56 { true, reinterpret_cast<const UChar*>(u"aa-\x6F22\x5B57") }, // Two CJK
Unified Ideographs |
57 { true, reinterpret_cast<const UChar*>(u"aa-\xD840\xDC0B") }, // Surroga
te pair U+2000B | 57 { true, reinterpret_cast<const UChar*>(u"aa-\xD840\xDC0B") }, // Surroga
te pair U+2000B |
58 | 58 |
59 { false, "a-A" }, | 59 { false, "a-A" }, |
60 { false, "a-Z" }, | 60 { false, "a-Z" }, |
61 }; | 61 }; |
62 for (auto test : tests) | 62 for (auto test : tests) |
63 testIsPotentialCustomElementName(test.str, test.expected); | 63 testIsPotentialCustomElementName(test.str, test.expected); |
64 } | 64 } |
65 | 65 |
66 TEST(CustomElementTest, TestIsPotentialCustomElementNameChar) | 66 TEST(CustomElementTest, TestIsValidNamePotentialCustomElementNameChar) |
67 { | 67 { |
68 struct { | 68 struct { |
69 UChar32 from, to; | 69 UChar32 from, to; |
70 } ranges[] = { | 70 } ranges[] = { |
71 { '-', '.' }, // "-" | "." need to merge to test -1/+1. | 71 { '-', '.' }, // "-" | "." need to merge to test -1/+1. |
72 { '0', '9' }, | 72 { '0', '9' }, |
73 { '_', '_' }, | 73 { '_', '_' }, |
74 { 'a', 'z' }, | 74 { 'a', 'z' }, |
75 { 0xB7, 0xB7 }, | 75 { 0xB7, 0xB7 }, |
76 { 0xC0, 0xD6 }, | 76 { 0xC0, 0xD6 }, |
(...skipping 10 matching lines...) Expand all Loading... |
87 { 0x10000, 0xEFFFF }, | 87 { 0x10000, 0xEFFFF }, |
88 }; | 88 }; |
89 for (auto range : ranges) { | 89 for (auto range : ranges) { |
90 testIsPotentialCustomElementNameChar(range.from - 1, false); | 90 testIsPotentialCustomElementNameChar(range.from - 1, false); |
91 for (UChar32 c = range.from; c <= range.to; ++c) | 91 for (UChar32 c = range.from; c <= range.to; ++c) |
92 testIsPotentialCustomElementNameChar(c, true); | 92 testIsPotentialCustomElementNameChar(c, true); |
93 testIsPotentialCustomElementNameChar(range.to + 1, false); | 93 testIsPotentialCustomElementNameChar(range.to + 1, false); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 TEST(CustomElementTest, TestIsPotentialCustomElementNameCharFalse) | 97 TEST(CustomElementTest, TestIsValidNamePotentialCustomElementNameCharFalse) |
98 { | 98 { |
99 struct { | 99 struct { |
100 UChar32 from, to; | 100 UChar32 from, to; |
101 } ranges[] = { | 101 } ranges[] = { |
102 { 'A', 'Z' }, | 102 { 'A', 'Z' }, |
103 }; | 103 }; |
104 for (auto range : ranges) { | 104 for (auto range : ranges) { |
105 for (UChar32 c = range.from; c <= range.to; ++c) | 105 for (UChar32 c = range.from; c <= range.to; ++c) |
106 testIsPotentialCustomElementNameChar(c, false); | 106 testIsPotentialCustomElementNameChar(c, false); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
| 110 TEST(CustomElementTest, TestIsValidNameHyphenContainingElementNames) |
| 111 { |
| 112 EXPECT_TRUE(CustomElement::isValidName("valid-name")); |
| 113 |
| 114 EXPECT_FALSE(CustomElement::isValidName("annotation-xml")); |
| 115 EXPECT_FALSE(CustomElement::isValidName("color-profile")); |
| 116 EXPECT_FALSE(CustomElement::isValidName("font-face")); |
| 117 EXPECT_FALSE(CustomElement::isValidName("font-face-src")); |
| 118 EXPECT_FALSE(CustomElement::isValidName("font-face-uri")); |
| 119 EXPECT_FALSE(CustomElement::isValidName("font-face-format")); |
| 120 EXPECT_FALSE(CustomElement::isValidName("font-face-name")); |
| 121 EXPECT_FALSE(CustomElement::isValidName("missing-glyph")); |
| 122 } |
| 123 |
110 } // namespace blink | 124 } // namespace blink |
OLD | NEW |