Title: [262499] trunk
Revision
262499
Author
[email protected]
Date
2020-06-03 12:04:28 -0700 (Wed, 03 Jun 2020)

Log Message

Text manipulation sometimes fails to replace text in attributes
https://bugs.webkit.org/show_bug.cgi?id=212701

Reviewed by Wenson Hsieh.

Source/WebCore:

Concatenate replacement tokens of same identifier for attribute like we do for title and option element in
r260393.

Covered by test: TextManipulation.CompleteTextManipulationShouldReplaceTextContentWithMultipleTokens

* editing/TextManipulationController.cpp:
(WebCore::TextManipulationController::replace):

Tools:

Modify TextManipulation.CompleteTextManipulationShouldReplaceTextContentWithMultipleTokens to cover text
manipulation for attributes.

* TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (262498 => 262499)


--- trunk/Source/WebCore/ChangeLog	2020-06-03 18:48:00 UTC (rev 262498)
+++ trunk/Source/WebCore/ChangeLog	2020-06-03 19:04:28 UTC (rev 262499)
@@ -1,3 +1,18 @@
+2020-06-03  Sihui Liu  <[email protected]>
+
+        Text manipulation sometimes fails to replace text in attributes
+        https://bugs.webkit.org/show_bug.cgi?id=212701
+
+        Reviewed by Wenson Hsieh.
+
+        Concatenate replacement tokens of same identifier for attribute like we do for title and option element in 
+        r260393.
+
+        Covered by test: TextManipulation.CompleteTextManipulationShouldReplaceTextContentWithMultipleTokens
+
+        * editing/TextManipulationController.cpp:
+        (WebCore::TextManipulationController::replace):
+
 2020-06-02  Dean Jackson  <[email protected]>
 
         [ macOS ] REGRESSION(r262366): webgl/1.0.3/conformance/canvas/buffer-offscreen-test.html & webgl/2.0.0/conformance/canvas/buffer-offscreen-test.html are constant failures

Modified: trunk/Source/WebCore/editing/TextManipulationController.cpp (262498 => 262499)


--- trunk/Source/WebCore/editing/TextManipulationController.cpp	2020-06-03 18:48:00 UTC (rev 262498)
+++ trunk/Source/WebCore/editing/TextManipulationController.cpp	2020-06-03 19:04:28 UTC (rev 262499)
@@ -603,7 +603,7 @@
         auto element = makeRefPtr(item.element.get());
         if (!element)
             return ManipulationFailureType::ContentChanged;
-        if (replacementTokens.size() > 1 && !canPerformTextManipulationByReplacingEntireTextContent(*element))
+        if (replacementTokens.size() > 1 && !canPerformTextManipulationByReplacingEntireTextContent(*element) && item.attributeName == nullQName())
             return ManipulationFailureType::InvalidToken;
         auto expectedTokenIdentifier = item.tokens[0].identifier;
         StringBuilder newValue;

Modified: trunk/Tools/ChangeLog (262498 => 262499)


--- trunk/Tools/ChangeLog	2020-06-03 18:48:00 UTC (rev 262498)
+++ trunk/Tools/ChangeLog	2020-06-03 19:04:28 UTC (rev 262499)
@@ -1,3 +1,16 @@
+2020-06-03  Sihui Liu  <[email protected]>
+
+        Text manipulation sometimes fails to replace text in attributes
+        https://bugs.webkit.org/show_bug.cgi?id=212701
+
+        Reviewed by Wenson Hsieh.
+
+        Modify TextManipulation.CompleteTextManipulationShouldReplaceTextContentWithMultipleTokens to cover text 
+        manipulation for attributes.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
+        (TestWebKitAPI::TEST):
+
 2020-06-03  Diego Pino Garcia  <[email protected]>
 
         [WPE] lint-test-expectations doesn't work when platform is WPE

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm (262498 => 262499)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm	2020-06-03 18:48:00 UTC (rev 262498)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm	2020-06-03 19:04:28 UTC (rev 262499)
@@ -1421,6 +1421,8 @@
         "    <option selected>Hello world</option>"
         "    <option>Should not be replaced</option>"
         "</select>"
