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

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

Issue 2838123002: Count element name validity per DOM versus HTML parsing. (Closed)
Patch Set: Do not need the attribute counting. Created 3 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/TreeScope.h" 5 #include "core/dom/TreeScope.h"
6 6
7 #include "bindings/core/v8/StringOrDictionary.h" 7 #include "bindings/core/v8/StringOrDictionary.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
10 #include "core/dom/shadow/ShadowRoot.h" 10 #include "core/dom/shadow/ShadowRoot.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 TEST(TreeScopeTest, CommonAncestorOfSameTrees) { 15 TEST(TreeScopeTest, CommonAncestorOfSameTrees) {
16 Document* document = Document::Create(); 16 Document* document = Document::Create();
17 EXPECT_EQ(document, document->CommonAncestorTreeScope(*document)); 17 EXPECT_EQ(document, document->CommonAncestorTreeScope(*document));
18 18
19 Element* html = document->createElement("html", StringOrDictionary()); 19 Element* html =
20 document->createElement(nullptr, "html", StringOrDictionary());
20 document->AppendChild(html); 21 document->AppendChild(html);
21 ShadowRoot* shadow_root = 22 ShadowRoot* shadow_root =
22 html->CreateShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 23 html->CreateShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
23 EXPECT_EQ(shadow_root, shadow_root->CommonAncestorTreeScope(*shadow_root)); 24 EXPECT_EQ(shadow_root, shadow_root->CommonAncestorTreeScope(*shadow_root));
24 } 25 }
25 26
26 TEST(TreeScopeTest, CommonAncestorOfInclusiveTrees) { 27 TEST(TreeScopeTest, CommonAncestorOfInclusiveTrees) {
27 // document 28 // document
28 // | : Common ancestor is document. 29 // | : Common ancestor is document.
29 // shadowRoot 30 // shadowRoot
30 31
31 Document* document = Document::Create(); 32 Document* document = Document::Create();
32 Element* html = document->createElement("html", StringOrDictionary()); 33 Element* html =
34 document->createElement(nullptr, "html", StringOrDictionary());
33 document->AppendChild(html); 35 document->AppendChild(html);
34 ShadowRoot* shadow_root = 36 ShadowRoot* shadow_root =
35 html->CreateShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 37 html->CreateShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
36 38
37 EXPECT_EQ(document, document->CommonAncestorTreeScope(*shadow_root)); 39 EXPECT_EQ(document, document->CommonAncestorTreeScope(*shadow_root));
38 EXPECT_EQ(document, shadow_root->CommonAncestorTreeScope(*document)); 40 EXPECT_EQ(document, shadow_root->CommonAncestorTreeScope(*document));
39 } 41 }
40 42
41 TEST(TreeScopeTest, CommonAncestorOfSiblingTrees) { 43 TEST(TreeScopeTest, CommonAncestorOfSiblingTrees) {
42 // document 44 // document
43 // / \ : Common ancestor is document. 45 // / \ : Common ancestor is document.
44 // A B 46 // A B
45 47
46 Document* document = Document::Create(); 48 Document* document = Document::Create();
47 Element* html = document->createElement("html", StringOrDictionary()); 49 Element* html =
50 document->createElement(nullptr, "html", StringOrDictionary());
48 document->AppendChild(html); 51 document->AppendChild(html);
49 Element* head = document->createElement("head", StringOrDictionary()); 52 Element* head =
53 document->createElement(nullptr, "head", StringOrDictionary());
50 html->AppendChild(head); 54 html->AppendChild(head);
51 Element* body = document->createElement("body", StringOrDictionary()); 55 Element* body =
56 document->createElement(nullptr, "body", StringOrDictionary());
52 html->AppendChild(body); 57 html->AppendChild(body);
53 58
54 ShadowRoot* shadow_root_a = 59 ShadowRoot* shadow_root_a =
55 head->CreateShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 60 head->CreateShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
56 ShadowRoot* shadow_root_b = 61 ShadowRoot* shadow_root_b =
57 body->CreateShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 62 body->CreateShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
58 63
59 EXPECT_EQ(document, shadow_root_a->CommonAncestorTreeScope(*shadow_root_b)); 64 EXPECT_EQ(document, shadow_root_a->CommonAncestorTreeScope(*shadow_root_b));
60 EXPECT_EQ(document, shadow_root_b->CommonAncestorTreeScope(*shadow_root_a)); 65 EXPECT_EQ(document, shadow_root_b->CommonAncestorTreeScope(*shadow_root_a));
61 } 66 }
62 67
63 TEST(TreeScopeTest, CommonAncestorOfTreesAtDifferentDepths) { 68 TEST(TreeScopeTest, CommonAncestorOfTreesAtDifferentDepths) {
64 // document 69 // document
65 // / \ : Common ancestor is document. 70 // / \ : Common ancestor is document.
66 // Y B 71 // Y B
67 // / 72 // /
68 // A 73 // A
69 74
70 Document* document = Document::Create(); 75 Document* document = Document::Create();
71 Element* html = document->createElement("html", StringOrDictionary()); 76 Element* html =
77 document->createElement(nullptr, "html", StringOrDictionary());
72 document->AppendChild(html); 78 document->AppendChild(html);
73 Element* head = document->createElement("head", StringOrDictionary()); 79 Element* head =
80 document->createElement(nullptr, "head", StringOrDictionary());
74 html->AppendChild(head); 81 html->AppendChild(head);
75 Element* body = document->createElement("body", StringOrDictionary()); 82 Element* body =
83 document->createElement(nullptr, "body", StringOrDictionary());
76 html->AppendChild(body); 84 html->AppendChild(body);
77 85
78 ShadowRoot* shadow_root_y = 86 ShadowRoot* shadow_root_y =
79 head->CreateShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 87 head->CreateShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
80 ShadowRoot* shadow_root_b = 88 ShadowRoot* shadow_root_b =
81 body->CreateShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 89 body->CreateShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
82 90
83 Element* div_in_y = document->createElement("div", StringOrDictionary()); 91 Element* div_in_y =
92 document->createElement(nullptr, "div", StringOrDictionary());
84 shadow_root_y->AppendChild(div_in_y); 93 shadow_root_y->AppendChild(div_in_y);
85 ShadowRoot* shadow_root_a = div_in_y->CreateShadowRootInternal( 94 ShadowRoot* shadow_root_a = div_in_y->CreateShadowRootInternal(
86 ShadowRootType::V0, ASSERT_NO_EXCEPTION); 95 ShadowRootType::V0, ASSERT_NO_EXCEPTION);
87 96
88 EXPECT_EQ(document, shadow_root_a->CommonAncestorTreeScope(*shadow_root_b)); 97 EXPECT_EQ(document, shadow_root_a->CommonAncestorTreeScope(*shadow_root_b));
89 EXPECT_EQ(document, shadow_root_b->CommonAncestorTreeScope(*shadow_root_a)); 98 EXPECT_EQ(document, shadow_root_b->CommonAncestorTreeScope(*shadow_root_a));
90 } 99 }
91 100
92 TEST(TreeScopeTest, CommonAncestorOfTreesInDifferentDocuments) { 101 TEST(TreeScopeTest, CommonAncestorOfTreesInDifferentDocuments) {
93 Document* document1 = Document::Create(); 102 Document* document1 = Document::Create();
94 Document* document2 = Document::Create(); 103 Document* document2 = Document::Create();
95 EXPECT_EQ(0, document1->CommonAncestorTreeScope(*document2)); 104 EXPECT_EQ(0, document1->CommonAncestorTreeScope(*document2));
96 EXPECT_EQ(0, document2->CommonAncestorTreeScope(*document1)); 105 EXPECT_EQ(0, document2->CommonAncestorTreeScope(*document1));
97 } 106 }
98 107
99 } // namespace blink 108 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Document.idl ('k') | third_party/WebKit/Source/core/dom/custom/CustomElementTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698