1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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>
|