+        "<span aria-label='label'>Text</span>"
+        "<img src='' alt='image'>"
         "</html>"];
 
     done = false;
@@ -1430,18 +1432,27 @@
     TestWebKitAPI::Util::run(&done);
 
     auto *items = [delegate items];
-    EXPECT_EQ(items.count, 3UL);
+    EXPECT_EQ(items.count, 6UL);
     EXPECT_EQ(items[0].tokens.count, 1UL);
     EXPECT_EQ(items[1].tokens.count, 1UL);
     EXPECT_EQ(items[2].tokens.count, 1UL);
+    EXPECT_EQ(items[3].tokens.count, 1UL);
+    EXPECT_EQ(items[4].tokens.count, 1UL);
+    EXPECT_EQ(items[5].tokens.count, 2UL);
     EXPECT_WK_STREQ("This is a test", items[0].tokens[0].content);
     EXPECT_WK_STREQ("Hello world", items[1].tokens[0].content);
     EXPECT_WK_STREQ("Should not be replaced", items[2].tokens[0].content);
+    EXPECT_WK_STREQ("label", items[3].tokens[0].content);
+    EXPECT_WK_STREQ("image", items[4].tokens[0].content);
+    EXPECT_WK_STREQ("Text", items[5].tokens[0].content);
+    EXPECT_WK_STREQ("[]", items[5].tokens[1].content);
 
     auto replacementItems = retainPtr(@[
         createItem(items[0].identifier, { { items[0].tokens[0].identifier, @"Replacement" }, { items[0].tokens[0].identifier, @"title" } }).autorelease(),
         createItem(items[1].identifier, { { items[1].tokens[0].identifier, @"Replacement" }, { items[1].tokens[0].identifier, @"option" } }).autorelease(),
         createItem(items[2].identifier, { { items[2].tokens[0].identifier, @"Failed replacement" }, { @"12345", @"option" } }).autorelease(),
+        createItem(items[3].identifier, { { items[3].tokens[0].identifier, @"Replacement" }, { items[3].tokens[0].identifier, @"label" } }).autorelease(),
+        createItem(items[4].identifier, { { items[4].tokens[0].identifier, @"Replacement" }, { items[4].tokens[0].identifier, @"image" } }).autorelease(),
     ]);
 
     done = false;
@@ -1449,7 +1460,7 @@
         EXPECT_EQ(errors.count, 1UL);
         EXPECT_EQ(errors.firstObject.domain, _WKTextManipulationItemErrorDomain);
         EXPECT_EQ(errors.firstObject.code, _WKTextManipulationItemErrorInvalidToken);
-        EXPECT_EQ(errors.firstObject.userInfo[_WKTextManipulationItemErrorItemKey], [replacementItems lastObject]);
+        EXPECT_EQ(errors.firstObject.userInfo[_WKTextManipulationItemErrorItemKey], [replacementItems objectAtIndex:2]);
         done = true;
     }];
 
@@ -1459,6 +1470,8 @@
     EXPECT_WK_STREQ("Replacement option", options.firstObject);
     EXPECT_WK_STREQ("Should not be replaced", options.lastObject);
     EXPECT_WK_STREQ("Replacement title", [webView stringByEvaluatingJavaScript:@"document.title"]);
+    EXPECT_WK_STREQ("Replacement label", [webView objectByEvaluatingJavaScript:@"document.querySelector('span').getAttribute('aria-label')"]);
+    EXPECT_WK_STREQ("Replacement image", [webView objectByEvaluatingJavaScript:@"document.querySelector('img').getAttribute('alt')"]);
 }
 
 TEST(TextManipulation, CompleteTextManipulationShouldReplaceContentsAroundParagraphWithJustImage)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to