editing/pasteboard/paste-and-sanitize.html is a flaky failure
https://bugs.webkit.org/show_bug.cgi?id=203199
<rdar://problem/53551736>

Reviewed by Tim Horton.

Try to make this test more robust in WebKit2 on iOS 13 by ensuring at least one round trip between the web
content process and the UI process after copying and pasting. The root cause of the flakiness is still unknown,
but evidence suggests that code in Pasteboard.framework needs at least one runloop to sever the connection
between the application process and `pasted` after writing content to the pasteboard; otherwise, this
post-writing cleanup step will race against the next time we attempt to trigger a paste.

* editing/pasteboard/paste-and-sanitize.html:
* platform/ios-12/TestExpectations:
* platform/ios/TestExpectations:

Remove the failing test expectations.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251465 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 2a56cac..61f5e09 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,23 @@
+2019-10-22  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        editing/pasteboard/paste-and-sanitize.html is a flaky failure
+        https://bugs.webkit.org/show_bug.cgi?id=203199
+        <rdar://problem/53551736>
+
+        Reviewed by Tim Horton.
+
+        Try to make this test more robust in WebKit2 on iOS 13 by ensuring at least one round trip between the web
+        content process and the UI process after copying and pasting. The root cause of the flakiness is still unknown,
+        but evidence suggests that code in Pasteboard.framework needs at least one runloop to sever the connection
+        between the application process and `pasted` after writing content to the pasteboard; otherwise, this
+        post-writing cleanup step will race against the next time we attempt to trigger a paste.
+
+        * editing/pasteboard/paste-and-sanitize.html:
+        * platform/ios-12/TestExpectations:
+        * platform/ios/TestExpectations:
+
+        Remove the failing test expectations.
+
 2019-10-22  Charlie Turner  <cturner@igalia.com>
 
         [GStreamer] Skip http/tests/media/hls/hls-video-resize.html
diff --git a/LayoutTests/editing/pasteboard/paste-and-sanitize.html b/LayoutTests/editing/pasteboard/paste-and-sanitize.html
index 363cdde..09d0eb8 100644
--- a/LayoutTests/editing/pasteboard/paste-and-sanitize.html
+++ b/LayoutTests/editing/pasteboard/paste-and-sanitize.html
@@ -2,6 +2,7 @@
 <html>
 <head>
 <script src="../../resources/js-test-pre.js"></script>
+<script src="../../resources/ui-helper.js"></script>
 </head>
 <body>
 <p id="description">This test checks that the paste operation trims the pasted fragment to reduce the verbosity of the markup without affecting the style. </p>
@@ -20,36 +21,46 @@
     return node;
 }
 
-function testPaste(tagName, originalMarkup, expected) {
+async function testPaste(tagName, originalMarkup, expected) {
     var node = createEditable(tagName, originalMarkup);
     root.appendChild(node);
 
     node.focus();
     document.execCommand("SelectAll", false);
     document.execCommand("Copy", false);
+    await UIHelper.ensurePresentationUpdate();
+
     document.execCommand("Paste", false);
+    await UIHelper.ensurePresentationUpdate();
 
     confirmedMarkup = node.innerHTML;
 
     shouldBe("confirmedMarkup", "'" + expected + "'");
 }
 
-testPaste("div", "Hello", "Hello");
-testPaste("div", "<b><i>Hello</i></b>", "<b><i>Hello</i></b>");
-testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>Hello</i></b></span></i></b></div>", "<b><i>Hello</i></b>");
-testPaste("div", "<div><div><div>Hello</div></div></div>", "Hello");
-testPaste("div", "<div><b><div><i>Hello</i></div></b></div>", "<i style=\"font-weight: bold;\">Hello</i>");
-testPaste("div", "<div><div style=\"text-align: center;\"><b>Hello</b></div></div>", "<div style=\"text-align: center;\"><b>Hello</b></div>");
-testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>hello</i></b></span></i></b></div><div><b><i><span style=\"font-weight: normal\"><b><i>world</i></b></span></i></b></div>", 
-          "<div><b><i>hello</i></b></div><div><b><i>world</i></b></div>");
-testPaste("div", "<div><b><i><span style=\"font-weight: normal;\"><b><i>hello1</i></b><b><i> hello2</i></b></span></i></b></div>", "<b><i><span style=\"font-weight: normal;\"><b><i>hello1</i></b><b><i>&nbsp;hello2</i></b></span></i></b>");
-testPaste("div", "<i style=\"margin: 10px;\"><b><i style=\"margin: 10px;\">hello</i></b></i>",
-          "<i style=\"margin: 10px;\">hello</i></b></i>");
-testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>Hello <!-- comment -->world</i></b></span></i></b></div>", "<b><i>Hello&nbsp;world</i></b>");
-testPaste("div", "<div><b><i><span style=\"font-weight: normal\">plain text<b><i>bold italic text</i></b></span></i></b></div>", "<b><i><span style=\"font-weight: normal;\">plain text<b><i>bold italic text</i></b></span></i></b>");
+jsTestIsAsync = true;
 
