瀏覽代碼

Tests: Fix 404 at css selector test

Fixes css/selectors/focus-visible-009.html
Pavel Shliak 7 月之前
父節點
當前提交
1d2ceaf33f

+ 1 - 1
Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-visible-009.html

@@ -7,7 +7,7 @@
   <link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />
   <script src="../../resources/testharness.js"></script>
   <script src="../../resources/testharnessreport.js"></script>
-  <script src="/html/interaction/focus/the-autofocus-attribute/resources/utils.js"></script>
+  <script src="../../html/interaction/focus/the-autofocus-attribute/resources/utils.js"></script>
   <style>
     @supports not selector(:focus-visible) {
       #button:focus {

+ 51 - 0
Tests/LibWeb/Text/input/wpt-import/html/interaction/focus/the-autofocus-attribute/resources/utils.js

@@ -0,0 +1,51 @@
+'use strict';
+
+function waitForEvent(target, type, options) {
+  return new Promise((resolve, reject) => {
+    target.addEventListener(type, resolve, options);
+  });
+}
+
+function waitForAnimationFrame(w) {
+  let targetWindow = w || window;
+  return new Promise((resolve, reject) => {
+    targetWindow.requestAnimationFrame(resolve);
+  });
+}
+
+function waitForEvent(target, type, options) {
+  return new Promise((resolve, reject) => {
+    target.addEventListener(type, resolve, options);
+  });
+}
+
+function waitForLoad(target) {
+  return waitForEvent(target, 'load');
+}
+
+function timeOut(test, ms) {
+  return new Promise((resolve, reject) => {
+    test.step_timeout(resolve, ms);
+  });
+}
+
+// If an element with autofocus is connected to a document and this function
+// is called, the autofocus result is deterministic after returning from the
+// function.
+// Exception: If the document has script-blocking style sheets, this function
+// doesn't work well.
+async function waitUntilStableAutofocusState(w) {
+  let targetWindow = w || window;
+  // Awaiting one animation frame is an easy way to determine autofocus state.
+  await waitForAnimationFrame(targetWindow);
+}
+
+async function waitForIframeLoad(src, w = window) {
+  const iframe = w.document.createElement("iframe");
+  let loadPromise = new Promise(resolve => {
+    iframe.addEventListener("load", () => resolve(iframe));
+  });
+  iframe.src = src;
+  w.document.body.appendChild(iframe);
+  return loadPromise;
+}