• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html manifest="resources/online-whitelist.manifest">
2<body>
3<p>Test online whitelist functionality. Should say PASS:</p>
4
5<div id="result"></div>
6<script>
7if (window.layoutTestController) {
8    layoutTestController.dumpAsText()
9    layoutTestController.waitUntilDone();
10}
11
12function log(message)
13{
14    document.getElementById("result").innerHTML += message + "<br>";
15}
16
17var hadError = false;
18
19function canLoad(url)
20{
21    try {
22        var req = new XMLHttpRequest();
23        req.open("GET", url, false);
24        req.send("");
25        return true;
26    } catch (e) {
27        return false;
28    }
29}
30
31function load(url)
32{
33    try {
34        var req = new XMLHttpRequest();
35        req.open("GET", url, false);
36        req.send("");
37        return req.responseText;
38    } catch (ex) {
39        alert("Unexpected error loading " + url + ": " + ex);
40        hadError = true;
41    }
42}
43
44function test()
45{
46    if (load("resources/counter.php?cached") != load("resources/counter.php?cached")) {
47        log("FAIL: Explicit entry didn't override online whitelist.");
48        hadError = true;
49    }
50
51    if (load("resources/counter.php?uncached") == load("resources/counter.php?uncached")) {
52        log("FAIL: Online whitelist resource wasn't reloaded from network.");
53        hadError = true;
54    }
55
56    if (load("resources/counter.php?uncachedxxx") == load("resources/counter.php?uncachedxxx")) {
57        log("FAIL: Online whitelist resource wasn't reloaded from network (prefix matching).");
58        hadError = true;
59    }
60
61    if (canLoad("resources/counter.php?foobar")) {
62        log("FAIL: Uncached resource was successfully loaded.");
63        hadError = true;
64    }
65
66    log(hadError ? "FAIL" : "PASS");
67
68    if (window.layoutTestController)
69        layoutTestController.notifyDone();
70}
71
72applicationCache.addEventListener('cached', test, false);
73applicationCache.addEventListener('noupdate', test, false);
74
75</script>
76</body>
77</html>
78