Title: [285084] trunk
Revision
285084
Author
commit-qu...@webkit.org
Date
2021-10-30 15:58:21 -0700 (Sat, 30 Oct 2021)

Log Message

Selection extend() should trigger exception with no ranges
https://bugs.webkit.org/show_bug.cgi?id=232420

Patch by Brandon Stewart <brandonstew...@apple.com> on 2021-10-30
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

Verify extend() will throw an exception when the Selection object
contains no Range objects. Chrome and Firefox will also throw an
exception in this scenario.

https://w3c.github.io/selection-api/#dom-selection-extend

* web-platform-tests/selection/extend-exception-expected.txt: Added.
* web-platform-tests/selection/extend-exception.html: Added.

Source/WebCore:

The 'extend' method in the Selection API should throw an exception upon
being called if there are no ranges present in the Selection object.

https://w3c.github.io/selection-api/#dom-selection-extend

Test: imported/w3c/web-platform-tests/selection/extend-exception.html

* page/DOMSelection.cpp:
(WebCore::DOMSelection::extend):

LayoutTests:

Resolve errors in test cases introduced by new exception being thrown by extend()
when no ranges are present.

* editing/execCommand/null_calc_primitive_value_for_css_property.html:
* editing/execCommand/transpose-backslash-with-euc.html:
* editing/inserting/insert-html-crash-02.html:
* editing/selection/DOMSelection-crossing-document-expected.txt:
* editing/selection/DOMSelection-crossing-document.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (285083 => 285084)


--- trunk/LayoutTests/ChangeLog	2021-10-30 19:57:56 UTC (rev 285083)
+++ trunk/LayoutTests/ChangeLog	2021-10-30 22:58:21 UTC (rev 285084)
@@ -1,3 +1,19 @@
+2021-10-30  Brandon Stewart  <brandonstew...@apple.com>
+
+        Selection extend() should trigger exception with no ranges
+        https://bugs.webkit.org/show_bug.cgi?id=232420
+
+        Reviewed by Chris Dumez.
+
+        Resolve errors in test cases introduced by new exception being thrown by extend()
+        when no ranges are present.
+
+        * editing/execCommand/null_calc_primitive_value_for_css_property.html:
+        * editing/execCommand/transpose-backslash-with-euc.html:
+        * editing/inserting/insert-html-crash-02.html:
+        * editing/selection/DOMSelection-crossing-document-expected.txt:
+        * editing/selection/DOMSelection-crossing-document.html:
+
 2021-10-29  Lauro Moura  <lmo...@igalia.com>
 
         [GLIB] Gardening timeouts affected by xhtml mimetype misdetection

Modified: trunk/LayoutTests/editing/execCommand/null_calc_primitive_value_for_css_property.html (285083 => 285084)


--- trunk/LayoutTests/editing/execCommand/null_calc_primitive_value_for_css_property.html	2021-10-30 19:57:56 UTC (rev 285083)
+++ trunk/LayoutTests/editing/execCommand/null_calc_primitive_value_for_css_property.html	2021-10-30 22:58:21 UTC (rev 285084)
@@ -10,7 +10,9 @@
     if (window.testRunner)
         testRunner.dumpAsText();
 
-    document.getSelection().extend(x); 
+    document.getSelection().collapse(x, 0);
+    document.getSelection().extend(x);
+
     document.execCommand("insertHTML", false, "The test passes if there is no crash.");
 }
 </script>

Modified: trunk/LayoutTests/editing/execCommand/transpose-backslash-with-euc.html (285083 => 285084)


