⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 259819 in webkit


Ignore:
Timestamp:
Apr 9, 2020, 1:16:38 PM (6 years ago)
Author:
Wenson Hsieh
Message:

Add an API test for <https://trac.webkit.org/r259766>
https://bugs.webkit.org/show_bug.cgi?id=210294

Reviewed by Tim Horton.

Source/WebCore:

Avoid trying to place the missing value into paragraphSets in TextManipulationController by bailing if either
the start or end positions are null (while the missing value requires both the start and end to be null, it is
sufficient to bail if either are null because observeParagraphs will be a no-op anyways).

See Tools/ChangeLog for more details.

Test: TextManipulation.CompleteTextManipulationAvoidCrashingWhenContentIsRemoved

  • editing/TextManipulationController.cpp:

(WebCore::TextManipulationController::scheduleObservartionUpdate):

Tools:

Exercise the pathological case fixed in r259766 by inserting and then immediately removing a paragraph element
after starting text manipulation. This test also revealed an existing issue in TextManipulationController, where
we will end up hitting a debug assertion when trying to insert { null position, null position } into a HashMap
underneath TextManipulationController::scheduleObservartionUpdate.

  • TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:

(TestWebKitAPI::TEST):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r259817 r259819  
     12020-04-09  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add an API test for <https://trac.webkit.org/r259766>
     4        https://bugs.webkit.org/show_bug.cgi?id=210294
     5
     6        Reviewed by Tim Horton.
     7
     8        Avoid trying to place the missing value into paragraphSets in TextManipulationController by bailing if either
     9        the start or end positions are null (while the missing value requires both the start and end to be null, it is
     10        sufficient to bail if either are null because `observeParagraphs` will be a no-op anyways).
     11
     12        See Tools/ChangeLog for more details.
     13
     14        Test: TextManipulation.CompleteTextManipulationAvoidCrashingWhenContentIsRemoved
     15
     16        * editing/TextManipulationController.cpp:
     17        (WebCore::TextManipulationController::scheduleObservartionUpdate):
     18
    1192020-04-09  Ryan Haddad  <ryanhaddad@apple.com>
    220
  • trunk/Source/WebCore/editing/TextManipulationController.cpp

    r259766 r259819  
    377377            auto end = endOfParagraph(lastPositionInOrAfterNode(element.ptr()));
    378378
     379            if (start.isNull() || end.isNull())
     380                continue;
     381
    379382            auto key = makeHashablePositionRange(start, end);
    380383            if (!paragraphSets.add(key).isNewEntry)
  • trunk/Tools/ChangeLog

    r259818 r259819  
     12020-04-09  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add an API test for <https://trac.webkit.org/r259766>
     4        https://bugs.webkit.org/show_bug.cgi?id=210294
     5
     6        Reviewed by Tim Horton.
     7
     8        Exercise the pathological case fixed in r259766 by inserting and then immediately removing a paragraph element
     9        after starting text manipulation. This test also revealed an existing issue in TextManipulationController, where
     10        we will end up hitting a debug assertion when trying to insert { null position, null position } into a HashMap
     11        underneath `TextManipulationController::scheduleObservartionUpdate`.
     12
     13        * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
     14        (TestWebKitAPI::TEST):
     15
    1162020-04-09  Simon Fraser  <simon.fraser@apple.com>
    217
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm

    r259647 r259819  
    844844}
    845845
     846TEST(TextManipulation, CompleteTextManipulationAvoidCrashingWhenContentIsRemoved)
     847{
     848    auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);
     849    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
     850    [webView _setTextManipulationDelegate:delegate.get()];
     851
     852    [webView synchronouslyLoadTestPageNamed:@"simple"];
     853
     854    done = false;
     855    [webView _startTextManipulationsWithConfiguration:nil completion:^{
     856        done = true;
     857    }];
     858    TestWebKitAPI::Util::run(&done);
     859
     860    auto *items = [delegate items];
     861    EXPECT_EQ(items.count, 1UL);
     862    auto *tokens = items[0].tokens;
     863    EXPECT_EQ(tokens.count, 1UL);
     864
     865    __block bool done = false;
     866    [webView performAfterReceivingMessage:@"DoneRemovingParagraph" action:^{
     867        done = true;
     868    }];
     869
     870    [webView stringByEvaluatingJavaScript:
     871        @"const paragraph = document.createElement('p');"
     872        "paragraph.textContent = 'Hello world';"
     873        "document.body.appendChild(paragraph);"
     874        "setTimeout(() => { paragraph.remove(); webkit.messageHandlers.testHandler.postMessage('DoneRemovingParagraph') })"];
     875
     876    done = false;
     877    [webView _completeTextManipulationForItems:@[(_WKTextManipulationItem *)createItem(items[0].identifier, {
     878        { tokens[0].identifier, @"Simple HTML file!" },
     879    })] completion:^(NSArray<NSError *> *errors) {
     880        EXPECT_EQ(errors, nil);
     881        done = true;
     882    }];
     883
     884    EXPECT_WK_STREQ("Simple HTML file!", [webView stringByEvaluatingJavaScript:@"document.body.textContent"]);
     885}
     886
    846887TEST(TextManipulation, CompleteTextManipulationShouldPreserveImagesAsExcludedTokens)
    847888{
Note: See TracChangeset for help on using the changeset viewer.