// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "third_party/blink/renderer/core/html/forms/html_form_element.h" #include "base/test/scoped_feature_list.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/renderer/core/dom/shadow_root.h" #include "third_party/blink/renderer/core/html/forms/html_input_element.h" #include "third_party/blink/renderer/core/html/html_body_element.h" #include "third_party/blink/renderer/core/testing/page_test_base.h" #include "third_party/googletest/src/googlemock/include/gmock/gmock-matchers.h" namespace blink { ElementsAre; IsEmpty; class HTMLFormElementTest : public PageTestBase { … }; void HTMLFormElementTest::SetUp() { … } // This tree is created manually because the HTML parser removes nested forms. // The created tree looks like this: // <body> // <form id=form1> // <form id=form2> // <input> TEST_F(HTMLFormElementTest, ListedElementsNestedForms) { … } TEST_F(HTMLFormElementTest, ListedElementsDetachedForm) { … } // This tree is created manually because the HTML parser removes nested forms. // The created tree looks like this: // <body> // <form id=form1> // <div id=form1div> // <template shadowrootmode=open> // <form id=form2> // <form id=form3> // <div id=form3div> // <template shadowrootmode=open> // // An <input> element is appended at the bottom and moved up one node at a time // in this tree, and each step of the way, ListedElements is checked on all // forms. TEST_F(HTMLFormElementTest, ListedElementsIncludeShadowTrees) { … } TEST_F(HTMLFormElementTest, ListedElementsAfterIncludeShadowTrees) { … } // Regression test for crbug.com/349121116: If there are no "form" attributes, // the traversal in CollectListedElements() must only collect descendants of the // form element. TEST_F(HTMLFormElementTest, ListedElementsIncludesOnlyDescendants) { … } // Tests that form control elements inside nested forms are extracted and // included in `ListedElements` if `include_shadow_trees` is true. TEST_F(HTMLFormElementTest, ListedElementsInNestedForms) { … } // Tests that dynamic addition and removal of an element inside Shadow DOM // properly invalidates the caches of all ancestors. TEST_F(HTMLFormElementTest, ListedElementsInDeepNestedForms) { … } // Tests that changes inside nested forms inside light DOM properly invalidate // the cache for listed elements. TEST_F(HTMLFormElementTest, ListedElementsInDeepNestedFormsLightDom) { … } // Tests that the listed elements of a form `f` only include elements inside // shadow DOM whose shadow hosts are descendants of `f`. TEST_F(HTMLFormElementTest, ShadowDomTreesMustBeDescendantsOfForm) { … } // Tests that dynamic nested form insertions properly invalidate the cache of // listed elements. TEST_F(HTMLFormElementTest, FormInsertionsInvalidateFormCaches) { … } // Tests that dynamic nested form removals properly invalidate the cache of // listed elements. TEST_F(HTMLFormElementTest, FormRemovalsInvalidateFormCaches) { … } // Tests that `include_shadow_trees=true` also includes form control elements // that are associated via form-attribute with forms nested inside the form // whose listed elements we are examining. TEST_F(HTMLFormElementTest, ElementsAssociateWithNestedForms) { … } } // namespace blink