summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-exact-match.html
blob: 4b89cee0c08094d84c00bb67e24deb13521b8145 (plain)
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
<p>Tests the behavior of whitelisting origins using exact matching.</p>

<pre id="console"></pre>
<script>
testRunner.dumpAsText();
testRunner.waitUntilDone();
testRunner.addOriginAccessWhitelistEntry("http://127.0.0.1:8000", "http", "localhost", false);

function log(message)
{
    document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
}

function test(url, expectSuccess)
{
    log("Testing: " + url + " (sync)");
    var req = new XMLHttpRequest();
    req.open("GET", url, false);
    try {
        req.send(null);
        log((expectSuccess ? "PASS: " : "FAIL: ") + req.responseText);
    } catch (e) {
        log((expectSuccess ? "FAIL: " : "PASS: ") + e);
    }

    log("Testing: " + url + " (async)");
    req = new XMLHttpRequest();
    req.open("GET", url, true);
    req.onload = function() {
        log((expectSuccess ? "PASS: " : "FAIL: ") + req.responseText);
        nextTest();
    };
    req.onerror = function() {
        log((expectSuccess ? "FAIL: " : "PASS: ") + req.status);
        nextTest();
    };
    req.send(null);
}

var tests = [
    ["http://localhost:8000/xmlhttprequest/resources/get.txt", true],
    ["http://loCALhost:8000/xmlhttprequest/resources/get.txt", true]
    // FIXME: Is it possible to setup the following tests?
    // ["http://localhost:8001/xmlhttprequest/resources/get.txt", false],
    // ["http://foo.localhost:8000/xmlhttprequest/resources/get.txt", false],
    // ["https://localhost:8000/xmlhttprequest/resources/get.txt", false]
];

var currentTest = 0;

function nextTest()
{
    if (currentTest < tests.length)
        test.apply(null, tests[currentTest++]);
    else
        testRunner.notifyDone();
}

nextTest();
</script>