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

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

Issue 2334223005: 2nd arg of document.createElement should be an object (Closed)
Patch Set: Remove deprecation warning for now. Created 4 years, 1 month 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 "core/dom/Document.h" 8 #include "core/dom/Document.h"
8 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
9 #include "core/dom/shadow/ShadowRoot.h" 10 #include "core/dom/shadow/ShadowRoot.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace blink { 13 namespace blink {
13 14
14 TEST(TreeScopeTest, CommonAncestorOfSameTrees) { 15 TEST(TreeScopeTest, CommonAncestorOfSameTrees) {
15 Document* document = Document::create(); 16 Document* document = Document::create();
16 EXPECT_EQ(document, document->commonAncestorTreeScope(*document)); 17 EXPECT_EQ(document, document->commonAncestorTreeScope(*document));
17 18
18 Element* html = 19 Element* html = document->createElement("html", StringOrDictionary(),
19 document->createElement("html", nullAtom, ASSERT_NO_EXCEPTION); 20 ASSERT_NO_EXCEPTION);
20 document->appendChild(html, ASSERT_NO_EXCEPTION); 21 document->appendChild(html, ASSERT_NO_EXCEPTION);
21 ShadowRoot* shadowRoot = 22 ShadowRoot* shadowRoot =
22 html->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 23 html->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
23 EXPECT_EQ(shadowRoot, shadowRoot->commonAncestorTreeScope(*shadowRoot)); 24 EXPECT_EQ(shadowRoot, shadowRoot->commonAncestorTreeScope(*shadowRoot));
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 = 33 Element* html = document->createElement("html", StringOrDictionary(),
33 document->createElement("html", nullAtom, ASSERT_NO_EXCEPTION); 34 ASSERT_NO_EXCEPTION);
34 document->appendChild(html, ASSERT_NO_EXCEPTION); 35 document->appendChild(html, ASSERT_NO_EXCEPTION);
35 ShadowRoot* shadowRoot = 36 ShadowRoot* shadowRoot =
36 html->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 37 html->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
37 38
38 EXPECT_EQ(document, document->commonAncestorTreeScope(*shadowRoot)); 39 EXPECT_EQ(document, document->commonAncestorTreeScope(*shadowRoot));
39 EXPECT_EQ(document, shadowRoot->commonAncestorTreeScope(*document)); 40 EXPECT_EQ(document, shadowRoot->commonAncestorTreeScope(*document));
40 } 41 }
41 42
42 TEST(TreeScopeTest, CommonAncestorOfSiblingTrees) { 43 TEST(TreeScopeTest, CommonAncestorOfSiblingTrees) {
43 // document 44 // document
44 // / \ : Common ancestor is document. 45 // / \ : Common ancestor is document.
45 // A B 46 // A B
46 47
47 Document* document = Document::create(); 48 Document* document = Document::create();
48 Element* html = 49 Element* html = document->createElement("html", StringOrDictionary(),
49 document->createElement("html", nullAtom, ASSERT_NO_EXCEPTION); 50 ASSERT_NO_EXCEPTION);
50 document->appendChild(html, ASSERT_NO_EXCEPTION); 51 document->appendChild(html, ASSERT_NO_EXCEPTION);
51 Element* head = 52 Element* head = document->createElement("head", StringOrDictionary(),
52 document->createElement("head", nullAtom, ASSERT_NO_EXCEPTION); 53 ASSERT_NO_EXCEPTION);
53 html->appendChild(head); 54 html->appendChild(head);
54 Element* body = 55 Element* body = document->createElement("body", StringOrDictionary(),
55 document->createElement("body", nullAtom, ASSERT_NO_EXCEPTION); 56 ASSERT_NO_EXCEPTION);
56 html->appendChild(body); 57 html->appendChild(body);
57 58
58 ShadowRoot* shadowRootA = 59 ShadowRoot* shadowRootA =
59 head->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 60 head->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
60 ShadowRoot* shadowRootB = 61 ShadowRoot* shadowRootB =
61 body->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 62 body->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
62 63
63 EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB)); 64 EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB));
64 EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA)); 65 EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA));
65 } 66 }
66 67
67 TEST(TreeScopeTest, CommonAncestorOfTreesAtDifferentDepths) { 68 TEST(TreeScopeTest, CommonAncestorOfTreesAtDifferentDepths) {
68 // document 69 // document
69 // / \ : Common ancestor is document. 70 // / \ : Common ancestor is document.
70 // Y B 71 // Y B
71 // / 72 // /
72 // A 73 // A
73 74
74 Document* document = Document::create(); 75 Document* document = Document::create();
75 Element* html = 76 Element* html = document->createElement("html", StringOrDictionary(),
76 document->createElement("html", nullAtom, ASSERT_NO_EXCEPTION); 77 ASSERT_NO_EXCEPTION);
77 document->appendChild(html, ASSERT_NO_EXCEPTION); 78 document->appendChild(html, ASSERT_NO_EXCEPTION);
78 Element* head = 79 Element* head = document->createElement("head", StringOrDictionary(),
79 document->createElement("head", nullAtom, ASSERT_NO_EXCEPTION); 80 ASSERT_NO_EXCEPTION);
80 html->appendChild(head); 81 html->appendChild(head);
81 Element* body = 82 Element* body = document->createElement("body", StringOrDictionary(),
82 document->createElement("body", nullAtom, ASSERT_NO_EXCEPTION); 83 ASSERT_NO_EXCEPTION);
83 html->appendChild(body); 84 html->appendChild(body);
84 85
85 ShadowRoot* shadowRootY = 86 ShadowRoot* shadowRootY =
86 head->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 87 head->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
87 ShadowRoot* shadowRootB = 88 ShadowRoot* shadowRootB =
88 body->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 89 body->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
89 90
90 Element* divInY = 91 Element* divInY =
91 document->createElement("div", nullAtom, ASSERT_NO_EXCEPTION); 92 document->createElement("div", StringOrDictionary(), ASSERT_NO_EXCEPTION);
92 shadowRootY->appendChild(divInY); 93 shadowRootY->appendChild(divInY);
93 ShadowRoot* shadowRootA = 94 ShadowRoot* shadowRootA =
94 divInY->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 95 divInY->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
95 96
96 EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB)); 97 EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB));
97 EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA)); 98 EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA));
98 } 99 }
99 100
100 TEST(TreeScopeTest, CommonAncestorOfTreesInDifferentDocuments) { 101 TEST(TreeScopeTest, CommonAncestorOfTreesInDifferentDocuments) {
101 Document* document1 = Document::create(); 102 Document* document1 = Document::create();
102 Document* document2 = Document::create(); 103 Document* document2 = Document::create();
103 EXPECT_EQ(0, document1->commonAncestorTreeScope(*document2)); 104 EXPECT_EQ(0, document1->commonAncestorTreeScope(*document2));
104 EXPECT_EQ(0, document2->commonAncestorTreeScope(*document1)); 105 EXPECT_EQ(0, document2->commonAncestorTreeScope(*document1));
105 } 106 }
106 107
107 } // namespace blink 108 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698