summaryrefslogtreecommitdiffstats
path: root/LayoutTests/http/tests/appcache/xhr-foreign-resource.html
blob: df08d3fe814cc1cac95275aaefeb7b27596569b8 (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
<html manifest="resources/xhr-foreign-resource.manifest">
<body>
<p>Test that a resource marked as foreign can still be loaded via XHR.</p>
<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 createFrame1()
{
    applicationCache.onnoupdate = function() { log("FAIL: Unexpected noupdate event") }
    applicationCache.oncached = function() { log("FAIL: Unexpected cached event") }
    
    var ifr = document.createElement("iframe");
    ifr.setAttribute("src", "resources/xhr-foreign-resource-frame.html");
    document.body.appendChild(ifr);
}

function createFrame2()
{
    // A copy that doesn't have its main resource in cache manifest.
    var ifr = document.createElement("iframe");
    ifr.setAttribute("src", "resources/xhr-foreign-resource-frame.html?");
    document.body.appendChild(ifr);
}

applicationCache.onnoupdate = function() { createFrame1() }
applicationCache.oncached = function() { createFrame1() }

applicationCache.onupdateready = function() { log("FAIL: received unexpected updateready event") }
applicationCache.onerror = function() { log("FAIL: received unexpected error event") }

var hadErrorFromSubframe = false;
var subframeMessagesReceived = 0;
function frameMessageReceived(evt)
{
    ++subframeMessagesReceived;
    if (evt.data != "SUCCESS")
        hadErrorFromSubframe = true;
    if (subframeMessagesReceived == 1)
        setTimeout(createFrame2, 0);
    else if (subframeMessagesReceived == 2)
        test();
}

function test(evt)
{
    if (!hadErrorFromSubframe) {
        // The subframe has a different cache, but it is also listed as a resource in main frame's
        // manifest, so it should be loaded successfully despite being marked as foreign now.
        try {
            var req = new XMLHttpRequest;
            req.open("GET", "resources/xhr-foreign-resource-frame.html", false);
            req.send("");
            log("SUCCESS");
        } catch (ex) {
            log (ex);
        }
    } else 
        log("FAIL: subframe didn't get a correct cache");

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

window.addEventListener("message", frameMessageReceived, false);

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