| 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 "core/HTMLNames.h" | 7 #include "core/HTMLNames.h" |
| 8 #include "core/SVGNames.h" | 8 #include "core/SVGNames.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/html/HTMLElement.h" | 10 #include "core/html/HTMLElement.h" |
| 11 #include "core/testing/DummyPageHolder.h" | 11 #include "core/testing/DummyPageHolder.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include <ios> |
| 13 #include <memory> | 14 #include <memory> |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 static void testIsPotentialCustomElementName(const AtomicString& str, bool expec
ted) | 18 static void testIsPotentialCustomElementName(const AtomicString& str, bool expec
ted) |
| 18 { | 19 { |
| 19 if (expected) { | 20 if (expected) { |
| 20 EXPECT_TRUE(CustomElement::isValidName(str)) | 21 EXPECT_TRUE(CustomElement::isValidName(str)) |
| 21 << str << " should be a valid custom element name."; | 22 << str << " should be a valid custom element name."; |
| 22 } else { | 23 } else { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 { 0x10000, 0xEFFFF }, | 94 { 0x10000, 0xEFFFF }, |
| 94 }; | 95 }; |
| 95 for (auto range : ranges) { | 96 for (auto range : ranges) { |
| 96 testIsPotentialCustomElementNameChar(range.from - 1, false); | 97 testIsPotentialCustomElementNameChar(range.from - 1, false); |
| 97 for (UChar32 c = range.from; c <= range.to; ++c) | 98 for (UChar32 c = range.from; c <= range.to; ++c) |
| 98 testIsPotentialCustomElementNameChar(c, true); | 99 testIsPotentialCustomElementNameChar(c, true); |
| 99 testIsPotentialCustomElementNameChar(range.to + 1, false); | 100 testIsPotentialCustomElementNameChar(range.to + 1, false); |
| 100 } | 101 } |
| 101 } | 102 } |
| 102 | 103 |
| 104 TEST(CustomElementTest, TestIsValidNamePotentialCustomElementName8BitChar) |
| 105 { |
| 106 // isPotentialCustomElementName8BitChar must match |
| 107 // isPotentialCustomElementNameChar, so we just test it returns |
| 108 // the same result throughout its range. |
| 109 for (UChar ch = 0x0; ch <= 0xff; ++ch) { |
| 110 EXPECT_EQ( |
| 111 Character::isPotentialCustomElementName8BitChar(ch), |
| 112 Character::isPotentialCustomElementNameChar(ch)) |
| 113 << "isPotentialCustomElementName8BitChar must agree with " |
| 114 << "isPotentialCustomElementNameChar: 0x" << std::hex << ch; |
| 115 } |
| 116 } |
| 117 |
| 103 TEST(CustomElementTest, TestIsValidNamePotentialCustomElementNameCharFalse) | 118 TEST(CustomElementTest, TestIsValidNamePotentialCustomElementNameCharFalse) |
| 104 { | 119 { |
| 105 struct { | 120 struct { |
| 106 UChar32 from, to; | 121 UChar32 from, to; |
| 107 } ranges[] = { | 122 } ranges[] = { |
| 108 { 'A', 'Z' }, | 123 { 'A', 'Z' }, |
| 109 }; | 124 }; |
| 110 for (auto range : ranges) { | 125 for (auto range : ranges) { |
| 111 for (UChar32 c = range.from; c <= range.to; ++c) | 126 for (UChar32 c = range.from; c <= range.to; ++c) |
| 112 testIsPotentialCustomElementNameChar(c, false); | 127 testIsPotentialCustomElementNameChar(c, false); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 EXPECT_EQ(data.state, element->getCustomElementState()) << data.name; | 193 EXPECT_EQ(data.state, element->getCustomElementState()) << data.name; |
| 179 EXPECT_EQ(data.v0state, element->getV0CustomElementState()) << data.name
; | 194 EXPECT_EQ(data.v0state, element->getV0CustomElementState()) << data.name
; |
| 180 | 195 |
| 181 element = document.createElementNS(SVGNames::svgNamespaceURI, data.name,
ASSERT_NO_EXCEPTION); | 196 element = document.createElementNS(SVGNames::svgNamespaceURI, data.name,
ASSERT_NO_EXCEPTION); |
| 182 EXPECT_EQ(CustomElementState::Uncustomized, element->getCustomElementSta
te()) << data.name; | 197 EXPECT_EQ(CustomElementState::Uncustomized, element->getCustomElementSta
te()) << data.name; |
| 183 EXPECT_EQ(data.v0state, element->getV0CustomElementState()) << data.name
; | 198 EXPECT_EQ(data.v0state, element->getV0CustomElementState()) << data.name
; |
| 184 } | 199 } |
| 185 } | 200 } |
| 186 | 201 |
| 187 } // namespace blink | 202 } // namespace blink |
| OLD | NEW |