summaryrefslogtreecommitdiffstats
path: root/LayoutTests/http/tests/appcache/fail-on-update-2.html
blob: fcbc3dde33f30291e9ddb68803c276f21e6c2948 (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
<html manifest="resources/fail-on-update-2.php">
<script>
if (window.layoutTestController) {
    layoutTestController.dumpAsText();
    layoutTestController.waitUntilDone();
}

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);

    setManifestDeleted(true);
    applicationCache.update();
    
    // Create two subframes at different times to make hitting the race condition more likely.
    var ifr = document.createElement("iframe");
    ifr.setAttribute("src", 'resources/fail-on-update-2.html');
    document.body.appendChild(ifr);

    setTimeout(function() {
        var ifr = document.createElement("iframe");
        ifr.setAttribute("src", 'resources/fail-on-update-2.html');
        document.body.appendChild(ifr);
    }, 0);
}

var subframesLeft = 2;
function subframeLoaded()
{
    if (!--subframesLeft) {
        document.write('<p>SUCCESS: No crash.</p>');
        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.addEventListener('noupdate', function() { setTimeout(test, 0) }, false);
applicationCache.addEventListener('cached', function() { setTimeout(test, 0) }, false);

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

</script>
<p>Test for a particular incorrect assertion failure.</p>

</html>