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..fa838498ac48a35fe6e7d77f7c6e987c452e30e6 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/dom/custom/CustomElementTest.cpp |
| @@ -0,0 +1,85 @@ |
| +// 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" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace blink { |
| + |
| +static void TestIsPotentialCustomElementNameChar(UChar32 c, bool expected) |
| +{ |
| + 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; |
| + } |
| + if (expected) |
| + EXPECT_TRUE(CustomElement::isPotentialCustomElementName(str)) << str; |
|
dominicc (has gone to gerrit)
2016/04/27 01:42:14
WDYT about making this message more descriptive, e
kojii
2016/04/27 03:52:13
Done, thanks for the suggestion.
|
| + else |
| + EXPECT_FALSE(CustomElement::isPotentialCustomElementName(str)) << str; |
| +} |
| + |
| +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" }, |
|
dominicc (has gone to gerrit)
2016/04/27 01:42:14
WDYT about including some multibyte strings here?
kojii
2016/04/27 03:52:13
Done.
|
| + }; |
| + for (auto test : tests) { |
| + if (test.expected) |
| + EXPECT_TRUE(CustomElement::isPotentialCustomElementName(test.str)) << test.str; |
| + else |
| + EXPECT_FALSE(CustomElement::isPotentialCustomElementName(test.str)) << test.str; |
| + } |
| + |
| + struct { |
|
dominicc (has gone to gerrit)
2016/04/27 01:42:14
Let's split these into two tests at this point; an
kojii
2016/04/27 03:52:13
Done.
|
| + UChar32 from, to; |
| + } ranges[] = { |
| + { '-', '.' }, |
|
dominicc (has gone to gerrit)
2016/04/27 01:42:14
Bit subtle given how the spec treats these, but OK
|
| + { '0', '9' }, |
| + { '_', '_' }, |
| + { 0xB7, 0xB7 }, |
|
dominicc (has gone to gerrit)
2016/04/27 01:42:14
What about good old a-z? And how about an explicit
kojii
2016/04/27 03:52:13
Done.
|
| + { 0xC0, 0xD6 }, |
| + { 0xD8, 0xF6 }, |
| + { 0xF8, 0x37D }, |
|
dominicc (has gone to gerrit)
2016/04/27 01:42:14
See my comment on CharacterPropertyDataGenerator.h
kojii
2016/04/27 03:52:13
Done, added comments.
|
| + { 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); |
| + } |
| +} |
| + |
| +} // namespace blink |