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

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

Issue 2508793002: Make exceptionState parameter of Document::createElement() to have default value (Closed)
Patch Set: 2016-11-16T15:26:06 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 "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 = document->createElement("html", StringOrDictionary());
20 ASSERT_NO_EXCEPTION);
21 document->appendChild(html, ASSERT_NO_EXCEPTION); 20 document->appendChild(html, ASSERT_NO_EXCEPTION);
22 ShadowRoot* shadowRoot = 21 ShadowRoot* shadowRoot =
23 html->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 22 html->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
24 EXPECT_EQ(shadowRoot, shadowRoot->commonAncestorTreeScope(*shadowRoot)); 23 EXPECT_EQ(shadowRoot, shadowRoot->commonAncestorTreeScope(*shadowRoot));
25 } 24 }
26 25
27 TEST(TreeScopeTest, CommonAncestorOfInclusiveTrees) { 26 TEST(TreeScopeTest, CommonAncestorOfInclusiveTrees) {
28 // document 27 // document
29 // | : Common ancestor is document. 28 // | : Common ancestor is document.
30 // shadowRoot 29 // shadowRoot
31 30
32 Document* document = Document::create(); 31 Document* document = Document::create();
33 Element* html = document->createElement("html", StringOrDictionary(), 32 Element* html = document->createElement("html", StringOrDictionary());
34 ASSERT_NO_EXCEPTION);
35 document->appendChild(html, ASSERT_NO_EXCEPTION); 33 document->appendChild(html, ASSERT_NO_EXCEPTION);
36 ShadowRoot* shadowRoot = 34 ShadowRoot* shadowRoot =
37 html->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 35 html->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
38 36
39 EXPECT_EQ(document, document->commonAncestorTreeScope(*shadowRoot)); 37 EXPECT_EQ(document, document->commonAncestorTreeScope(*shadowRoot));
40 EXPECT_EQ(document, shadowRoot->commonAncestorTreeScope(*document)); 38 EXPECT_EQ(document, shadowRoot->commonAncestorTreeScope(*document));
41 } 39 }
42 40
43 TEST(TreeScopeTest, CommonAncestorOfSiblingTrees) { 41 TEST(TreeScopeTest, CommonAncestorOfSiblingTrees) {
44 // document 42 // document
45 // / \ : Common ancestor is document. 43 // / \ : Common ancestor is document.
46 // A B 44 // A B
47 45
48 Document* document = Document::create(); 46 Document* document = Document::create();
49 Element* html = document->createElement("html", StringOrDictionary(), 47 Element* html = document->createElement("html", StringOrDictionary());
50 ASSERT_NO_EXCEPTION);
51 document->appendChild(html, ASSERT_NO_EXCEPTION); 48 document->appendChild(html, ASSERT_NO_EXCEPTION);
52 Element* head = document->createElement("head", StringOrDictionary(), 49 Element* head = document->createElement("head", StringOrDictionary());
53 ASSERT_NO_EXCEPTION);
54 html->appendChild(head); 50 html->appendChild(head);
55 Element* body = document->createElement("body", StringOrDictionary(), 51 Element* body = document->createElement("body", StringOrDictionary());
56 ASSERT_NO_EXCEPTION);
57 html->appendChild(body); 52 html->appendChild(body);
58 53
59 ShadowRoot* shadowRootA = 54 ShadowRoot* shadowRootA =
60 head->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 55 head->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
61 ShadowRoot* shadowRootB = 56 ShadowRoot* shadowRootB =
62 body->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 57 body->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
63 58
64 EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB)); 59 EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB));
65 EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA)); 60 EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA));
66 } 61 }
67 62
68 TEST(TreeScopeTest, CommonAncestorOfTreesAtDifferentDepths) { 63 TEST(TreeScopeTest, CommonAncestorOfTreesAtDifferentDepths) {
69 // document 64 // document
70 // / \ : Common ancestor is document. 65 // / \ : Common ancestor is document.
71 // Y B 66 // Y B
72 // / 67 // /
73 // A 68 // A
74 69
75 Document* document = Document::create(); 70 Document* document = Document::create();
76 Element* html = document->createElement("html", StringOrDictionary(), 71 Element* html = document->createElement("html", StringOrDictionary());
77 ASSERT_NO_EXCEPTION);
78 document->appendChild(html, ASSERT_NO_EXCEPTION); 72 document->appendChild(html, ASSERT_NO_EXCEPTION);
79 Element* head = document->createElement("head", StringOrDictionary(), 73 Element* head = document->createElement("head", StringOrDictionary());
80 ASSERT_NO_EXCEPTION);
81 html->appendChild(head); 74 html->appendChild(head);
82 Element* body = document->createElement("body", StringOrDictionary(), 75 Element* body = document->createElement("body", StringOrDictionary());
83 ASSERT_NO_EXCEPTION);
84 html->appendChild(body); 76 html->appendChild(body);
85 77
86 ShadowRoot* shadowRootY = 78 ShadowRoot* shadowRootY =
87 head->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 79 head->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
88 ShadowRoot* shadowRootB = 80 ShadowRoot* shadowRootB =
89 body->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 81 body->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
90 82
91 Element* divInY = 83 Element* divInY = document->createElement("div", StringOrDictionary());
92 document->createElement("div", StringOrDictionary(), ASSERT_NO_EXCEPTION);
93 shadowRootY->appendChild(divInY); 84 shadowRootY->appendChild(divInY);
94 ShadowRoot* shadowRootA = 85 ShadowRoot* shadowRootA =
95 divInY->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); 86 divInY->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
96 87
97 EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB)); 88 EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB));
98 EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA)); 89 EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA));
99 } 90 }
100 91
101 TEST(TreeScopeTest, CommonAncestorOfTreesInDifferentDocuments) { 92 TEST(TreeScopeTest, CommonAncestorOfTreesInDifferentDocuments) {
102 Document* document1 = Document::create(); 93 Document* document1 = Document::create();
103 Document* document2 = Document::create(); 94 Document* document2 = Document::create();
104 EXPECT_EQ(0, document1->commonAncestorTreeScope(*document2)); 95 EXPECT_EQ(0, document1->commonAncestorTreeScope(*document2));
105 EXPECT_EQ(0, document2->commonAncestorTreeScope(*document1)); 96 EXPECT_EQ(0, document2->commonAncestorTreeScope(*document1));
106 } 97 }
107 98
108 } // namespace blink 99 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698