summaryrefslogtreecommitdiffstats
path: root/LayoutTests/http/tests/appcache/update-cache.html
blob: dd48b0199eead6134014f766804c269151f57257 (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
<html manifest="resources/versioned-manifest.php">
<body>
<p>Test a simple offline application self-update process. Should print a series of messages followed with DONE:</p>
<div id=result></div>

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

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

function modifyManifest()
{
    var req = new XMLHttpRequest;
    req.open("GET", "resources/versioned-manifest.php?command=step", false);
    req.send(false);
}

function test()
{
    modifyManifest();

    applicationCache.oncached = function() { log("FAIL: Unexpected cached event") }
    applicationCache.onnoupdate = function() { log("FAIL: Unexpected noupdate event") }
    applicationCache.onupdateready = function() { setTimeout(test2, 0) }

    log("Updating cache group...");
    setTimeout("applicationCache.update()", 0);
}

function test2()
{
    log((applicationCache.status == applicationCache.UPDATEREADY) ? "Cache status is UPDATEREADY" : ("FAIL: Incorrect cache status, " + applicationCache.status));

    modifyManifest();
    applicationCache.onupdateready = function() { setTimeout(test3, 0) }

    log("Updating cache group once more...");
    setTimeout("applicationCache.update()", 0);
}

function test3()
{
    log((applicationCache.status == applicationCache.UPDATEREADY) ? "Cache status is UPDATEREADY" : ("FAIL: Incorrect cache status, " + applicationCache.status));

    log("Associating document with the newest cache version...");
    applicationCache.swapCache();

    log((applicationCache.status == applicationCache.IDLE) ? "Cache status is IDLE" : ("FAIL: Incorrect cache status, " + applicationCache.status));

    log("DONE");
    if (window.layoutTestController)
        layoutTestController.notifyDone();
}

applicationCache.oncached = test;
applicationCache.onnoupdate = test;
applicationCache.onupdateready = function() { log("FAIL: Unexpected updateready event") }
applicationCache.onerror = function() { log("FAIL: Unexpected error event") }
applicationCache.onobsolete = function() { log("FAIL: Unexpected obsolete event") }

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