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

Unified Diff: third_party/WebKit/Source/core/dom/shadow/ComposedTreeTraversalTest.cpp

Issue 1675163002: Rename ComposedTree to FlatTree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wip Created 4 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/shadow/ComposedTreeTraversalTest.cpp
diff --git a/third_party/WebKit/Source/core/dom/shadow/ComposedTreeTraversalTest.cpp b/third_party/WebKit/Source/core/dom/shadow/ComposedTreeTraversalTest.cpp
deleted file mode 100644
index 12f29ac07777654ef7123364e99ae1483bb0a3be..0000000000000000000000000000000000000000
--- a/third_party/WebKit/Source/core/dom/shadow/ComposedTreeTraversalTest.cpp
+++ /dev/null
@@ -1,573 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "core/dom/shadow/ComposedTreeTraversal.h"
-
-#include "bindings/core/v8/ExceptionStatePlaceholder.h"
-#include "core/dom/Document.h"
-#include "core/dom/Element.h"
-#include "core/dom/Node.h"
-#include "core/dom/NodeTraversal.h"
-#include "core/dom/shadow/ShadowRoot.h"
-#include "core/frame/FrameView.h"
-#include "core/html/HTMLDocument.h"
-#include "core/html/HTMLElement.h"
-#include "core/testing/DummyPageHolder.h"
-#include "platform/geometry/IntSize.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "wtf/Compiler.h"
-#include "wtf/OwnPtr.h"
-#include "wtf/PassRefPtr.h"
-#include "wtf/RefPtr.h"
-#include "wtf/StdLibExtras.h"
-#include "wtf/Vector.h"
-
-namespace blink {
-
-class ComposedTreeTraversalTest : public ::testing::Test {
-protected:
- HTMLDocument& document() const;
-
- // Sets |mainHTML| to BODY element with |innerHTML| property and attaches
- // shadow root to child with |shadowHTML|, then update distribution for
- // calling member functions in |ComposedTreeTraversal|.
- void setupSampleHTML(const char* mainHTML, const char* shadowHTML, unsigned);
-
- void setupDocumentTree(const char* mainHTML);
-
- void attachV0ShadowRoot(Element& shadowHost, const char* shadowInnerHTML);
- void attachOpenShadowRoot(Element& shadowHost, const char* shadowInnerHTML);
-
-private:
- void SetUp() override;
-
- RefPtrWillBePersistent<HTMLDocument> m_document;
- OwnPtr<DummyPageHolder> m_dummyPageHolder;
-};
-
-void ComposedTreeTraversalTest::SetUp()
-{
- m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
- m_document = toHTMLDocument(&m_dummyPageHolder->document());
- ASSERT(m_document);
-}
-
-HTMLDocument& ComposedTreeTraversalTest::document() const
-{
- return *m_document;
-}
-
-void ComposedTreeTraversalTest::setupSampleHTML(const char* mainHTML, const char* shadowHTML, unsigned index)
-{
- RefPtrWillBeRawPtr<Element> body = document().body();
- body->setInnerHTML(String::fromUTF8(mainHTML), ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> shadowHost = toElement(NodeTraversal::childAt(*body, index));
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = shadowHost->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
- shadowRoot->setInnerHTML(String::fromUTF8(shadowHTML), ASSERT_NO_EXCEPTION);
- body->updateDistribution();
-}
-
-void ComposedTreeTraversalTest::setupDocumentTree(const char* mainHTML)
-{
- RefPtrWillBeRawPtr<Element> body = document().body();
- body->setInnerHTML(String::fromUTF8(mainHTML), ASSERT_NO_EXCEPTION);
-}
-
-void ComposedTreeTraversalTest::attachV0ShadowRoot(Element& shadowHost, const char* shadowInnerHTML)
-{
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = shadowHost.createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION);
- shadowRoot->setInnerHTML(String::fromUTF8(shadowInnerHTML), ASSERT_NO_EXCEPTION);
- document().body()->updateDistribution();
-}
-
-void ComposedTreeTraversalTest::attachOpenShadowRoot(Element& shadowHost, const char* shadowInnerHTML)
-{
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = shadowHost.createShadowRootInternal(ShadowRootType::Open, ASSERT_NO_EXCEPTION);
- shadowRoot->setInnerHTML(String::fromUTF8(shadowInnerHTML), ASSERT_NO_EXCEPTION);
- document().body()->updateDistribution();
-}
-
-void testCommonAncestor(Node* expectedResult, const Node& nodeA, const Node& nodeB)
-{
- Node* result1 = ComposedTreeTraversal::commonAncestor(nodeA, nodeB);
- EXPECT_EQ(expectedResult, result1) << "commonAncestor(" << nodeA.textContent() << "," << nodeB.textContent() << ")";
- Node* result2 = ComposedTreeTraversal::commonAncestor(nodeB, nodeA);
- EXPECT_EQ(expectedResult, result2) << "commonAncestor(" << nodeB.textContent() << "," << nodeA.textContent() << ")";
-}
-
-// Test case for
-// - childAt
-// - countChildren
-// - hasChildren
-// - index
-// - isDescendantOf
-TEST_F(ComposedTreeTraversalTest, childAt)
-{
- const char* mainHTML =
- "<div id='m0'>"
- "<span id='m00'>m00</span>"
- "<span id='m01'>m01</span>"
- "</div>";
- const char* shadowHTML =
- "<a id='s00'>s00</a>"
- "<content select='#m01'></content>"
- "<a id='s02'>s02</a>"
- "<a id='s03'><content select='#m00'></content></a>"
- "<a id='s04'>s04</a>";
- setupSampleHTML(mainHTML, shadowHTML, 0);
-
- RefPtrWillBeRawPtr<Element> body = document().body();
- RefPtrWillBeRawPtr<Element> m0 = body->querySelector("#m0", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m00 = m0->querySelector("#m00", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m01 = m0->querySelector("#m01", ASSERT_NO_EXCEPTION);
-
- RefPtrWillBeRawPtr<Element> shadowHost = m0;
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = shadowHost->openShadowRoot();
- RefPtrWillBeRawPtr<Element> s00 = shadowRoot->querySelector("#s00", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> s02 = shadowRoot->querySelector("#s02", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> s03 = shadowRoot->querySelector("#s03", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> s04 = shadowRoot->querySelector("#s04", ASSERT_NO_EXCEPTION);
-
- const unsigned numberOfChildNodes = 5;
- Node* expectedChildNodes[5] = { s00.get(), m01.get(), s02.get(), s03.get(), s04.get() };
-
- ASSERT_EQ(numberOfChildNodes, ComposedTreeTraversal::countChildren(*shadowHost));
- EXPECT_TRUE(ComposedTreeTraversal::hasChildren(*shadowHost));
-
- for (unsigned index = 0; index < numberOfChildNodes; ++index) {
- Node* child = ComposedTreeTraversal::childAt(*shadowHost, index);
- EXPECT_EQ(expectedChildNodes[index], child)
- << "ComposedTreeTraversal::childAt(*shadowHost, " << index << ")";
- EXPECT_EQ(index, ComposedTreeTraversal::index(*child))
- << "ComposedTreeTraversal::index(ComposedTreeTraversal(*shadowHost, " << index << "))";
- EXPECT_TRUE(ComposedTreeTraversal::isDescendantOf(*child, *shadowHost))
- << "ComposedTreeTraversal::isDescendantOf(*ComposedTreeTraversal(*shadowHost, " << index << "), *shadowHost)";
- }
- EXPECT_EQ(nullptr, ComposedTreeTraversal::childAt(*shadowHost, numberOfChildNodes + 1))
- << "Out of bounds childAt() returns nullptr.";
-
- // Distribute node |m00| is child of node in shadow tree |s03|.
- EXPECT_EQ(m00.get(), ComposedTreeTraversal::childAt(*s03, 0));
-}
-
-// Test case for
-// - commonAncestor
-// - isDescendantOf
-TEST_F(ComposedTreeTraversalTest, commonAncestor)
-{
- // We build following composed tree:
- // ____BODY___
- // | | |
- // m0 m1 m2 m1 is shadow host having m10, m11, m12.
- // _|_ | __|__
- // | | | | |
- // m00 m01 | m20 m21
- // _____|_____________
- // | | | | |
- // s10 s11 s12 s13 s14
- // |
- // __|__
- // | | |
- // m12 m10 m11 <-- distributed
- // where: each symbol consists with prefix, child index, child-child index.
- // prefix "m" means node in main tree,
- // prefix "d" means node in main tree and distributed
- // prefix "s" means node in shadow tree
- const char* mainHTML =
- "<a id='m0'><b id='m00'>m00</b><b id='m01'>m01</b></a>"
- "<a id='m1'>"
- "<b id='m10'>m10</b>"
- "<b id='m11'>m11</b>"
- "<b id='m12'>m12</b>"
- "</a>"
- "<a id='m2'><b id='m20'>m20</b><b id='m21'>m21</b></a>";
- const char* shadowHTML =
- "<a id='s10'>s10</a>"
- "<a id='s11'><content select='#m12'></content></a>"
- "<a id='s12'>s12</a>"
- "<a id='s13'>"
- "<content select='#m10'></content>"
- "<content select='#m11'></content>"
- "</a>"
- "<a id='s14'>s14</a>";
- setupSampleHTML(mainHTML, shadowHTML, 1);
- RefPtrWillBeRawPtr<Element> body = document().body();
- RefPtrWillBeRawPtr<Element> m0 = body->querySelector("#m0", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m1 = body->querySelector("#m1", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m2 = body->querySelector("#m2", ASSERT_NO_EXCEPTION);
-
- RefPtrWillBeRawPtr<Element> m00 = body->querySelector("#m00", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m01 = body->querySelector("#m01", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m10 = body->querySelector("#m10", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m11 = body->querySelector("#m11", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m12 = body->querySelector("#m12", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m20 = body->querySelector("#m20", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m21 = body->querySelector("#m21", ASSERT_NO_EXCEPTION);
-
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = m1->openShadowRoot();
- RefPtrWillBeRawPtr<Element> s10 = shadowRoot->querySelector("#s10", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> s11 = shadowRoot->querySelector("#s11", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> s12 = shadowRoot->querySelector("#s12", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> s13 = shadowRoot->querySelector("#s13", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> s14 = shadowRoot->querySelector("#s14", ASSERT_NO_EXCEPTION);
-
- testCommonAncestor(body.get(), *m0, *m1);
- testCommonAncestor(body.get(), *m1, *m2);
- testCommonAncestor(body.get(), *m1, *m20);
- testCommonAncestor(body.get(), *s14, *m21);
-
- testCommonAncestor(m0.get(), *m0, *m0);
- testCommonAncestor(m0.get(), *m00, *m01);
-
- testCommonAncestor(m1.get(), *m1.get(), *m1);
- testCommonAncestor(m1.get(), *s10, *s14);
- testCommonAncestor(m1.get(), *s10, *m12);
- testCommonAncestor(m1.get(), *s12, *m12);
- testCommonAncestor(m1.get(), *m10, *m12);
-
- testCommonAncestor(m01.get(), *m01, *m01);
- testCommonAncestor(s11.get(), *s11, *m12);
- testCommonAncestor(s13.get(), *m10, *m11);
-
- s12->remove(ASSERT_NO_EXCEPTION);
- testCommonAncestor(s12.get(), *s12, *s12);
- testCommonAncestor(nullptr, *s12, *s11);
- testCommonAncestor(nullptr, *s12, *m01);
- testCommonAncestor(nullptr, *s12, *m20);
-
- m20->remove(ASSERT_NO_EXCEPTION);
- testCommonAncestor(m20.get(), *m20, *m20);
- testCommonAncestor(nullptr, *m20, *s12);
- testCommonAncestor(nullptr, *m20, *m1);
-}
-
-// Test case for
-// - nextSkippingChildren
-// - previousSkippingChildren
-TEST_F(ComposedTreeTraversalTest, nextSkippingChildren)
-{
- const char* mainHTML =
- "<div id='m0'>m0</div>"
- "<div id='m1'>"
- "<span id='m10'>m10</span>"
- "<span id='m11'>m11</span>"
- "</div>"
- "<div id='m2'>m2</div>";
- const char* shadowHTML =
- "<content select='#m11'></content>"
- "<a id='s11'>s11</a>"
- "<a id='s12'>"
- "<b id='s120'>s120</b>"
- "<content select='#m10'></content>"
- "</a>";
- setupSampleHTML(mainHTML, shadowHTML, 1);
-
- RefPtrWillBeRawPtr<Element> body = document().body();
- RefPtrWillBeRawPtr<Element> m0 = body->querySelector("#m0", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m1 = body->querySelector("#m1", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m2 = body->querySelector("#m2", ASSERT_NO_EXCEPTION);
-
- RefPtrWillBeRawPtr<Element> m10 = body->querySelector("#m10", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m11 = body->querySelector("#m11", ASSERT_NO_EXCEPTION);
-
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = m1->openShadowRoot();
- RefPtrWillBeRawPtr<Element> s11 = shadowRoot->querySelector("#s11", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> s12 = shadowRoot->querySelector("#s12", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> s120 = shadowRoot->querySelector("#s120", ASSERT_NO_EXCEPTION);
-
- // Main tree node to main tree node
- EXPECT_EQ(*m1, ComposedTreeTraversal::nextSkippingChildren(*m0));
- EXPECT_EQ(*m0, ComposedTreeTraversal::previousSkippingChildren(*m1));
-
- // Distribute node to main tree node
- EXPECT_EQ(*m2, ComposedTreeTraversal::nextSkippingChildren(*m10));
- EXPECT_EQ(*m1, ComposedTreeTraversal::previousSkippingChildren(*m2));
-
- // Distribute node to node in shadow tree
- EXPECT_EQ(*s11, ComposedTreeTraversal::nextSkippingChildren(*m11));
- EXPECT_EQ(*m11, ComposedTreeTraversal::previousSkippingChildren(*s11));
-
- // Node in shadow tree to distributed node
- EXPECT_EQ(*s11, ComposedTreeTraversal::nextSkippingChildren(*m11));
- EXPECT_EQ(*m11, ComposedTreeTraversal::previousSkippingChildren(*s11));
-
- EXPECT_EQ(*m10, ComposedTreeTraversal::nextSkippingChildren(*s120));
- EXPECT_EQ(*s120, ComposedTreeTraversal::previousSkippingChildren(*m10));
-
- // Node in shadow tree to main tree
- EXPECT_EQ(*m2, ComposedTreeTraversal::nextSkippingChildren(*s12));
- EXPECT_EQ(*m1, ComposedTreeTraversal::previousSkippingChildren(*m2));
-}
-
-// Test case for
-// - lastWithin
-// - lastWithinOrSelf
-TEST_F(ComposedTreeTraversalTest, lastWithin)
-{
- const char* mainHTML =
- "<div id='m0'>m0</div>"
- "<div id='m1'>"
- "<span id='m10'>m10</span>"
- "<span id='m11'>m11</span>"
- "<span id='m12'>m12</span>" // #m12 is not distributed.
- "</div>"
- "<div id='m2'></div>";
- const char* shadowHTML =
- "<content select='#m11'></content>"
- "<a id='s11'>s11</a>"
- "<a id='s12'>"
- "<content select='#m10'></content>"
- "</a>";
- setupSampleHTML(mainHTML, shadowHTML, 1);
-
- RefPtrWillBeRawPtr<Element> body = document().body();
- RefPtrWillBeRawPtr<Element> m0 = body->querySelector("#m0", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m1 = body->querySelector("#m1", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m2 = body->querySelector("#m2", ASSERT_NO_EXCEPTION);
-
- RefPtrWillBeRawPtr<Element> m10 = body->querySelector("#m10", ASSERT_NO_EXCEPTION);
-
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = m1->openShadowRoot();
- RefPtrWillBeRawPtr<Element> s11 = shadowRoot->querySelector("#s11", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> s12 = shadowRoot->querySelector("#s12", ASSERT_NO_EXCEPTION);
-
- EXPECT_EQ(m0->firstChild(), ComposedTreeTraversal::lastWithin(*m0));
- EXPECT_EQ(*m0->firstChild(), ComposedTreeTraversal::lastWithinOrSelf(*m0));
-
- EXPECT_EQ(m10->firstChild(), ComposedTreeTraversal::lastWithin(*m1));
- EXPECT_EQ(*m10->firstChild(), ComposedTreeTraversal::lastWithinOrSelf(*m1));
-
- EXPECT_EQ(nullptr, ComposedTreeTraversal::lastWithin(*m2));
- EXPECT_EQ(*m2, ComposedTreeTraversal::lastWithinOrSelf(*m2));
-
- EXPECT_EQ(s11->firstChild(), ComposedTreeTraversal::lastWithin(*s11));
- EXPECT_EQ(*s11->firstChild(), ComposedTreeTraversal::lastWithinOrSelf(*s11));
-
- EXPECT_EQ(m10->firstChild(), ComposedTreeTraversal::lastWithin(*s12));
- EXPECT_EQ(*m10->firstChild(), ComposedTreeTraversal::lastWithinOrSelf(*s12));
-}
-
-TEST_F(ComposedTreeTraversalTest, previousPostOrder)
-{
- const char* mainHTML =
- "<div id='m0'>m0</div>"
- "<div id='m1'>"
- "<span id='m10'>m10</span>"
- "<span id='m11'>m11</span>"
- "</div>"
- "<div id='m2'>m2</div>";
- const char* shadowHTML =
- "<content select='#m11'></content>"
- "<a id='s11'>s11</a>"
- "<a id='s12'>"
- "<b id='s120'>s120</b>"
- "<content select='#m10'></content>"
- "</a>";
- setupSampleHTML(mainHTML, shadowHTML, 1);
-
- RefPtrWillBeRawPtr<Element> body = document().body();
- RefPtrWillBeRawPtr<Element> m0 = body->querySelector("#m0", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m1 = body->querySelector("#m1", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m2 = body->querySelector("#m2", ASSERT_NO_EXCEPTION);
-
- RefPtrWillBeRawPtr<Element> m10 = body->querySelector("#m10", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m11 = body->querySelector("#m11", ASSERT_NO_EXCEPTION);
-
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = m1->openShadowRoot();
- RefPtrWillBeRawPtr<Element> s11 = shadowRoot->querySelector("#s11", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> s12 = shadowRoot->querySelector("#s12", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> s120 = shadowRoot->querySelector("#s120", ASSERT_NO_EXCEPTION);
-
- EXPECT_EQ(*m0->firstChild(), ComposedTreeTraversal::previousPostOrder(*m0));
- EXPECT_EQ(*s12, ComposedTreeTraversal::previousPostOrder(*m1));
- EXPECT_EQ(*m10->firstChild(), ComposedTreeTraversal::previousPostOrder(*m10));
- EXPECT_EQ(*s120, ComposedTreeTraversal::previousPostOrder(*m10->firstChild()));
- EXPECT_EQ(*s120, ComposedTreeTraversal::previousPostOrder(*m10->firstChild(), s12.get()));
- EXPECT_EQ(*m11->firstChild(), ComposedTreeTraversal::previousPostOrder(*m11));
- EXPECT_EQ(*m0, ComposedTreeTraversal::previousPostOrder(*m11->firstChild()));
- EXPECT_EQ(nullptr, ComposedTreeTraversal::previousPostOrder(*m11->firstChild(), m11.get()));
- EXPECT_EQ(*m2->firstChild(), ComposedTreeTraversal::previousPostOrder(*m2));
-
- EXPECT_EQ(*s11->firstChild(), ComposedTreeTraversal::previousPostOrder(*s11));
- EXPECT_EQ(*m10, ComposedTreeTraversal::previousPostOrder(*s12));
- EXPECT_EQ(*s120->firstChild(), ComposedTreeTraversal::previousPostOrder(*s120));
- EXPECT_EQ(*s11, ComposedTreeTraversal::previousPostOrder(*s120->firstChild()));
- EXPECT_EQ(nullptr, ComposedTreeTraversal::previousPostOrder(*s120->firstChild(), s12.get()));
-}
-
-TEST_F(ComposedTreeTraversalTest, nextSiblingNotInDocumentComposedTree)
-{
- const char* mainHTML =
- "<div id='m0'>m0</div>"
- "<div id='m1'>"
- "<span id='m10'>m10</span>"
- "<span id='m11'>m11</span>"
- "</div>"
- "<div id='m2'>m2</div>";
- const char* shadowHTML =
- "<content select='#m11'></content>";
- setupSampleHTML(mainHTML, shadowHTML, 1);
-
- RefPtrWillBeRawPtr<Element> body = document().body();
- RefPtrWillBeRawPtr<Element> m10 = body->querySelector("#m10", ASSERT_NO_EXCEPTION);
-
- EXPECT_EQ(nullptr, ComposedTreeTraversal::nextSibling(*m10));
- EXPECT_EQ(nullptr, ComposedTreeTraversal::previousSibling(*m10));
-}
-
-TEST_F(ComposedTreeTraversalTest, redistribution)
-{
- const char* mainHTML =
- "<div id='m0'>m0</div>"
- "<div id='m1'>"
- "<span id='m10'>m10</span>"
- "<span id='m11'>m11</span>"
- "</div>"
- "<div id='m2'>m2</div>";
- const char* shadowHTML1 =
- "<div id='s1'>"
- "<content></content>"
- "</div>";
-
- setupSampleHTML(mainHTML, shadowHTML1, 1);
-
- const char* shadowHTML2 =
- "<div id='s2'>"
- "<content select='#m10'></content>"
- "<span id='s21'>s21</span>"
- "</div>";
-
- RefPtrWillBeRawPtr<Element> body = document().body();
- RefPtrWillBeRawPtr<Element> m1 = body->querySelector("#m1", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> m10 = body->querySelector("#m10", ASSERT_NO_EXCEPTION);
-
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = m1->openShadowRoot();
- RefPtrWillBeRawPtr<Element> s1 = shadowRoot1->querySelector("#s1", ASSERT_NO_EXCEPTION);
-
- attachV0ShadowRoot(*s1, shadowHTML2);
-
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot2 = s1->openShadowRoot();
- RefPtrWillBeRawPtr<Element> s21 = shadowRoot2->querySelector("#s21", ASSERT_NO_EXCEPTION);
-
- EXPECT_EQ(s21.get(), ComposedTreeTraversal::nextSibling(*m10));
- EXPECT_EQ(m10.get(), ComposedTreeTraversal::previousSibling(*s21));
-
- // ComposedTreeTraversal::traverseSiblings does not work for a node which is not in a document composed tree.
- // e.g. The following test fails. The result of ComposedTreeTraversal::previousSibling(*m11)) will be #m10, instead of nullptr.
- // RefPtrWillBeRawPtr<Element> m11 = body->querySelector("#m11", ASSERT_NO_EXCEPTION);
- // EXPECT_EQ(nullptr, ComposedTreeTraversal::previousSibling(*m11));
-}
-
-TEST_F(ComposedTreeTraversalTest, v1Simple)
-{
- const char* mainHTML =
- "<div id='host'>"
- "<div id='child1' slot='slot1'></div>"
- "<div id='child2' slot='slot2'></div>"
- "</div>";
- const char* shadowHTML =
- "<div id='shadow-child1'></div>"
- "<slot name='slot1'></slot>"
- "<slot name='slot2'></slot>"
- "<div id='shadow-child2'></div>";
-
- setupDocumentTree(mainHTML);
- RefPtrWillBeRawPtr<Element> body = document().body();
- RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> child1 = body->querySelector("#child1", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> child2 = body->querySelector("#child2", ASSERT_NO_EXCEPTION);
-
- attachOpenShadowRoot(*host, shadowHTML);
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = host->openShadowRoot();
- RefPtrWillBeRawPtr<Element> slot1 = shadowRoot->querySelector("[name=slot1]", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> slot2 = shadowRoot->querySelector("[name=slot2]", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> shadowChild1 = shadowRoot->querySelector("#shadow-child1", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> shadowChild2 = shadowRoot->querySelector("#shadow-child2", ASSERT_NO_EXCEPTION);
-
- EXPECT_TRUE(slot1);
- EXPECT_TRUE(slot2);
- EXPECT_EQ(shadowChild1.get(), ComposedTreeTraversal::firstChild(*host));
- EXPECT_EQ(child1.get(), ComposedTreeTraversal::nextSibling(*shadowChild1));
- EXPECT_EQ(child2.get(), ComposedTreeTraversal::nextSibling(*child1));
- EXPECT_EQ(shadowChild2.get(), ComposedTreeTraversal::nextSibling(*child2));
-}
-
-TEST_F(ComposedTreeTraversalTest, v1Redistribution)
-{
- const char* mainHTML =
- "<div id='d1'>"
- "<div id='d2' slot='d1-s1'></div>"
- "<div id='d3' slot='d1-s2'></div>"
- "<div id='d4' slot='nonexistent'></div>"
- "<div id='d5'></div>"
- "</div>"
- "<div id='d6'></div>";
- const char* shadowHTML1 =
- "<div id='d1-1'>"
- "<div id='d1-2'></div>"
- "<slot id='d1-s0'></slot>"
- "<slot name='d1-s1' slot='d1-1-s1'></slot>"
- "<slot name='d1-s2'></slot>"
- "<div id='d1-3'></div>"
- "<div id='d1-4' slot='d1-1-s1'></div>"
- "</div>";
- const char* shadowHTML2 =
- "<div id='d1-1-1'></div>"
- "<slot name='d1-1-s1'></slot>"
- "<slot name='d1-1-s2'></slot>"
- "<div id='d1-1-2'></div>";
-
- setupDocumentTree(mainHTML);
-
- RefPtrWillBeRawPtr<Element> body = document().body();
- RefPtrWillBeRawPtr<Element> d1 = body->querySelector("#d1", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d2 = body->querySelector("#d2", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d3 = body->querySelector("#d3", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d4 = body->querySelector("#d4", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d5 = body->querySelector("#d5", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d6 = body->querySelector("#d6", ASSERT_NO_EXCEPTION);
-
- attachOpenShadowRoot(*d1, shadowHTML1);
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = d1->openShadowRoot();
- RefPtrWillBeRawPtr<Element> d11 = shadowRoot1->querySelector("#d1-1", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d12 = shadowRoot1->querySelector("#d1-2", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d13 = shadowRoot1->querySelector("#d1-3", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d14 = shadowRoot1->querySelector("#d1-4", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d1s0 = shadowRoot1->querySelector("#d1-s0", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d1s1 = shadowRoot1->querySelector("[name=d1-s1]", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d1s2 = shadowRoot1->querySelector("[name=d1-s2]", ASSERT_NO_EXCEPTION);
-
- attachOpenShadowRoot(*d11, shadowHTML2);
- RefPtrWillBeRawPtr<ShadowRoot> shadowRoot2 = d11->openShadowRoot();
- RefPtrWillBeRawPtr<Element> d111 = shadowRoot2->querySelector("#d1-1-1", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d112 = shadowRoot2->querySelector("#d1-1-2", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d11s1 = shadowRoot2->querySelector("[name=d1-1-s1]", ASSERT_NO_EXCEPTION);
- RefPtrWillBeRawPtr<Element> d11s2 = shadowRoot2->querySelector("[name=d1-1-s2]", ASSERT_NO_EXCEPTION);
-
- EXPECT_TRUE(d5);
- EXPECT_TRUE(d12);
- EXPECT_TRUE(d13);
- EXPECT_TRUE(d1s0);
- EXPECT_TRUE(d1s1);
- EXPECT_TRUE(d1s2);
- EXPECT_TRUE(d11s1);
- EXPECT_TRUE(d11s2);
- EXPECT_EQ(d11.get(), ComposedTreeTraversal::next(*d1));
- EXPECT_EQ(d111.get(), ComposedTreeTraversal::next(*d11));
- EXPECT_EQ(d2.get(), ComposedTreeTraversal::next(*d111));
- EXPECT_EQ(d14.get(), ComposedTreeTraversal::next(*d2));
- EXPECT_EQ(d112.get(), ComposedTreeTraversal::next(*d14));
- EXPECT_EQ(d6.get(), ComposedTreeTraversal::next(*d112));
-
- EXPECT_EQ(d112.get(), ComposedTreeTraversal::previous(*d6));
-
- EXPECT_EQ(d11.get(), ComposedTreeTraversal::parent(*d111));
- EXPECT_EQ(d11.get(), ComposedTreeTraversal::parent(*d112));
- EXPECT_EQ(d11.get(), ComposedTreeTraversal::parent(*d2));
- EXPECT_EQ(d11.get(), ComposedTreeTraversal::parent(*d14));
- EXPECT_EQ(nullptr, ComposedTreeTraversal::parent(*d3));
- EXPECT_EQ(nullptr, ComposedTreeTraversal::parent(*d4));
-}
-
-} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698