Title: [227859] trunk/Tools
Revision
227859
Author
[email protected]
Date
2018-01-30 15:05:57 -0800 (Tue, 30 Jan 2018)

Log Message

[iOS] API test UIPasteboardTests.DataTransferGetDataWhenPastingPlatformRepresentations fails after r223440
https://bugs.webkit.org/show_bug.cgi?id=182307
<rdar://problem/36041485>

Reviewed by Ryosuke Niwa.

Adjusts a failing API test that we forgot to rebaseline after r223440, which ensures that the result of reading
"text/html" from the DataTransfer is sanitized markup. To do this, teach the test harness
(dump-datatransfer-types.html) to ignore inline styles in markup if a flag is set, and then set that flag in
UIPasteboardTests.DataTransferGetDataWhenPastingPlatformRepresentations.

* TestWebKitAPI/Tests/WebKitCocoa/dump-datatransfer-types.html:
* TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (227858 => 227859)


--- trunk/Tools/ChangeLog	2018-01-30 22:47:05 UTC (rev 227858)
+++ trunk/Tools/ChangeLog	2018-01-30 23:05:57 UTC (rev 227859)
@@ -1,3 +1,20 @@
+2018-01-30  Wenson Hsieh  <[email protected]>
+
+        [iOS] API test UIPasteboardTests.DataTransferGetDataWhenPastingPlatformRepresentations fails after r223440
+        https://bugs.webkit.org/show_bug.cgi?id=182307
+        <rdar://problem/36041485>
+
+        Reviewed by Ryosuke Niwa.
+
+        Adjusts a failing API test that we forgot to rebaseline after r223440, which ensures that the result of reading
+        "text/html" from the DataTransfer is sanitized markup. To do this, teach the test harness
+        (dump-datatransfer-types.html) to ignore inline styles in markup if a flag is set, and then set that flag in
+        UIPasteboardTests.DataTransferGetDataWhenPastingPlatformRepresentations.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/dump-datatransfer-types.html:
+        * TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:
+        (TestWebKitAPI::TEST):
+
 2018-01-30  Sergio Villar Senin  <[email protected]>
 
         [WebVR][GTK][WPE] Exclude OpenVR from tarballs

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/dump-datatransfer-types.html (227858 => 227859)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/dump-datatransfer-types.html	2018-01-30 22:47:05 UTC (rev 227858)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/dump-datatransfer-types.html	2018-01-30 23:05:57 UTC (rev 227859)
@@ -55,6 +55,9 @@
 // Setting this flag to `true` allows the page to write custom MIME types via the DataTransfer when dragging or copying.
 writeCustomData = false;
 
+// Setting this flag to `true` strips out inline styles in markup generated when getting "text/html" from a DataTransfer.
+ignoreInlineStyles = false;
+
 // Entries in this dictionary will be supplied as custom data using DataTransfer.setData when dragging or copying.
 // This is prepopulated with sample data by default, but tests may override this as needed.
 customData = {
@@ -66,11 +69,24 @@
     "baz/uri-list" : "https://www.webkit.org"
 };
 
+function stripInlineStylesFromPasteboardData(data)
+{
+    const parsedDocument = new DOMParser().parseFromString(data, "text/html");
+    const treeWalker = parsedDocument.createTreeWalker(parsedDocument.body, NodeFilter.SHOW_ELEMENT);
+    while (treeWalker.nextNode())
+        treeWalker.currentNode.removeAttribute("style");
+    return parsedDocument.body.innerHTML;
+}
+
 function updateResultWithEvent(event) {
     let pasteboard = event.dataTransfer || event.clipboardData;
     const eventData = {};
-    for (const type of pasteboard.types)
-        eventData[type] = pasteboard.getData(type);
+    for (const type of pasteboard.types) {
+        let pasteboardData = pasteboard.getData(type);
+        if (ignoreInlineStyles && type === "text/html")
+            pasteboardData = stripInlineStylesFromPasteboardData(pasteboardData);
+        eventData[type] = pasteboardData;
+    }
     result[event.type] = eventData;
     if (event.type === "paste" || event.type === "drop") {
         output.value = JSON.stringify(result, null, "    ");

Modified: trunk/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm (227858 => 227859)


--- trunk/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm	2018-01-30 22:47:05 UTC (rev 227858)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm	2018-01-30 23:05:57 UTC (rev 227859)
@@ -167,11 +167,12 @@
 TEST(UIPasteboardTests, DataTransferGetDataWhenPastingPlatformRepresentations)
 {
     auto webView = setUpWebViewForPasteboardTests(@"dump-datatransfer-types");
+    [webView stringByEvaluatingJavaScript:@"ignoreInlineStyles = true"];
 
     // This simulates how a native app on iOS might write to the pasteboard when copying.
     RetainPtr<NSURL> testURL = [NSURL URLWithString:@"https://www.apple.com/"];
     RetainPtr<NSString> testPlainTextString = @"WebKit";
-    RetainPtr<NSString> testMarkupString = @"<a href=''>The WebKit Project</a>";
+    RetainPtr<NSString> testMarkupString = @"<a href="" WebKit Project</a>";
     auto itemProvider = adoptNS([[NSItemProvider alloc] init]);
     [itemProvider registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypeHTML visibility:NSItemProviderRepresentationVisibilityAll loadHandler:^NSProgress *(DataLoadCompletionBlock completionHandler)
     {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to