Преглед на файлове

LibWeb: Fix endless spinning in apply_the_history_step()

While waiting for a task that populates a session history entry, we
can't limit the processing of the event loop to the
`NavigationAndTraversal` task source. This is because fetching uses the
`Networking` task source, which also needs to be processed.

Since making a fetch request might take some time, we want to process
everything on the event loop while waiting, to avoid blocking user
interactions.

It is still possible to use `spin_processing_tasks_with_source_until()`
on subsequent steps of `apply_the_history_step()`.

Also modifies test that was flaky.
Aliaksandr Kalenik преди 1 година
родител
ревизия
609a72f7c7

+ 1 - 1
Tests/LibWeb/Text/expected/navigation/remove-iframe-from-timeout-callback.txt

@@ -1 +1 @@
-  
+PASS: did not crash 

+ 15 - 11
Tests/LibWeb/Text/input/navigation/remove-iframe-from-timeout-callback.html

@@ -1,12 +1,16 @@
-<script src="../include.js"></script>
-<div id="foo">
-    <iframe></iframe>
-    <script>
-        setTimeout(function () {
-            foo.remove();
-            // Pass (didn't crash)
-            internals.signalTextTestIsDone();
+<script src="../include.js"></script><div id="foo"><iframe></iframe><script>
+    setTimeout(function () {
+        foo.remove();
+        window.done = true;
+    }, 0);
+</script></div><iframe></iframe><script>
+    asyncTest(function (done) {
+        let internalId;
+        internalId = setInterval(function () {
+            if (window.done) {
+                clearInterval(internalId);
+                done();
+            }
         }, 0);
-    </script>
-</div>
-<iframe></iframe>
+    });
+</script>PASS: did not crash

+ 1 - 1
Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp

@@ -572,7 +572,7 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_
         // AD-HOC: Since currently populate_session_history_entry_document does not run in parallel
         //         we call spin_until to interrupt execution of this function and let document population
         //         to complete.
-        main_thread_event_loop().spin_processing_tasks_with_source_until(Task::Source::NavigationAndTraversal, [&] {
+        main_thread_event_loop().spin_until([&] {
             return !changing_navigable_continuations.is_empty() || completed_change_jobs == total_change_jobs;
         });