Bug 197438 - REGRESSION(r244494): editing/pasteboard/5761530-1.html is flaky due to a simple line layout bug
Summary: REGRESSION(r244494): editing/pasteboard/5761530-1.html is flaky due to a simp...
Status: REOPENED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: zalan
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-04-30 13:42 PDT by Ryosuke Niwa
Modified: 2019-05-01 15:38 PDT (History)
6 users (show)

See Also:


Attachments
Reduction (219 bytes, text/html)
2019-05-01 14:16 PDT, Ryosuke Niwa
no flags Details
Patch (1.87 KB, patch)
2019-05-01 14:37 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2019-04-30 13:42:23 PDT
Truitt Savell 2019-04-30 09:56:55 PDT
It looks like the changes in https://trac.webkit.org/changeset/244494/webkit

has caused the test editing/pasteboard/5761530-1.html to become flakey. 

I was able to reproduce this using command:
run-webkit-tests editing/pasteboard/5761530-1.html --iterations 20 --ios-simulator
The test passes on 244493 and with fail on 244494

History:
https://webkit-test-results.webkit.org/dashboards/flakiness_dashboard.html#showAllRuns=true&tests=editing%2Fpasteboard%2F5761530-1.html

Diff:
--- /Volumes/Data/slave/ios-simulator-12-release-tests-wk2/build/layout-test-results/editing/pasteboard/5761530-1-expected.txt
+++ /Volumes/Data/slave/ios-simulator-12-release-tests-wk2/build/layout-test-results/editing/pasteboard/5761530-1-actual.txt
@@ -1,3 +1,3 @@
 This tests to see that tabs are put into tab spans when they are copied individually. The pasted tab should be inside of a tab span, not a style span. To run the test manually, paste and then inspect the editable region, and ensure that there is a tab span at the beginning of the editable div.
 
-<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space:pre;">	</span>xxx
+<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space:pre;"> </span>xxx
Comment 1 Radar WebKit Bug Importer 2019-04-30 13:43:20 PDT
<rdar://problem/50348091>
Comment 2 Wenson Hsieh 2019-04-30 20:07:59 PDT
It was specifically this change:

--- a/Source/WebKit/WebProcess/WebPage/WebPage.cpp
+++ b/Source/WebKit/WebProcess/WebPage/WebPage.cpp
@@ -1125,7 +1125,7 @@ void WebPage::updateEditorStateAfterLayoutIfEditabilityChanged()
     Frame& frame = m_page->focusController().focusedOrMainFrame();
     EditorStateIsContentEditable editorStateIsContentEditable = frame.selection().selection().isContentEditable() ? EditorStateIsContentEditable::Yes : EditorStateIsContentEditable::No;
     if (m_lastEditorStateWasContentEditable != editorStateIsContentEditable)
-        sendPartialEditorStateAndSchedulePostLayoutUpdate();
+        scheduleFullEditorStateUpdate();
 }

 String WebPage::renderTreeExternalRepresentation() const

...that causes this test to be flaky. Reverting to always send the partial editor state update immediately when changing editability fixes the flakiness for me. I'll need to see what exactly in the UI process is depending on this state being up to date.
Comment 3 Wenson Hsieh 2019-04-30 22:42:59 PDT
...this is even weirder than I thought!

Simply asking whether the current selection is at the beginning of a sentence via FrameSelection::selectionAtSentenceStart (and not even using the result) in this function:

     Frame& frame = m_page->focusController().focusedOrMainFrame();
     EditorStateIsContentEditable editorStateIsContentEditable = frame.selection().selection().isContentEditable() ? EditorStateIsContentEditable::Yes : EditorStateIsContentEditable::No;
-    if (m_lastEditorStateWasContentEditable != editorStateIsContentEditable)
+    if (m_lastEditorStateWasContentEditable != editorStateIsContentEditable) {
+        frame.selection().selectionAtSentenceStart();
         scheduleFullEditorStateUpdate();
+    }

...seems to make this test pass reliably 🤔.
Comment 4 Ryosuke Niwa 2019-05-01 00:49:08 PDT
Oh, I wonder this is an issue with simple line layout. Try disabling it via settings?
Comment 5 Wenson Hsieh 2019-05-01 07:32:39 PDT
(In reply to Ryosuke Niwa from comment #4)
> Oh, I wonder this is an issue with simple line layout. Try disabling it via
> settings?

Oh interesting! Adding `internals.settings.setSimpleLineLayoutEnabled(false);` to the beginning of the test does seem to fix the flakiness...
Comment 6 Ryosuke Niwa 2019-05-01 09:25:05 PDT
Okay. So I think this might be a bug in TextIterator / StylizedMarkupAccumulator with simple line layout code in which a tab character or 4 spaces is collapsed in its serialization even though white-space: pre is set.
Comment 7 Ryosuke Niwa 2019-05-01 13:53:44 PDT
It's probably a bug in TextIterator::handleTextNode. When copying the content of a plain text, we end up using TextIterator to grab the content in StyledMarkupAccumulator::appendText
Comment 8 Wenson Hsieh 2019-05-01 13:59:51 PDT
(In reply to Ryosuke Niwa from comment #7)
> It's probably a bug in TextIterator::handleTextNode. When copying the
> content of a plain text, we end up using TextIterator to grab the content in
> StyledMarkupAccumulator::appendText

Yep, I'm poking around in and around this code at the moment :)

I'll post some more findings in a bit. There's some behaviors regarding the lifetime of a renderer's SLL that are currently confusing me.
Comment 9 Ryosuke Niwa 2019-05-01 14:16:18 PDT
Created attachment 368708 [details]
Reduction

Here's a reduction of the issue Zalan and I worked.
Comment 10 Wenson Hsieh 2019-05-01 14:22:20 PDT
Alan, Ryosuke and I chatted about this over IRC. For now, let's disable SLL in this test to make it pass; Alan will continue investigating a fix in SLL logic to get innerText working for tab-spans in SLL.
Comment 11 Wenson Hsieh 2019-05-01 14:37:18 PDT
Created attachment 368714 [details]
Patch
Comment 12 WebKit Commit Bot 2019-05-01 15:34:09 PDT
Comment on attachment 368714 [details]
Patch

Clearing flags on attachment: 368714

Committed r244854: <https://trac.webkit.org/changeset/244854>
Comment 13 WebKit Commit Bot 2019-05-01 15:34:10 PDT
All reviewed patches have been landed.  Closing bug.
Comment 14 Wenson Hsieh 2019-05-01 15:38:04 PDT
Reopening to track the SLL issue described above.