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