OLD | NEW |
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/ElementCreationOptionsOrString.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 { | 16 { |
16 Document* document = Document::create(); | 17 Document* document = Document::create(); |
17 EXPECT_EQ(document, document->commonAncestorTreeScope(*document)); | 18 EXPECT_EQ(document, document->commonAncestorTreeScope(*document)); |
18 | 19 |
19 Element* html = document->createElement("html", nullAtom, ASSERT_NO_EXCEPTIO
N); | 20 Element* html = document->createElement("html", ElementCreationOptionsOrStri
ng::fromString(emptyString()), ASSERT_NO_EXCEPTION); |
20 document->appendChild(html, ASSERT_NO_EXCEPTION); | 21 document->appendChild(html, ASSERT_NO_EXCEPTION); |
21 ShadowRoot* shadowRoot = html->createShadowRootInternal(ShadowRootType::V0,
ASSERT_NO_EXCEPTION); | 22 ShadowRoot* shadowRoot = html->createShadowRootInternal(ShadowRootType::V0,
ASSERT_NO_EXCEPTION); |
22 EXPECT_EQ(shadowRoot, shadowRoot->commonAncestorTreeScope(*shadowRoot)); | 23 EXPECT_EQ(shadowRoot, shadowRoot->commonAncestorTreeScope(*shadowRoot)); |
23 } | 24 } |
24 | 25 |
25 TEST(TreeScopeTest, CommonAncestorOfInclusiveTrees) | 26 TEST(TreeScopeTest, CommonAncestorOfInclusiveTrees) |
26 { | 27 { |
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", nullAtom, ASSERT_NO_EXCEPTIO
N); | 33 Element* html = document->createElement("html", ElementCreationOptionsOrStri
ng::fromString(emptyString()), ASSERT_NO_EXCEPTION); |
33 document->appendChild(html, ASSERT_NO_EXCEPTION); | 34 document->appendChild(html, ASSERT_NO_EXCEPTION); |
34 ShadowRoot* shadowRoot = html->createShadowRootInternal(ShadowRootType::V0,
ASSERT_NO_EXCEPTION); | 35 ShadowRoot* shadowRoot = html->createShadowRootInternal(ShadowRootType::V0,
ASSERT_NO_EXCEPTION); |
35 | 36 |
36 EXPECT_EQ(document, document->commonAncestorTreeScope(*shadowRoot)); | 37 EXPECT_EQ(document, document->commonAncestorTreeScope(*shadowRoot)); |
37 EXPECT_EQ(document, shadowRoot->commonAncestorTreeScope(*document)); | 38 EXPECT_EQ(document, shadowRoot->commonAncestorTreeScope(*document)); |
38 } | 39 } |
39 | 40 |
40 TEST(TreeScopeTest, CommonAncestorOfSiblingTrees) | 41 TEST(TreeScopeTest, CommonAncestorOfSiblingTrees) |
41 { | 42 { |
42 // document | 43 // document |
43 // / \ : Common ancestor is document. | 44 // / \ : Common ancestor is document. |
44 // A B | 45 // A B |
45 | 46 |
46 Document* document = Document::create(); | 47 Document* document = Document::create(); |
47 Element* html = document->createElement("html", nullAtom, ASSERT_NO_EXCEPTIO
N); | 48 Element* html = document->createElement("html", ElementCreationOptionsOrStri
ng::fromString(emptyString()), ASSERT_NO_EXCEPTION); |
48 document->appendChild(html, ASSERT_NO_EXCEPTION); | 49 document->appendChild(html, ASSERT_NO_EXCEPTION); |
49 Element* head = document->createElement("head", nullAtom, ASSERT_NO_EXCEPTIO
N); | 50 Element* head = document->createElement("head", ElementCreationOptionsOrStri
ng::fromString(emptyString()), ASSERT_NO_EXCEPTION); |
50 html->appendChild(head); | 51 html->appendChild(head); |
51 Element* body = document->createElement("body", nullAtom, ASSERT_NO_EXCEPTIO
N); | 52 Element* body = document->createElement("body", ElementCreationOptionsOrStri
ng::fromString(emptyString()), ASSERT_NO_EXCEPTION); |
52 html->appendChild(body); | 53 html->appendChild(body); |
53 | 54 |
54 ShadowRoot* shadowRootA = head->createShadowRootInternal(ShadowRootType::V0,
ASSERT_NO_EXCEPTION); | 55 ShadowRoot* shadowRootA = head->createShadowRootInternal(ShadowRootType::V0,
ASSERT_NO_EXCEPTION); |
55 ShadowRoot* shadowRootB = body->createShadowRootInternal(ShadowRootType::V0,
ASSERT_NO_EXCEPTION); | 56 ShadowRoot* shadowRootB = body->createShadowRootInternal(ShadowRootType::V0,
ASSERT_NO_EXCEPTION); |
56 | 57 |
57 EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB)); | 58 EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB)); |
58 EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA)); | 59 EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA)); |
59 } | 60 } |
60 | 61 |
61 TEST(TreeScopeTest, CommonAncestorOfTreesAtDifferentDepths) | 62 TEST(TreeScopeTest, CommonAncestorOfTreesAtDifferentDepths) |
62 { | 63 { |
63 // document | 64 // document |
64 // / \ : Common ancestor is document. | 65 // / \ : Common ancestor is document. |
65 // Y B | 66 // Y B |
66 // / | 67 // / |
67 // A | 68 // A |
68 | 69 |
69 Document* document = Document::create(); | 70 Document* document = Document::create(); |
70 Element* html = document->createElement("html", nullAtom, ASSERT_NO_EXCEPTIO
N); | 71 Element* html = document->createElement("html", ElementCreationOptionsOrStri
ng::fromString(emptyString()), ASSERT_NO_EXCEPTION); |
71 document->appendChild(html, ASSERT_NO_EXCEPTION); | 72 document->appendChild(html, ASSERT_NO_EXCEPTION); |
72 Element* head = document->createElement("head", nullAtom, ASSERT_NO_EXCEPTIO
N); | 73 Element* head = document->createElement("head", ElementCreationOptionsOrStri
ng::fromString(emptyString()), ASSERT_NO_EXCEPTION); |
73 html->appendChild(head); | 74 html->appendChild(head); |
74 Element* body = document->createElement("body", nullAtom, ASSERT_NO_EXCEPTIO
N); | 75 Element* body = document->createElement("body", ElementCreationOptionsOrStri
ng::fromString(emptyString()), ASSERT_NO_EXCEPTION); |
75 html->appendChild(body); | 76 html->appendChild(body); |
76 | 77 |
77 ShadowRoot* shadowRootY = head->createShadowRootInternal(ShadowRootType::V0,
ASSERT_NO_EXCEPTION); | 78 ShadowRoot* shadowRootY = head->createShadowRootInternal(ShadowRootType::V0,
ASSERT_NO_EXCEPTION); |
78 ShadowRoot* shadowRootB = body->createShadowRootInternal(ShadowRootType::V0,
ASSERT_NO_EXCEPTION); | 79 ShadowRoot* shadowRootB = body->createShadowRootInternal(ShadowRootType::V0,
ASSERT_NO_EXCEPTION); |
79 | 80 |
80 Element* divInY = document->createElement("div", nullAtom, ASSERT_NO_EXCEPTI
ON); | 81 Element* divInY = document->createElement("div", ElementCreationOptionsOrStr
ing::fromString(emptyString()), ASSERT_NO_EXCEPTION); |
81 shadowRootY->appendChild(divInY); | 82 shadowRootY->appendChild(divInY); |
82 ShadowRoot* shadowRootA = divInY->createShadowRootInternal(ShadowRootType::V
0, ASSERT_NO_EXCEPTION); | 83 ShadowRoot* shadowRootA = divInY->createShadowRootInternal(ShadowRootType::V
0, ASSERT_NO_EXCEPTION); |
83 | 84 |
84 EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB)); | 85 EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB)); |
85 EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA)); | 86 EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA)); |
86 } | 87 } |
87 | 88 |
88 TEST(TreeScopeTest, CommonAncestorOfTreesInDifferentDocuments) | 89 TEST(TreeScopeTest, CommonAncestorOfTreesInDifferentDocuments) |
89 { | 90 { |
90 Document* document1 = Document::create(); | 91 Document* document1 = Document::create(); |
91 Document* document2 = Document::create(); | 92 Document* document2 = Document::create(); |
92 EXPECT_EQ(0, document1->commonAncestorTreeScope(*document2)); | 93 EXPECT_EQ(0, document1->commonAncestorTreeScope(*document2)); |
93 EXPECT_EQ(0, document2->commonAncestorTreeScope(*document1)); | 94 EXPECT_EQ(0, document2->commonAncestorTreeScope(*document1)); |
94 } | 95 } |
95 | 96 |
96 } // namespace blink | 97 } // namespace blink |
OLD | NEW |