Browse Source

LibWeb: Pageshow event dispatched by the user agent should be trusted

The spec says that "isTrusted is a convenience that indicates whether
an event is dispatched by the user agent (as opposed to using
dispatchEvent())"

But when dispatching a pageshow event the flag was incorrectly set
to false.

This fixes https://wpt.fyi/results/html/syntax/parsing/the-end.html
Alan Kemp 8 tháng trước cách đây
mục cha
commit
d2fbbabd89

+ 1 - 0
Tests/LibWeb/Text/expected/HTML/pageshow-event-istrusted.txt

@@ -0,0 +1 @@
+PASS

+ 14 - 0
Tests/LibWeb/Text/input/HTML/pageshow-event-istrusted.html

@@ -0,0 +1,14 @@
+<script src="../include.js"></script>
+<iframe id="i"></iframe>
+<script>
+    asyncTest((done) => {
+        window.addEventListener("pageshow", (e) => {
+            if (e.isTrusted) {
+                println("PASS");
+            } else {
+                println("FAIL");
+            }
+            done();
+		});
+    });
+</script>

+ 3 - 0
Userland/Libraries/LibWeb/HTML/Window.cpp

@@ -423,6 +423,9 @@ void Window::fire_a_page_transition_event(FlyString const& event_name, bool pers
     // the bubbles attribute initialized to true,
     event->set_bubbles(true);
 
+    // isTrusted is a convenience that indicates whether an event is dispatched by the user agent (as opposed to using dispatchEvent())
+    event->set_is_trusted(true);
+
     // and legacy target override flag set.
     dispatch_event(event);
 }