summaryrefslogtreecommitdiffstats
path: root/LayoutTests/http/tests/appcache/online-whitelist.html
blob: f33fb6d4686749420a06372a2f0b58b6a6e9a10a (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<html manifest="resources/online-whitelist.manifest">
<body>
<p>Test online whitelist functionality. Should say PASS:</p>

<div id="result"></div>
<script>
if (window.layoutTestController) {
    layoutTestController.dumpAsText()
    layoutTestController.waitUntilDone();
}

function log(message)
{
    document.getElementById("result").innerHTML += message + "<br>";
}

var hadError = false;

function canLoad(url)
{
    try {
        var req = new XMLHttpRequest();
        req.open("GET", url, false);
        req.send("");
        return true;
    } catch (e) {
        return false;
    }
}

function load(url)
{
    try {
        var req = new XMLHttpRequest();
        req.open("GET", url, false);
        req.send("");
        return req.responseText;
    } catch (ex) {
        alert("Unexpected error loading " + url + ": " + ex);
        hadError = true;
    }
}

function test()
{
    if (load("resources/counter.php?cached") != load("resources/counter.php?cached")) {
        log("FAIL: Explicit entry didn't override online whitelist.");
        hadError = true;
    }

    if (load("resources/counter.php?uncached") == load("resources/counter.php?uncached")) {
        log("FAIL: Online whitelist resource wasn't reloaded from network.");
        hadError = true;
    }

    if (load("resources/counter.php?uncachedxxx") == load("resources/counter.php?uncachedxxx")) {
        log("FAIL: Online whitelist resource wasn't reloaded from network (prefix matching).");
        hadError = true;
    }

    if (canLoad("resources/counter.php?foobar")) {
        log("FAIL: Uncached resource was successfully loaded.");
        hadError = true;
    }

    log(hadError ? "FAIL" : "PASS");

    if (window.layoutTestController)
        layoutTestController.notifyDone();
}

applicationCache.addEventListener('cached', test, false);
applicationCache.addEventListener('noupdate', test, false);

</script>
</body>
</html>