Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Empty file.
Empty file.
32 changes: 25 additions & 7 deletions test/fixtures/wpt/common/get-host-info.sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,60 @@ function get_host_info() {
var HTTP_PORT2 = '{{ports[http][1]}}';
var HTTPS_PORT = '{{ports[https][0]}}';
var HTTPS_PORT2 = '{{ports[https][1]}}';
var HTTPS_PUBLIC_PORT = '{{ports[https-public][0]}}';
var PROTOCOL = self.location.protocol;
var IS_HTTPS = (PROTOCOL == "https:");
var PORT = IS_HTTPS ? HTTPS_PORT : HTTP_PORT;
var PORT2 = IS_HTTPS ? HTTPS_PORT2 : HTTP_PORT2;
var HTTP_PORT_ELIDED = HTTP_PORT == "80" ? "" : (":" + HTTP_PORT);
var HTTP_PORT2_ELIDED = HTTP_PORT2 == "80" ? "" : (":" + HTTP_PORT2);
var HTTPS_PORT_ELIDED = HTTPS_PORT == "443" ? "" : (":" + HTTPS_PORT);
var HTTPS_PUBLIC_PORT_ELIDED = HTTPS_PUBLIC_PORT == '443' ? '' : (':' + HTTPS_PUBLIC_PORT);
var PORT_ELIDED = IS_HTTPS ? HTTPS_PORT_ELIDED : HTTP_PORT_ELIDED;
var ORIGINAL_HOST = '{{host}}';
var REMOTE_HOST = (ORIGINAL_HOST === 'localhost') ? '127.0.0.1' : ('www1.' + ORIGINAL_HOST);
var OTHER_HOST = '{{domains[www2]}}';
var NOTSAMESITE_HOST = (ORIGINAL_HOST === 'localhost') ? '127.0.0.1' : ('{{hosts[alt][]}}');
var OTHER_NOTSAMESITE_HOST = '{{hosts[alt][www2]}}';

return {
HTTP_PORT: HTTP_PORT,
HTTP_PORT2: HTTP_PORT2,
HTTPS_PORT: HTTPS_PORT,
HTTPS_PORT2: HTTPS_PORT2,
HTTPS_PUBLIC_PORT: HTTPS_PUBLIC_PORT,
HTTP_PORT_ELIDED: HTTP_PORT_ELIDED,
HTTPS_PORT_ELIDED: HTTPS_PORT_ELIDED,
HTTPS_PUBLIC_PORT_ELIDED: HTTPS_PUBLIC_PORT_ELIDED,
PORT: PORT,
PORT2: PORT2,
ORIGINAL_HOST: ORIGINAL_HOST,
REMOTE_HOST: REMOTE_HOST,
NOTSAMESITE_HOST,

ORIGIN: PROTOCOL + "//" + ORIGINAL_HOST + PORT_ELIDED,
ORIGIN: PROTOCOL + '//' + ORIGINAL_HOST + PORT_ELIDED,
HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + HTTP_PORT_ELIDED,
HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + HTTPS_PORT_ELIDED,
HTTPS_ORIGIN_WITH_CREDS: 'https://foo:bar@' + ORIGINAL_HOST + HTTPS_PORT_ELIDED,
HTTP_ORIGIN_WITH_DIFFERENT_PORT: 'http://' + ORIGINAL_HOST + HTTP_PORT2_ELIDED,
REMOTE_ORIGIN: PROTOCOL + "//" + REMOTE_HOST + PORT_ELIDED,
OTHER_ORIGIN: PROTOCOL + "//" + OTHER_HOST + PORT_ELIDED,
HTTPS_ORIGIN_WITH_CREDS:
'https://foo:bar@' + ORIGINAL_HOST + HTTPS_PORT_ELIDED,
HTTP_ORIGIN_WITH_DIFFERENT_PORT:
'http://' + ORIGINAL_HOST + HTTP_PORT2_ELIDED,
REMOTE_ORIGIN: PROTOCOL + '//' + REMOTE_HOST + PORT_ELIDED,
OTHER_ORIGIN: PROTOCOL + '//' + OTHER_HOST + PORT_ELIDED,
HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + HTTP_PORT_ELIDED,
HTTP_NOTSAMESITE_ORIGIN: 'http://' + NOTSAMESITE_HOST + HTTP_PORT_ELIDED,
HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT: 'http://' + REMOTE_HOST + HTTP_PORT2_ELIDED,
HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT:
'http://' + REMOTE_HOST + HTTP_PORT2_ELIDED,
HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + HTTPS_PORT_ELIDED,
HTTPS_REMOTE_ORIGIN_WITH_CREDS: 'https://foo:bar@' + REMOTE_HOST + HTTPS_PORT_ELIDED,
HTTPS_REMOTE_PUBLIC_ORIGIN:
'https://' + REMOTE_HOST + HTTPS_PUBLIC_PORT_ELIDED,
HTTPS_REMOTE_ORIGIN_WITH_CREDS:
'https://foo:bar@' + REMOTE_HOST + HTTPS_PORT_ELIDED,
HTTPS_NOTSAMESITE_ORIGIN: 'https://' + NOTSAMESITE_HOST + HTTPS_PORT_ELIDED,
HTTPS_NOTSAMESITE_PUBLIC_ORIGIN:
'https://' + NOTSAMESITE_HOST + HTTPS_PUBLIC_PORT_ELIDED,
HTTPS_OTHER_NOTSAMESITE_ORIGIN:
'https://' + OTHER_NOTSAMESITE_HOST + HTTPS_PORT_ELIDED,
UNAUTHENTICATED_ORIGIN: 'http://' + OTHER_HOST + HTTP_PORT_ELIDED,
AUTHENTICATED_ORIGIN: 'https://' + OTHER_HOST + HTTPS_PORT_ELIDED
};
Expand Down
139 changes: 139 additions & 0 deletions test/fixtures/wpt/common/reftest-wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function takeScreenshotDelayed(timeout) {
* Ensure that a precondition is met before waiting for a screenshot.
* @param {bool} condition - Fail the test if this evaluates to false
* @param {string} msg - Error message to write to the screenshot
* @returns {bool} True if the condition passed, false if it failed
*/
function failIfNot(condition, msg) {
const fail = () => {
Expand All @@ -35,5 +36,143 @@ function failIfNot(condition, msg) {
} else {
document.addEventListener("DOMContentLoaded", fail, false);
}
return false;
}
return true;
}

/**
* Display the failure reason and stop waiting for a screenshot.
*
* Does nothing for a mismatch-only reftest (no `match` reference is also
* present), since an error page necessarily differs from the reference and
* would spuriously pass instead of correctly timing out.
* @param {Error|ErrorEvent|PromiseRejectionEvent|*} error - The error that caused the failure.
*/
function failOnError(error) {
// Only <link>s explicitly in the XHTML namespace count as match/mismatch
// links, matching the manifest's own namespace-qualified lookup.
const links = document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "link");
let hasMatch = false;
let hasMismatch = false;
for (const link of links) {
const rel = link.getAttribute("rel");
if (rel === "match") {
hasMatch = true;
} else if (rel === "mismatch") {
hasMismatch = true;
}
}
if (hasMismatch && !hasMatch) {
return;
}

let message;
if (typeof PromiseRejectionEvent !== "undefined" && error instanceof PromiseRejectionEvent) {
if (error.reason && error.reason.message) {
message = "Unhandled rejection: " + error.reason.message;
} else {
message = "Unhandled rejection";
}
} else {
if (error.message) {
message = "Uncaught exception: " + error.message;
} else {
message = "Uncaught exception";
}
}

const node = document.createElementNS("http://www.w3.org/1999/xhtml", "div");
node.textContent = message;

if (document.body) {
document.body.insertBefore(node, document.body.firstChild);
} else {
const root = document.documentElement;
const is_html = (root &&
root.namespaceURI === "http://www.w3.org/1999/xhtml" &&
root.localName === "html");
const is_svg = ("SVGSVGElement" in self && root instanceof SVGSVGElement);
if (is_svg) {
const foreignObject = document.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
foreignObject.setAttribute("width", "100%");
foreignObject.setAttribute("height", "100%");
root.insertBefore(foreignObject, root.firstChild);
foreignObject.appendChild(node);
} else if (is_html) {
root.appendChild(document.createElementNS("http://www.w3.org/1999/xhtml", "body"))
.appendChild(node);
} else {
root.insertBefore(node, root.firstChild);
}
}

takeScreenshot();
}

/**
* Wrap `func` so a synchronous exception it throws is reported via
* failOnError() instead of propagating as an uncaught error. For use
* wrapping a callback, e.g. an event listener.
* @param {Function} func - Callback to wrap.
* @returns {Function} The wrapped callback.
*/
function reftestStep(func) {
return function(...args) {
try {
return func.apply(this, args);
} catch (e) {
failOnError(e);
}
};
}

/**
* Call `func` immediately, reporting via failOnError() either a
* synchronous exception it throws or an asynchronous rejection of the
* promise it returns.
* @param {Function} func - Function to call, typically async.
*/
function reftestPromise(func) {
const result = reftestStep(func)();
Promise.resolve(result).catch(failOnError);
}

/**
* Once a text track cue becomes active, pause the video, wait
* for layout to update, then call takeScreenshot().
*/
function waitForActiveCueAndTakeScreenshot() {
var videoElement = document.querySelector("video");
var trackElement = document.querySelector("track");

if (!failIfNot(videoElement, "Video element not found"))
return;

if (!failIfNot(trackElement, "Track element not found"))
return;

var textTrack = trackElement.track;

function pauseVideoAndTakeScreenshot() {
if (videoElement.paused)
requestAnimationFrame(() => takeScreenshot());
else {
videoElement.addEventListener("pause", function() {
requestAnimationFrame(() => takeScreenshot());
});
videoElement.pause();
}
}

textTrack.oncuechange = function() {
if (textTrack.activeCues && textTrack.activeCues.length) {
textTrack.oncuechange = null;
pauseVideoAndTakeScreenshot();
}
};

if (textTrack.activeCues && textTrack.activeCues.length)
pauseVideoAndTakeScreenshot();
}

Loading