diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/base/test/test_meta_refresh_referrer.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/test/test_meta_refresh_referrer.html')
-rw-r--r-- | dom/base/test/test_meta_refresh_referrer.html | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/dom/base/test/test_meta_refresh_referrer.html b/dom/base/test/test_meta_refresh_referrer.html new file mode 100644 index 0000000000..2af0a1f1f8 --- /dev/null +++ b/dom/base/test/test_meta_refresh_referrer.html @@ -0,0 +1,98 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <meta name='referrer' content='origin'> + <title>Test for referrer of meta refresh request</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + +<script type="application/javascript"> + +SimpleTest.waitForExplicitFinish(); +var advance = function() { tests.next(); }; + +/** + * Listen for notifications from the child. + */ +window.addEventListener("message", function(event) { + if (event.data == "childLoadComplete") { + advance(); + } +}); + +var tests = (function*() { + var iframe = document.getElementById("testframe"); + + // reset counter to make the test pass --repeat test + yield reset(); + + // load the test frame + yield iframe.src = + '/tests/dom/base/test/iframe_meta_refresh.sjs?action=test&load=refresh'; + + // check the test result + yield checkResults(referrerHeaderChecker); + + // complete. + SimpleTest.finish(); +})(); + +function referrerHeaderChecker(results) { + var expected = {'count': 2, 'referrers': ['origin', 'none']}; + is(results.count, expected.count, "Correct number of referrer header"); + is(results.referrers[0], expected.referrers[0], "Correct load referrer header"); + is(results.referrers[1], expected.referrers[1], "Correct refresh referrer header"); + + advance(); +} + +/** + * helper to perform an XHR. + */ +function doXHR(url, onSuccess, onFail) { + var xhr = new XMLHttpRequest(); + xhr.onload = function () { + if (xhr.status == 200) { + onSuccess(xhr); + } else { + onFail(xhr); + } + }; + xhr.open('GET', url, true); + xhr.send(null); +} + +/** + * Grabs the results via XHR and passes to checker. + */ +function checkResults(checker) { + doXHR('/tests/dom/base/test/iframe_meta_refresh.sjs?action=results', + function(xhr) { + checker(JSON.parse(xhr.responseText)); + }, + function(xhr) { + ok(false, "Can't get results from server."); + }); +} + +/** + * Reset the counter. + */ +function reset() { + doXHR('/tests/dom/base/test/iframe_meta_refresh.sjs?action=reset', + advance, + function(xhr) { + ok(false, "error in reset state"); + SimpleTest.finish(); + }); +} + +</script> +</head> + +<body onload="tests.next();"> + <iframe id="testframe"></iframe> + +</body> +</html></html> |