Add a new Web Platform Test in LayoutTest/imported/w3c/web-platform-tests/dom/ranges
https://bugs.webkit.org/show_bug.cgi?id=213667
Patch by Pinki Gyanchandani <pgyanchandani@apple.com> on 2020-06-29
Reviewed by Darin Adler.
Adding a Web Platfotm Test to test the handling of Ranges, when range is associated with a parentless node, and this parentless node moves to
new document.
This test has been provided by Darin Adler.
* web-platform-tests/dom/ranges/Range-adopt-test-expected.txt: Added.
* web-platform-tests/dom/ranges/Range-adopt-test.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@263646 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/imported/w3c/ChangeLog b/LayoutTests/imported/w3c/ChangeLog
index 2b6a67d..57300c4 100644
--- a/LayoutTests/imported/w3c/ChangeLog
+++ b/LayoutTests/imported/w3c/ChangeLog
@@ -1,3 +1,18 @@
+2020-06-29 Pinki Gyanchandani <pgyanchandani@apple.com>
+
+ Add a new Web Platform Test in LayoutTest/imported/w3c/web-platform-tests/dom/ranges
+ https://bugs.webkit.org/show_bug.cgi?id=213667
+
+ Reviewed by Darin Adler.
+
+ Adding a Web Platfotm Test to test the handling of Ranges, when range is associated with a parentless node, and this parentless node moves to
+ new document.
+
+ This test has been provided by Darin Adler.
+
+ * web-platform-tests/dom/ranges/Range-adopt-test-expected.txt: Added.
+ * web-platform-tests/dom/ranges/Range-adopt-test.html: Added.
+
2020-06-28 Rob Buis <rbuis@igalia.com>
Setting url.search="??" (two questionmarks) has incorrect behavior
diff --git a/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-adopt-test-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-adopt-test-expected.txt
new file mode 100644
index 0000000..79fc23b
--- /dev/null
+++ b/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-adopt-test-expected.txt
@@ -0,0 +1,6 @@
+
+PASS Range in document: Removing the only element in the range must collapse the range
+PASS Parented range container moved to another document with appendChild: Moving the element to the other document must collapse the range
+PASS Parentless range container moved to another document with appendChild: Removing the only element in the range must collapse the range
+PASS Range container's parentless container moved to another document with appendChild: Removing the only element in the range must collapse the range
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-adopt-test.html b/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-adopt-test.html
new file mode 100644
index 0000000..3735fc3
--- /dev/null
+++ b/LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-adopt-test.html
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<script src='/resources/testharness.js'></script>
+<script src='/resources/testharnessreport.js'></script>
+<script>
+function createRangeWithUnparentedContainerOfSingleElement() {
+ const range = document.createRange();
+ const container = document.createElement("container");
+ const element = document.createElement("element");
+ container.appendChild(element);
+ range.selectNode(element);
+ return range;
+}
+function nestRangeInOuterContainer(range) {
+ range.startContainer.ownerDocument.createElement("outer").appendChild(range.startContainer);
+}
+function moveNodeToNewlyCreatedDocumentWithAppendChild(node) {
+ document.implementation.createDocument(null, null).appendChild(node);
+}
+
+//Tests removing only element
+test(()=>{
+ const range = createRangeWithUnparentedContainerOfSingleElement();
+ range.startContainer.removeChild(range.startContainer.firstChild);
+ assert_equals(range.endOffset, 0);
+}, "Range in document: Removing the only element in the range must collapse the range");
+
+
+//Tests removing only element after parented container moved to another document
+test(()=>{
+ const range = createRangeWithUnparentedContainerOfSingleElement();
+ nestRangeInOuterContainer(range);
+ moveNodeToNewlyCreatedDocumentWithAppendChild(range.startContainer);
+ assert_equals(range.endOffset, 0);
+}, "Parented range container moved to another document with appendChild: Moving the element to the other document must collapse the range");
+
+//Tests removing only element after parentless container moved oo another document
+test(()=>{
+ const range = createRangeWithUnparentedContainerOfSingleElement();
+ moveNodeToNewlyCreatedDocumentWithAppendChild(range.startContainer);
+ range.startContainer.removeChild(range.startContainer.firstChild);
+ assert_equals(range.endOffset, 0);
+}, "Parentless range container moved to another document with appendChild: Removing the only element in the range must collapse the range");
+
+//Tests removing only element after parentless container of container moved to another document
+test(()=>{
+ const range = createRangeWithUnparentedContainerOfSingleElement();
+ nestRangeInOuterContainer(range);
+ moveNodeToNewlyCreatedDocumentWithAppendChild(range.startContainer.parentNode);
+ range.startContainer.removeChild(range.startContainer.firstChild);
+ assert_equals(range.endOffset, 0);
+}, "Range container's parentless container moved to another document with appendChild: Removing the only element in the range must collapse the range");
+</script>