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

Side by Side Diff: sky/engine/core/dom/TreeScopeTest.cpp

Issue 759663003: Only allow one shadowRoot. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: ojan review. Created 6 years 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 "sky/engine/config.h" 5 #include "sky/engine/config.h"
6 #include "sky/engine/core/dom/TreeScope.h" 6 #include "sky/engine/core/dom/TreeScope.h"
7 7
8 #include <gtest/gtest.h> 8 #include <gtest/gtest.h>
9 #include "sky/engine/core/dom/Document.h" 9 #include "sky/engine/core/dom/Document.h"
10 #include "sky/engine/core/dom/Element.h" 10 #include "sky/engine/core/dom/Element.h"
11 #include "sky/engine/core/dom/shadow/ShadowRoot.h" 11 #include "sky/engine/core/dom/shadow/ShadowRoot.h"
12 12
13 using namespace blink; 13 using namespace blink;
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 RefPtr<Element> html = document->createElement("html", nullAtom, ASSERT_NO_E XCEPTION); 22 RefPtr<Element> html = document->createElement("html", nullAtom, ASSERT_NO_E XCEPTION);
23 document->appendChild(html, ASSERT_NO_EXCEPTION); 23 document->appendChild(html, ASSERT_NO_EXCEPTION);
24 RefPtr<ShadowRoot> shadowRoot = html->createShadowRoot(ASSERT_NO_EXCEPTION); 24 RefPtr<ShadowRoot> shadowRoot = html->ensureShadowRoot(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 RefPtr<Element> html = document->createElement("html", nullAtom, ASSERT_NO_E XCEPTION); 35 RefPtr<Element> html = document->createElement("html", nullAtom, ASSERT_NO_E XCEPTION);
36 document->appendChild(html, ASSERT_NO_EXCEPTION); 36 document->appendChild(html, ASSERT_NO_EXCEPTION);
37 RefPtr<ShadowRoot> shadowRoot = html->createShadowRoot(ASSERT_NO_EXCEPTION); 37 RefPtr<ShadowRoot> shadowRoot = html->ensureShadowRoot(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 RefPtr<Element> html = document->createElement("html", nullAtom, ASSERT_NO_E XCEPTION); 50 RefPtr<Element> html = document->createElement("html", nullAtom, ASSERT_NO_E XCEPTION);
51 document->appendChild(html, ASSERT_NO_EXCEPTION); 51 document->appendChild(html, ASSERT_NO_EXCEPTION);
52 RefPtr<Element> head = document->createElement("head", nullAtom, ASSERT_NO_E XCEPTION); 52 RefPtr<Element> head = document->createElement("head", nullAtom, ASSERT_NO_E XCEPTION);
53 html->appendChild(head); 53 html->appendChild(head);
54 RefPtr<Element> body = document->createElement("body", nullAtom, ASSERT_NO_E XCEPTION); 54 RefPtr<Element> body = document->createElement("body", nullAtom, ASSERT_NO_E XCEPTION);
55 html->appendChild(body); 55 html->appendChild(body);
56 56
57 RefPtr<ShadowRoot> shadowRootA = head->createShadowRoot(ASSERT_NO_EXCEPTION) ; 57 RefPtr<ShadowRoot> shadowRootA = head->ensureShadowRoot(ASSERT_NO_EXCEPTION) ;
58 RefPtr<ShadowRoot> shadowRootB = body->createShadowRoot(ASSERT_NO_EXCEPTION) ; 58 RefPtr<ShadowRoot> shadowRootB = body->ensureShadowRoot(ASSERT_NO_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 RefPtr<Element> html = document->createElement("html", nullAtom, ASSERT_NO_E XCEPTION); 73 RefPtr<Element> html = document->createElement("html", nullAtom, ASSERT_NO_E XCEPTION);
74 document->appendChild(html, ASSERT_NO_EXCEPTION); 74 document->appendChild(html, ASSERT_NO_EXCEPTION);
75 RefPtr<Element> head = document->createElement("head", nullAtom, ASSERT_NO_E XCEPTION); 75 RefPtr<Element> head = document->createElement("head", nullAtom, ASSERT_NO_E XCEPTION);
76 html->appendChild(head); 76 html->appendChild(head);
77 RefPtr<Element> body = document->createElement("body", nullAtom, ASSERT_NO_E XCEPTION); 77 RefPtr<Element> body = document->createElement("body", nullAtom, ASSERT_NO_E XCEPTION);
78 html->appendChild(body); 78 html->appendChild(body);
79 79
80 RefPtr<ShadowRoot> shadowRootY = head->createShadowRoot(ASSERT_NO_EXCEPTION) ; 80 RefPtr<ShadowRoot> shadowRootY = head->ensureShadowRoot(ASSERT_NO_EXCEPTION) ;
81 RefPtr<ShadowRoot> shadowRootB = body->createShadowRoot(ASSERT_NO_EXCEPTION) ; 81 RefPtr<ShadowRoot> shadowRootB = body->ensureShadowRoot(ASSERT_NO_EXCEPTION) ;
82 82
83 RefPtr<Element> divInY = document->createElement("div", nullAtom, ASSERT_NO_ EXCEPTION); 83 RefPtr<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 RefPtr<ShadowRoot> shadowRootA = divInY->ensureShadowRoot(ASSERT_NO_EXCEPTIO N);
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
OLDNEW
« no previous file with comments | « sky/engine/core/dom/TreeScopeAdopter.cpp ('k') | sky/engine/core/dom/shadow/ComposedTreeWalker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698