TEST(TreeScopeTest, CommonAncestorOfTreesAtDifferentDepths) { // document // / \ : Common ancestor is document. // Y B // / // A Document* document = Document::create(); Element* html = document->createElement("html", StringOrDictionary()); document->appendChild(html); Element* head = document->createElement("head", StringOrDictionary()); html->appendChild(head); Element* body = document->createElement("body", StringOrDictionary()); html->appendChild(body); ShadowRoot* shadowRootY = head->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); ShadowRoot* shadowRootB = body->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); Element* divInY = document->createElement("div", StringOrDictionary()); shadowRootY->appendChild(divInY); ShadowRoot* shadowRootA = divInY->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); EXPECT_EQ(document, shadowRootA->commonAncestorTreeScope(*shadowRootB)); EXPECT_EQ(document, shadowRootB->commonAncestorTreeScope(*shadowRootA)); }
Element* createElementWithId(const char* localName, const char* id) { NonThrowableExceptionState noExceptions; Element* element = document()->createElement( localName, StringOrDictionary(), noExceptions); element->setAttribute(HTMLNames::idAttr, id); return element; }
TEST(TreeScopeTest, CommonAncestorOfSameTrees) { Document* document = Document::create(); EXPECT_EQ(document, document->commonAncestorTreeScope(*document)); Element* html = document->createElement("html", StringOrDictionary()); document->appendChild(html); ShadowRoot* shadowRoot = html->createShadowRootInternal(ShadowRootType::V0, ASSERT_NO_EXCEPTION); EXPECT_EQ(shadowRoot, shadowRoot->commonAncestorTreeScope(*shadowRoot)); }
TEST_F(CustomElementUpgradeSorterTest, oneCandidate) { NonThrowableExceptionState noExceptions; Element* element = document()->createElement("a-a", StringOrDictionary(), noExceptions); document()->documentElement()->appendChild(element); CustomElementUpgradeSorter sorter; sorter.add(element); HeapVector<Member<Element>> elements; sorter.sorted(&elements, document()); EXPECT_EQ(1u, elements.size()) << "exactly one candidate should be in the result set"; EXPECT_TRUE(elements.contains(element)) << "the candidate should be the element that was added"; }
TEST_F(CustomElementUpgradeSorterTest, inOtherDocument_notInSet) { NonThrowableExceptionState noExceptions; Element* element = document()->createElement("a-a", StringOrDictionary(), noExceptions); Document* otherDocument = HTMLDocument::create(); otherDocument->appendChild(element); EXPECT_EQ(otherDocument, element->ownerDocument()) << "sanity: another document should have adopted an element on append"; CustomElementUpgradeSorter sorter; sorter.add(element); HeapVector<Member<Element>> elements; sorter.sorted(&elements, document()); EXPECT_EQ(0u, elements.size()) << "the adopted-away candidate should not have been included"; }