Changeset 285084 in webkit


Ignore:
Timestamp:
Oct 30, 2021 3:58:21 PM (9 months ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Brandon Stewart <Brandon> 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:
Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r285067 r285084  
     12021-10-30  Brandon Stewart  <brandonstewart@apple.com>
     2
     3        Selection extend() should trigger exception with no ranges
     4        https://bugs.webkit.org/show_bug.cgi?id=232420
     5
     6        Reviewed by Chris Dumez.
     7
     8        Resolve errors in test cases introduced by new exception being thrown by extend()
     9        when no ranges are present.
     10
     11        * editing/execCommand/null_calc_primitive_value_for_css_property.html:
     12        * editing/execCommand/transpose-backslash-with-euc.html:
     13        * editing/inserting/insert-html-crash-02.html:
     14        * editing/selection/DOMSelection-crossing-document-expected.txt:
     15        * editing/selection/DOMSelection-crossing-document.html:
     16
    1172021-10-29  Lauro Moura  <lmoura@igalia.com>
    218
  • trunk/LayoutTests/editing/execCommand/null_calc_primitive_value_for_css_property.html

    r271635 r285084  
    1111        testRunner.dumpAsText();
    1212
    13     document.getSelection().extend(x);
     13    document.getSelection().collapse(x, 0);
     14    document.getSelection().extend(x);
     15
    1416    document.execCommand("insertHTML", false, "The test passes if there is no crash.");
    1517}
  • trunk/LayoutTests/editing/execCommand/transpose-backslash-with-euc.html

    r120173 r285084  
    1212{
    1313    var backslashDivElement = document.getElementById("backslash");
     14    getSelection().collapse(backslashDivElement, 0);
    1415    getSelection().extend(backslashDivElement, 1);
    1516    document.execCommand("Transpose");
  • trunk/LayoutTests/editing/inserting/insert-html-crash-02.html

    r283868 r285084  
    1414    document.body.appendChild(iframe0);
    1515    document.body.appendChild(document.createElement('iframe'));
     16    getSelection().collapse(document.body, 0);
    1617    getSelection().extend(document.body);
    1718    iframe0.contentDocument.onvisibilitychange = () => {
  • trunk/LayoutTests/editing/selection/DOMSelection-crossing-document-expected.txt

    r56962 r285084  
    99PASS mainSel.anchorNode is null
    1010PASS foreignSel.anchorNode is null
    11 PASS mainSel.anchorNode is null
     11PASS mainSel.anchorNode is not null
    1212PASS foreignSel.anchorNode is null
    1313PASS mainSel.anchorNode is null
  • trunk/LayoutTests/editing/selection/DOMSelection-crossing-document.html

    r217390 r285084  
    4747
    4848clear();
     49mainSel.addRange(new Range());
    4950mainSel.extend(foreignElement, 1);
    5051shouldBeNull("foreignSel.anchorNode");
    51 shouldBeNull("mainSel.anchorNode");
     52shouldNotBe("mainSel.anchorNode", "null");
    5253
    5354clear();
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r285054 r285084  
     12021-10-30  Brandon Stewart  <brandonstewart@apple.com>
     2
     3        Selection extend() should trigger exception with no ranges
     4        https://bugs.webkit.org/show_bug.cgi?id=232420
     5
     6        Reviewed by Chris Dumez.
     7
     8        Verify extend() will throw an exception when the Selection object
     9        contains no Range objects. Chrome and Firefox will also throw an
     10        exception in this scenario.
     11
     12        https://w3c.github.io/selection-api/#dom-selection-extend
     13
     14        * web-platform-tests/selection/extend-exception-expected.txt: Added.
     15        * web-platform-tests/selection/extend-exception.html: Added.
     16
    1172021-10-29  Antti Koivisto  <antti@apple.com>
    218
  • trunk/Source/WebCore/ChangeLog

    r285083 r285084  
     12021-10-30  Brandon Stewart  <brandonstewart@apple.com>
     2
     3        Selection extend() should trigger exception with no ranges
     4        https://bugs.webkit.org/show_bug.cgi?id=232420
     5
     6        Reviewed by Chris Dumez.
     7
     8        The 'extend' method in the Selection API should throw an exception upon
     9        being called if there are no ranges present in the Selection object.
     10
     11        https://w3c.github.io/selection-api/#dom-selection-extend
     12
     13        Test: imported/w3c/web-platform-tests/selection/extend-exception.html
     14
     15        * page/DOMSelection.cpp:
     16        (WebCore::DOMSelection::extend):
     17
    1182021-10-30  Alan Bujtas  <zalan@apple.com>
    219
  • trunk/Source/WebCore/page/DOMSelection.cpp

    r278253 r285084  
    339339    if (!frame)
    340340        return { };
     341   
     342    if (rangeCount() < 1)
     343        return Exception { InvalidStateError, "extend() requires a Range to be added to the Selection" };
     344
    341345    if (frame->settings().liveRangeSelectionEnabled()) {
    342346        if (!frame->document()->contains(node))
Note: See TracChangeset for help on using the changeset viewer.