Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/custom/CustomElementTest.cpp |
| diff --git a/third_party/WebKit/Source/core/dom/custom/CustomElementTest.cpp b/third_party/WebKit/Source/core/dom/custom/CustomElementTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1b76776a72c13fa2ebf47616c490a1b00f0be972 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/dom/custom/CustomElementTest.cpp |
| @@ -0,0 +1,113 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/dom/custom/CustomElement.h" |
| + |
| +#include "platform/Logging.h" |
|
tkent
2016/04/27 08:21:18
Please don't use platform/Logging.h.
kojii
2016/04/27 08:45:20
Done, sorry, copied from somewhere.
|
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace blink { |
| + |
| +static void TestIsPotentialCustomElementName(const AtomicString& str, bool expected) |
|
tkent
2016/04/27 08:21:18
Function name should start with lower case latter
kojii
2016/04/27 08:45:20
Done, confused with test names, sorry.
|
| +{ |
| + if (expected) { |
| + EXPECT_TRUE(CustomElement::isPotentialCustomElementName(str)) |
| + << str << " should be PotentialCustomElementName."; |
| + } else { |
| + EXPECT_FALSE(CustomElement::isPotentialCustomElementName(str)) |
| + << str << " should NOT be PotentialCustomElementName."; |
| + } |
| +} |
| + |
| +static void TestIsPotentialCustomElementNameChar(UChar32 c, bool expected) |
|
tkent
2016/04/27 08:21:18
Ditto.
kojii
2016/04/27 08:45:20
Done.
|
| +{ |
| + LChar str8[] = "a-X"; |
| + UChar str16[] = { 'a', '-', 'X', '\0', '\0' }; |
| + AtomicString str; |
| + if (c <= 0xFF) { |
| + str8[2] = c; |
| + str = str8; |
| + } else { |
| + size_t i = 2; |
| + U16_APPEND_UNSAFE(str16, i, c); |
| + str16[i] = 0; |
| + str = str16; |
| + } |
| + TestIsPotentialCustomElementName(str, expected); |
| +} |
| + |
| +TEST(CustomElementTest, TestIsPotentialCustomElementName) |
| +{ |
| + struct { |
| + bool expected; |
| + AtomicString str; |
| + } tests[] = { |
| + { false, "" }, |
| + { false, "a" }, |
| + { false, "A" }, |
| + |
| + { false, "A-" }, |
| + { false, "0-" }, |
| + |
| + { true, "a-" }, |
| + { true, "a-a" }, |
| + { true, "aa-" }, |
| + { true, "aa-a" }, |
| + { true, reinterpret_cast<const UChar*>(u"aa-\x6F22\x5B57") }, // Two CJK Unified Ideographs |
| + { true, reinterpret_cast<const UChar*>(u"aa-\xD840\xDC0B") }, // Surrogate pair U+2000B |
| + |
| + { false, "a-A" }, |
| + { false, "a-Z" }, |
| + }; |
| + for (auto test : tests) |
| + TestIsPotentialCustomElementName(test.str, test.expected); |
| +} |
| + |
| +TEST(CustomElementTest, TestIsPotentialCustomElementNameChar) |
| +{ |
| + |
|
tkent
2016/04/27 08:21:18
This blank line looks unnecessary.
kojii
2016/04/27 08:45:20
Done.
|
| + struct { |
| + UChar32 from, to; |
| + } ranges[] = { |
| + { '-', '.' }, // "-" | "." need to merge to test -1/+1. |
| + { '0', '9' }, |
| + { '_', '_' }, |
| + { 'a', 'z' }, |
| + { 0xB7, 0xB7 }, |
| + { 0xC0, 0xD6 }, |
| + { 0xD8, 0xF6 }, |
| + { 0xF8, 0x37D }, // [#xF8-#x2FF] | [#x300-#x37D] need to merge to test -1/+1. |
| + { 0x37F, 0x1FFF }, |
| + { 0x200C, 0x200D }, |
| + { 0x203F, 0x2040 }, |
| + { 0x2070, 0x218F }, |
| + { 0x2C00, 0x2FEF }, |
| + { 0x3001, 0xD7FF }, |
| + { 0xF900, 0xFDCF }, |
| + { 0xFDF0, 0xFFFD }, |
| + { 0x10000, 0xEFFFF }, |
| + }; |
| + for (auto range : ranges) { |
| + TestIsPotentialCustomElementNameChar(range.from - 1, false); |
| + for (UChar32 c = range.from; c <= range.to; ++c) |
| + TestIsPotentialCustomElementNameChar(c, true); |
| + TestIsPotentialCustomElementNameChar(range.to + 1, false); |
| + } |
| +} |
| + |
| +TEST(CustomElementTest, TestIsPotentialCustomElementNameCharFalse) |
| +{ |
| + |
|
tkent
2016/04/27 08:21:18
This blank line looks unnecessary.
kojii
2016/04/27 08:45:20
Done.
|
| + struct { |
| + UChar32 from, to; |
| + } ranges[] = { |
| + { 'A', 'Z' }, |
| + }; |
| + for (auto range : ranges) { |
| + for (UChar32 c = range.from; c <= range.to; ++c) |
| + TestIsPotentialCustomElementNameChar(c, false); |
| + } |
| +} |
| + |
| +} // namespace blink |