Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/CustomElementTest.cpp

Issue 2002903002: Hook createElement for Custom Elements V1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dominicc review Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/custom/CustomElement.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #include "core/SVGNames.h"
9 #include "core/dom/Document.h"
10 #include "core/html/HTMLElement.h"
11 #include "core/testing/DummyPageHolder.h"
7 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
8 13
9 namespace blink { 14 namespace blink {
10 15
11 static void testIsPotentialCustomElementName(const AtomicString& str, bool expec ted) 16 static void testIsPotentialCustomElementName(const AtomicString& str, bool expec ted)
12 { 17 {
13 if (expected) { 18 if (expected) {
14 EXPECT_TRUE(CustomElement::isValidName(str)) 19 EXPECT_TRUE(CustomElement::isValidName(str))
15 << str << " should be a valid custom element name."; 20 << str << " should be a valid custom element name.";
16 } else { 21 } else {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 EXPECT_FALSE(CustomElement::isValidName("annotation-xml")); 119 EXPECT_FALSE(CustomElement::isValidName("annotation-xml"));
115 EXPECT_FALSE(CustomElement::isValidName("color-profile")); 120 EXPECT_FALSE(CustomElement::isValidName("color-profile"));
116 EXPECT_FALSE(CustomElement::isValidName("font-face")); 121 EXPECT_FALSE(CustomElement::isValidName("font-face"));
117 EXPECT_FALSE(CustomElement::isValidName("font-face-src")); 122 EXPECT_FALSE(CustomElement::isValidName("font-face-src"));
118 EXPECT_FALSE(CustomElement::isValidName("font-face-uri")); 123 EXPECT_FALSE(CustomElement::isValidName("font-face-uri"));
119 EXPECT_FALSE(CustomElement::isValidName("font-face-format")); 124 EXPECT_FALSE(CustomElement::isValidName("font-face-format"));
120 EXPECT_FALSE(CustomElement::isValidName("font-face-name")); 125 EXPECT_FALSE(CustomElement::isValidName("font-face-name"));
121 EXPECT_FALSE(CustomElement::isValidName("missing-glyph")); 126 EXPECT_FALSE(CustomElement::isValidName("missing-glyph"));
122 } 127 }
123 128
129 TEST(CustomElementTest, StateByParser)
130 {
131 const char* bodyContent = "<div id=div></div>"
132 "<a-a id=v1v0></a-a>"
133 "<font-face id=v0></font-face>";
134 OwnPtr<DummyPageHolder> pageHolder = DummyPageHolder::create();
135 Document& document = pageHolder->document();
136 document.body()->setInnerHTML(String::fromUTF8(bodyContent), ASSERT_NO_EXCEP TION);
137
138 struct {
139 const char* id;
140 CustomElementState state;
141 Element::V0CustomElementState v0state;
142 } parserData[] = {
143 { "div", CustomElementState::Uncustomized, Element::V0NotCustomElement } ,
144 { "v1v0", CustomElementState::Undefined, Element::V0WaitingForUpgrade },
145 { "v0", CustomElementState::Uncustomized, Element::V0WaitingForUpgrade } ,
146 };
147 for (const auto& data : parserData) {
148 Element* element = document.getElementById(data.id);
149 EXPECT_EQ(data.state, element->getCustomElementState()) << data.id;
150 EXPECT_EQ(data.v0state, element->getV0CustomElementState()) << data.id;
151 }
152 }
153
154 TEST(CustomElementTest, StateByCreateElement)
155 {
156 struct {
157 const char* name;
158 CustomElementState state;
159 Element::V0CustomElementState v0state;
160 } createElementData[] = {
161 { "div", CustomElementState::Uncustomized, Element::V0NotCustomElement } ,
162 { "a-a", CustomElementState::Undefined, Element::V0WaitingForUpgrade },
163 // TODO(pdr): <font-face> should be V0NotCustomElement as per the spec,
164 // but was regressed to be V0WaitingForUpgrade in
165 // http://crrev.com/656913006
166 { "font-face", CustomElementState::Uncustomized, Element::V0WaitingForUp grade },
167 { "_-X", CustomElementState::Uncustomized, Element::V0WaitingForUpgrade },
168 };
169 OwnPtr<DummyPageHolder> pageHolder = DummyPageHolder::create();
170 Document& document = pageHolder->document();
171 for (const auto& data : createElementData) {
172 Element* element = document.createElement(data.name, ASSERT_NO_EXCEPTION );
173 EXPECT_EQ(data.state, element->getCustomElementState()) << data.name;
174 EXPECT_EQ(data.v0state, element->getV0CustomElementState()) << data.name ;
175
176 element = document.createElementNS(HTMLNames::xhtmlNamespaceURI, data.na me, ASSERT_NO_EXCEPTION);
177 EXPECT_EQ(data.state, element->getCustomElementState()) << data.name;
178 EXPECT_EQ(data.v0state, element->getV0CustomElementState()) << data.name ;
179
180 element = document.createElementNS(SVGNames::svgNamespaceURI, data.name, ASSERT_NO_EXCEPTION);
181 EXPECT_EQ(CustomElementState::Uncustomized, element->getCustomElementSta te()) << data.name;
182 EXPECT_EQ(data.v0state, element->getV0CustomElementState()) << data.name ;
183 }
184 }
185
124 } // namespace blink 186 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/custom/CustomElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698