--- trunk/LayoutTests/editing/execCommand/transpose-backslash-with-euc.html	2021-10-30 19:57:56 UTC (rev 285083)
+++ trunk/LayoutTests/editing/execCommand/transpose-backslash-with-euc.html	2021-10-30 22:58:21 UTC (rev 285084)
@@ -11,6 +11,7 @@
 function test()
 {
     var backslashDivElement = document.getElementById("backslash");
+    getSelection().collapse(backslashDivElement, 0);
     getSelection().extend(backslashDivElement, 1);
     document.execCommand("Transpose");
 

Modified: trunk/LayoutTests/editing/inserting/insert-html-crash-02.html (285083 => 285084)


--- trunk/LayoutTests/editing/inserting/insert-html-crash-02.html	2021-10-30 19:57:56 UTC (rev 285083)
+++ trunk/LayoutTests/editing/inserting/insert-html-crash-02.html	2021-10-30 22:58:21 UTC (rev 285084)
@@ -13,6 +13,7 @@
     let iframe0 = document.createElement('iframe');
     document.body.appendChild(iframe0);
     document.body.appendChild(document.createElement('iframe'));
+    getSelection().collapse(document.body, 0);
     getSelection().extend(document.body);
     iframe0.contentDocument._onvisibilitychange_ = () => {
       document.execCommand('InsertHTML', false, 'foo');

Modified: trunk/LayoutTests/editing/selection/DOMSelection-crossing-document-expected.txt (285083 => 285084)


--- trunk/LayoutTests/editing/selection/DOMSelection-crossing-document-expected.txt	2021-10-30 19:57:56 UTC (rev 285083)
+++ trunk/LayoutTests/editing/selection/DOMSelection-crossing-document-expected.txt	2021-10-30 22:58:21 UTC (rev 285084)
@@ -8,7 +8,7 @@
 PASS foreignSel.anchorNode is null
 PASS mainSel.anchorNode is null
 PASS foreignSel.anchorNode is null
-PASS mainSel.anchorNode is null
+PASS mainSel.anchorNode is not null
 PASS foreignSel.anchorNode is null
 PASS mainSel.anchorNode is null
 PASS foreignSel.anchorNode is null

Modified: trunk/LayoutTests/editing/selection/DOMSelection-crossing-document.html (285083 => 285084)


--- trunk/LayoutTests/editing/selection/DOMSelection-crossing-document.html	2021-10-30 19:57:56 UTC (rev 285083)
+++ trunk/LayoutTests/editing/selection/DOMSelection-crossing-document.html	2021-10-30 22:58:21 UTC (rev 285084)
@@ -46,9 +46,10 @@
 shouldBeNull("mainSel.anchorNode");
 
 clear();
+mainSel.addRange(new Range());
 mainSel.extend(foreignElement, 1);
 shouldBeNull("foreignSel.anchorNode");
-shouldBeNull("mainSel.anchorNode");
+shouldNotBe("mainSel.anchorNode", "null");
 
 clear();
 mainSel.selectAllChildren(foreignElement, 1);

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (285083 => 285084)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-30 19:57:56 UTC (rev 285083)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-30 22:58:21 UTC (rev 285084)
@@ -1,3 +1,19 @@
+2021-10-30  Brandon Stewart  <brandonstew...@apple.com>
+
+        Selection extend() should trigger exception with no ranges
+        https://bugs.webkit.org/show_bug.cgi?id=232420
+
+        Reviewed by Chris Dumez.
+
+        Verify extend() will throw an exception when the Selection object
+        contains no Range objects. Chrome and Firefox will also throw an
+        exception in this scenario.
+
+        https://w3c.github.io/selection-api/#dom-selection-extend
+
+        * web-platform-tests/selection/extend-exception-expected.txt: Added.
+        * web-platform-tests/selection/extend-exception.html: Added.
+
 2021-10-29  Antti Koivisto  <an...@apple.com>
 
         Allow :is/:where after all pseudo elements

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/selection/extend-exception-expected.txt (0 => 285084)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/selection/extend-exception-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/selection/extend-exception-expected.txt	2021-10-30 22:58:21 UTC (rev 285084)
@@ -0,0 +1,3 @@
+
+PASS InvalidStateError exception is thrown for extend() when no ranges are present in Selection
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/selection/extend-exception.html (0 => 285084)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/selection/extend-exception.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/selection/extend-exception.html	2021-10-30 22:58:21 UTC (rev 285084)
@@ -0,0 +1,21 @@
+<!doctype html>
+<html>
+<title>Selection extend() test thrown exceptions</title>
+<meta charset=utf-8>
+<body>
+<script src=""
+<script src=""
+<script>
+"use strict";
+
+test(function() {
+    let div = document.createElement("div");
+    document.body.appendChild(div);
+
+    assert_throws_dom("INVALID_STATE_ERR", function() { getSelection().extend(div) }, "InvalidStateError exception should be thrown for extend() due to no ranges being added to Selection");
+
+    this.add_cleanup(function() { div.remove() });
+}, "InvalidStateError exception is thrown for extend() when no ranges are present in Selection");
+</script>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (285083 => 285084)


--- trunk/Source/WebCore/ChangeLog	2021-10-30 19:57:56 UTC (rev 285083)
+++ trunk/Source/WebCore/ChangeLog	2021-10-30 22:58:21 UTC (rev 285084)
@@ -1,3 +1,20 @@
+2021-10-30  Brandon Stewart  <brandonstew...@apple.com>
+
+        Selection extend() should trigger exception with no ranges
+        https://bugs.webkit.org/show_bug.cgi?id=232420
+
+        Reviewed by Chris Dumez.
+
+        The 'extend' method in the Selection API should throw an exception upon
+        being called if there are no ranges present in the Selection object.
+
+        https://w3c.github.io/selection-api/#dom-selection-extend
+
+        Test: imported/w3c/web-platform-tests/selection/extend-exception.html
+
+        * page/DOMSelection.cpp:
+        (WebCore::DOMSelection::extend):
+
 2021-10-30  Alan Bujtas  <za...@apple.com>
 
         [LFC][IFC] Add bidi level to InlineDisplay::Box

Modified: trunk/Source/WebCore/page/DOMSelection.cpp (285083 => 285084)


--- trunk/Source/WebCore/page/DOMSelection.cpp	2021-10-30 19:57:56 UTC (rev 285083)
+++ trunk/Source/WebCore/page/DOMSelection.cpp	2021-10-30 22:58:21 UTC (rev 285084)
@@ -338,6 +338,10 @@
     auto frame = this->frame();
     if (!frame)
         return { };
+    
+    if (rangeCount() < 1)
+        return Exception { InvalidStateError, "extend() requires a Range to be added to the Selection" };
+
     if (frame->settings().liveRangeSelectionEnabled()) {
         if (!frame->document()->contains(node))
             return { };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to