-root.style.display = "none";
+async function runTest() {
+    await testPaste("div", "Hello", "Hello");
+    await testPaste("div", "<b><i>Hello</i></b>", "<b><i>Hello</i></b>");
+    await testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>Hello</i></b></span></i></b></div>", "<b><i>Hello</i></b>");
+    await testPaste("div", "<div><div><div>Hello</div></div></div>", "Hello");
+    await testPaste("div", "<div><b><div><i>Hello</i></div></b></div>", "<i style=\"font-weight: bold;\">Hello</i>");
+    await testPaste("div", "<div><div style=\"text-align: center;\"><b>Hello</b></div></div>", "<div style=\"text-align: center;\"><b>Hello</b></div>");
+    await testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>hello</i></b></span></i></b></div><div><b><i><span style=\"font-weight: normal\"><b><i>world</i></b></span></i></b></div>",
+              "<div><b><i>hello</i></b></div><div><b><i>world</i></b></div>");
+    await testPaste("div", "<div><b><i><span style=\"font-weight: normal;\"><b><i>hello1</i></b><b><i> hello2</i></b></span></i></b></div>", "<b><i><span style=\"font-weight: normal;\"><b><i>hello1</i></b><b><i>&nbsp;hello2</i></b></span></i></b>");
+    await testPaste("div", "<i style=\"margin: 10px;\"><b><i style=\"margin: 10px;\">hello</i></b></i>",
+              "<i style=\"margin: 10px;\">hello</i></b></i>");
+    await testPaste("div", "<div><b><i><span style=\"font-weight: normal\"><b><i>Hello <!-- comment -->world</i></b></span></i></b></div>", "<b><i>Hello&nbsp;world</i></b>");
+    await testPaste("div", "<div><b><i><span style=\"font-weight: normal\">plain text<b><i>bold italic text</i></b></span></i></b></div>", "<b><i><span style=\"font-weight: normal;\">plain text<b><i>bold italic text</i></b></span></i></b>");
 
+    root.style.display = "none";
+
+    finishJSTest();
+}
+
+addEventListener("load", runTest);
 </script>
 <script src="../../resources/js-test-post.js"></script>
 </body>
diff --git a/LayoutTests/platform/ios-12/TestExpectations b/LayoutTests/platform/ios-12/TestExpectations
index c9be827..0e88229 100644
--- a/LayoutTests/platform/ios-12/TestExpectations
+++ b/LayoutTests/platform/ios-12/TestExpectations
@@ -10,8 +10,5 @@
 fast/forms/auto-fill-button/caps-lock-indicator-should-not-be-visible-when-auto-fill-strong-password-button-is-visible.html [ Skip ]
 fast/forms/password-scrolled-after-caps-lock-toggled.html [ Skip ]
 
-# rdar://53551736 (Layout Test editing/pasteboard/paste-and-sanitize.html is a Flaky Failure on iOS 13)
-editing/pasteboard/paste-and-sanitize.html [ Pass ]
-
 # rdar://54561673 (REGRESSION: Layout test http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2.html is a flaky timeout)
 http/tests/security/frameNavigation/sandbox-ALLOWED-top-navigation-with-user-gesture-2.html [ Pass ]
diff --git a/LayoutTests/platform/ios/TestExpectations b/LayoutTests/platform/ios/TestExpectations
index cbc7de3..c848bd4 100644
--- a/LayoutTests/platform/ios/TestExpectations
+++ b/LayoutTests/platform/ios/TestExpectations
@@ -3335,9 +3335,6 @@
 # <rdar://problem/52689856> storage/websql/test-authorizer.html is failing
 storage/websql/test-authorizer.html [ Failure ]
 
-# rdar://53551736 (Layout Test editing/pasteboard/paste-and-sanitize.html is a Flaky Failure on iOS 13)
-editing/pasteboard/paste-and-sanitize.html [ Pass Failure ]
-
 # Skip until we have the fixes for <rdar://problem/53613454> and <rdar://problem/54001139>.
 fast/events/ios/multiple-key-press-and-release-ordering.html [ Skip ]