summaryrefslogtreecommitdiffstats
path: root/LayoutTests/http/tests/appcache/remove-cache.html
blob: 954418c281e46e962b2324f79f66dae66c2fdb3a (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<html manifest="resources/fail-on-update.php">
<p>Test that a 404 response for manifest results in cache removal.</p>
<body>
<ul>
<li>Frame 1: Manifest is still available, so a new master resource is added to the cache.
<li>Frame 2: Manifest loading results in 404 response, so the cache group becomes obsolete, and an obsolete event is dispatched (because the document in frame was associated with a cache in the group).
<li>Frame 3: Manifest is still 404 - the document is never associated with a cache.
<li>Frame 4: Manifest is now available, so the document gets associated with a cache in a newly created group; the obsolete cache group is not affected.
</ul>
<p>Should say SUCCESS:</p>
<div id=result></div>

<script>
if (window.layoutTestController) {
    layoutTestController.dumpAsText();
    layoutTestController.waitUntilDone();
}

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

function setManifestDeleted(state)
{
    var req = new XMLHttpRequest;
    req.open("GET", "resources/fail-on-update.php?command=" + (state ? "delete" : "reset"), false);
    req.send(null);
}

function test()
{
    clearTimeout(timeoutId);

    // The frame will be associated to a cache, and its main resource will be added to the cache.
    var ifr = document.createElement("iframe");
    ifr.setAttribute("src", "resources/remove-cache-frame.html");
    document.body.appendChild(ifr);
    applicationCache.onnoupdate = test2;
}

function test2()
{
    applicationCache.onnoupdate = function() { log("Unexpected noupdate event") }
    applicationCache.oncached = function() { log("Unexpected cached event") }

    setManifestDeleted(true);
    // The frame will be associated to a cache, but update will obsolete it.
    var ifr = document.createElement("iframe");
    ifr.setAttribute("src", "resources/remove-cache-frame.html");
    document.body.appendChild(ifr);
    applicationCache.onobsolete = test3;
}

function test3()
{
    applicationCache.onchecking = function() { log("Unexpected checking event after obsolete event") }
    applicationCache.onupdateready = function() { log("Unexpected updateready event after obsolete event") }
    applicationCache.onerror = function() { log("Unexpected error event after obsolete event") }
    applicationCache.onnoupdate = function() { log("Unexpected noupdate event after obsolete event") }
    applicationCache.oncached = function() { log("Unexpected cached event after obsolete event") }

    // The frame will not be associated to a cache.
    var ifr = document.createElement("iframe");
    ifr.setAttribute("src", "resources/remove-cache-frame.html");
    document.body.appendChild(ifr);
    window.addEventListener("message", test4, false);
}

function test4()
{
    setManifestDeleted(false);

    window.removeEventListener("message", test4, false);
    applicationCache.onupdateready = null;

    // The frame will be associated to a cache.
    var ifr = document.createElement("iframe");
    ifr.setAttribute("src", "resources/remove-cache-frame-2.html");
    document.body.appendChild(ifr);
    window.addEventListener("message", test5, false);
}

function test5()
{
    log("SUCCESS");
    if (window.layoutTestController)
        layoutTestController.notifyDone();
}

function resetManifest()
{
    if (applicationCache.status != applicationCache.UNCACHED && applicationCache.status != applicationCache.OBSOLETE) {
        timeoutId = setTimeout(resetManifest, 100);
        return;
    }

    setManifestDeleted(false);
    location.reload();
}

applicationCache.onupdateready = function() { log("Unexpected updateready event") }
applicationCache.onnoupdate = test;
applicationCache.oncached = test;

// If the manifest script happened to be in a wrong state, reset it.
var timeoutId = setTimeout(resetManifest, 100);

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