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 "config.h" | 5 #include "config.h" |
6 #include "core/dom/TreeScope.h" | 6 #include "core/dom/TreeScope.h" |
7 | 7 |
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 <gtest/gtest.h> | 11 #include <gtest/gtest.h> |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 TEST(TreeScopeTest, CommonAncestorOfSameTrees) | 15 TEST(TreeScopeTest, CommonAncestorOfSameTrees) |
16 { | 16 { |
17 RefPtrWillBeRawPtr<Document> document = Document::create(); | 17 RefPtrWillBeRawPtr<Document> document = Document::create(); |
18 EXPECT_EQ(document.get(), document->commonAncestorTreeScope(*document)); | 18 EXPECT_EQ(document.get(), document->commonAncestorTreeScope(*document)); |
19 | 19 |
20 RefPtrWillBeRawPtr<Element> html = document->createElement("html", nullAtom,
ASSERT_NO_EXCEPTION); | 20 RefPtrWillBeRawPtr<Element> html = document->createElement("html", nullAtom,
ASSERT_NO_EXCEPTION); |
21 document->appendChild(html, ASSERT_NO_EXCEPTION); | 21 document->appendChild(html, ASSERT_NO_EXCEPTION); |
22 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = html->createShadowRootInternal(S
hadowRootType::OpenByDefault, ASSERT_NO_EXCEPTION); | 22 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = html->createShadowRootInternal(S
hadowRootType::V0, ASSERT_NO_EXCEPTION); |
23 EXPECT_EQ(shadowRoot.get(), shadowRoot->commonAncestorTreeScope(*shadowRoot)
); | 23 EXPECT_EQ(shadowRoot.get(), shadowRoot->commonAncestorTreeScope(*shadowRoot)
); |
24 } | 24 } |
25 | 25 |
26 TEST(TreeScopeTest, CommonAncestorOfInclusiveTrees) | 26 TEST(TreeScopeTest, CommonAncestorOfInclusiveTrees) |
27 { | 27 { |
28 // document | 28 // document |
29 // | : Common ancestor is document. | 29 // | : Common ancestor is document. |
30 // shadowRoot | 30 // shadowRoot |
31 | 31 |
32 RefPtrWillBeRawPtr<Document> document = Document::create(); | 32 RefPtrWillBeRawPtr<Document> document = Document::create(); |
33 RefPtrWillBeRawPtr<Element> html = document->createElement("html", nullAtom,
ASSERT_NO_EXCEPTION); | 33 RefPtrWillBeRawPtr<Element> html = document->createElement("html", nullAtom,
ASSERT_NO_EXCEPTION); |
34 document->appendChild(html, ASSERT_NO_EXCEPTION); | 34 document->appendChild(html, ASSERT_NO_EXCEPTION); |
35 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = html->createShadowRootInternal(S
hadowRootType::OpenByDefault, ASSERT_NO_EXCEPTION); | 35 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = html->createShadowRootInternal(S
hadowRootType::V0, ASSERT_NO_EXCEPTION); |
36 | 36 |
37 EXPECT_EQ(document.get(), document->commonAncestorTreeScope(*shadowRoot)); | 37 EXPECT_EQ(document.get(), document->commonAncestorTreeScope(*shadowRoot)); |
38 EXPECT_EQ(document.get(), shadowRoot->commonAncestorTreeScope(*document)); | 38 EXPECT_EQ(document.get(), shadowRoot->commonAncestorTreeScope(*document)); |
39 } | 39 } |
40 | 40 |
41 TEST(TreeScopeTest, CommonAncestorOfSiblingTrees) | 41 TEST(TreeScopeTest, CommonAncestorOfSiblingTrees) |
42 { | 42 { |
43 // document | 43 // document |
44 // / \ : Common ancestor is document. | 44 // / \ : Common ancestor is document. |
45 // A B | 45 // A B |
46 | 46 |
47 RefPtrWillBeRawPtr<Document> document = Document::create(); | 47 RefPtrWillBeRawPtr<Document> document = Document::create(); |
48 RefPtrWillBeRawPtr<Element> html = document->createElement("html", nullAtom,
ASSERT_NO_EXCEPTION); | 48 RefPtrWillBeRawPtr<Element> html = document->createElement("html", nullAtom,
ASSERT_NO_EXCEPTION); |
49 document->appendChild(html, ASSERT_NO_EXCEPTION); | 49 document->appendChild(html, ASSERT_NO_EXCEPTION); |
50 RefPtrWillBeRawPtr<Element> head = document->createElement("head", nullAtom,
ASSERT_NO_EXCEPTION); | 50 RefPtrWillBeRawPtr<Element> head = document->createElement("head", nullAtom,
ASSERT_NO_EXCEPTION); |
51 html->appendChild(head); | 51 html->appendChild(head); |
52 RefPtrWillBeRawPtr<Element> body = document->createElement("body", nullAtom,
ASSERT_NO_EXCEPTION); | 52 RefPtrWillBeRawPtr<Element> body = document->createElement("body", nullAtom,
ASSERT_NO_EXCEPTION); |
53 html->appendChild(body); | 53 html->appendChild(body); |
54 | 54 |
55 RefPtrWillBeRawPtr<ShadowRoot> shadowRootA = head->createShadowRootInternal(
ShadowRootType::OpenByDefault, ASSERT_NO_EXCEPTION); | 55 RefPtrWillBeRawPtr<ShadowRoot> shadowRootA = head->createShadowRootInternal(
ShadowRootType::V0, ASSERT_NO_EXCEPTION); |
56 RefPtrWillBeRawPtr<ShadowRoot> shadowRootB = body->createShadowRootInternal(
ShadowRootType::OpenByDefault, ASSERT_NO_EXCEPTION); | 56 RefPtrWillBeRawPtr<ShadowRoot> shadowRootB = body->createShadowRootInternal(
ShadowRootType::V0, ASSERT_NO_EXCEPTION); |
57 | 57 |
58 EXPECT_EQ(document.get(), shadowRootA->commonAncestorTreeScope(*shadowRootB)
); | 58 EXPECT_EQ(document.get(), shadowRootA->commonAncestorTreeScope(*shadowRootB)
); |
59 EXPECT_EQ(document.get(), shadowRootB->commonAncestorTreeScope(*shadowRootA)
); | 59 EXPECT_EQ(document.get(), shadowRootB->commonAncestorTreeScope(*shadowRootA)
); |
60 } | 60 } |
61 | 61 |
62 TEST(TreeScopeTest, CommonAncestorOfTreesAtDifferentDepths) | 62 TEST(TreeScopeTest, CommonAncestorOfTreesAtDifferentDepths) |
63 { | 63 { |
64 // document | 64 // document |
65 // / \ : Common ancestor is document. | 65 // / \ : Common ancestor is document. |
66 // Y B | 66 // Y B |
67 // / | 67 // / |
68 // A | 68 // A |
69 | 69 |
70 RefPtrWillBeRawPtr<Document> document = Document::create(); | 70 RefPtrWillBeRawPtr<Document> document = Document::create(); |
71 RefPtrWillBeRawPtr<Element> html = document->createElement("html", nullAtom,
ASSERT_NO_EXCEPTION); | 71 RefPtrWillBeRawPtr<Element> html = document->createElement("html", nullAtom,
ASSERT_NO_EXCEPTION); |
72 document->appendChild(html, ASSERT_NO_EXCEPTION); | 72 document->appendChild(html, ASSERT_NO_EXCEPTION); |
73 RefPtrWillBeRawPtr<Element> head = document->createElement("head", nullAtom,
ASSERT_NO_EXCEPTION); | 73 RefPtrWillBeRawPtr<Element> head = document->createElement("head", nullAtom,
ASSERT_NO_EXCEPTION); |
74 html->appendChild(head); | 74 html->appendChild(head); |
75 RefPtrWillBeRawPtr<Element> body = document->createElement("body", nullAtom,
ASSERT_NO_EXCEPTION); | 75 RefPtrWillBeRawPtr<Element> body = document->createElement("body", nullAtom,
ASSERT_NO_EXCEPTION); |
76 html->appendChild(body); | 76 html->appendChild(body); |
77 | 77 |
78 RefPtrWillBeRawPtr<ShadowRoot> shadowRootY = head->createShadowRootInternal(
ShadowRootType::OpenByDefault, ASSERT_NO_EXCEPTION); | 78 RefPtrWillBeRawPtr<ShadowRoot> shadowRootY = head->createShadowRootInternal(
ShadowRootType::V0, ASSERT_NO_EXCEPTION); |
79 RefPtrWillBeRawPtr<ShadowRoot> shadowRootB = body->createShadowRootInternal(
ShadowRootType::OpenByDefault, ASSERT_NO_EXCEPTION); | 79 RefPtrWillBeRawPtr<ShadowRoot> shadowRootB = body->createShadowRootInternal(
ShadowRootType::V0, ASSERT_NO_EXCEPTION); |
80 | 80 |
81 RefPtrWillBeRawPtr<Element> divInY = document->createElement("div", nullAtom
, ASSERT_NO_EXCEPTION); | 81 RefPtrWillBeRawPtr<Element> divInY = document->createElement("div", nullAtom
, ASSERT_NO_EXCEPTION); |
82 shadowRootY->appendChild(divInY); | 82 shadowRootY->appendChild(divInY); |
83 RefPtrWillBeRawPtr<ShadowRoot> shadowRootA = divInY->createShadowRootInterna
l(ShadowRootType::OpenByDefault, ASSERT_NO_EXCEPTION); | 83 RefPtrWillBeRawPtr<ShadowRoot> shadowRootA = divInY->createShadowRootInterna
l(ShadowRootType::V0, ASSERT_NO_EXCEPTION); |
84 | 84 |
85 EXPECT_EQ(document.get(), shadowRootA->commonAncestorTreeScope(*shadowRootB)
); | 85 EXPECT_EQ(document.get(), shadowRootA->commonAncestorTreeScope(*shadowRootB)
); |
86 EXPECT_EQ(document.get(), shadowRootB->commonAncestorTreeScope(*shadowRootA)
); | 86 EXPECT_EQ(document.get(), shadowRootB->commonAncestorTreeScope(*shadowRootA)
); |
87 } | 87 } |
88 | 88 |
89 TEST(TreeScopeTest, CommonAncestorOfTreesInDifferentDocuments) | 89 TEST(TreeScopeTest, CommonAncestorOfTreesInDifferentDocuments) |
90 { | 90 { |
91 RefPtrWillBeRawPtr<Document> document1 = Document::create(); | 91 RefPtrWillBeRawPtr<Document> document1 = Document::create(); |
92 RefPtrWillBeRawPtr<Document> document2 = Document::create(); | 92 RefPtrWillBeRawPtr<Document> document2 = Document::create(); |
93 EXPECT_EQ(0, document1->commonAncestorTreeScope(*document2)); | 93 EXPECT_EQ(0, document1->commonAncestorTreeScope(*document2)); |
94 EXPECT_EQ(0, document2->commonAncestorTreeScope(*document1)); | 94 EXPECT_EQ(0, document2->commonAncestorTreeScope(*document1)); |
95 } | 95 } |
96 | 96 |
97 } // namespace blink | 97 } // namespace blink |
OLD | NEW |