summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/inspector/network-status-non-http.html
blob: a788f4c62d3c0c96b865b04516015fb90bbaa282 (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
<html>
<head>
<script src="../http/tests/inspector/inspector-test.js"></script>
<script>
function test() {
    var requestsToWatch = /\/network-test\.js$|\/non-existent-file.js$|^data:application\/javascript,|/;
    var seenRequests = 0;

    function dumpRequests()
    {
        var logView = WebInspector.panels.network._networkLogView;
        logView.refresh();
        var dataGrid = logView.element.querySelector("table.data");
        var urls = document.evaluate("//tbody/tr/td[position()=1]/div/@title", dataGrid, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
        var outputStrings = [];

        for (var i = 0; i < urls.snapshotLength; ++i) {
            var url = urls.snapshotItem(i).value;
            if (requestsToWatch.test(url)) {
                var urlFragment = /^data:/.test(url) ? url.replace(/,.*$/, "") : url.replace(/.*\//, "");
                var status = document.evaluate("ancestor::tr/td[position()=3]", urls.snapshotItem(i), null, XPathResult.STRING_TYPE, null);
                var outputStatus = status.stringValue;
                // Truncate the status string on failure, since the description following "(failed)" is platform-dependent.
                if (outputStatus.startsWith("(failed)"))
                    outputStatus = "(failed)";
                outputStrings.push(urlFragment + ": " + outputStatus);
            }
        }
        outputStrings.sort();
        InspectorTest.addObject(outputStrings);
        InspectorTest.completeTest();
    }

    function onRequestFinished(request)
    {
        if (!requestsToWatch.test(request.url))
            return;
        if (++seenRequests === 3)
            dumpRequests();
    }

    WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestFinished, onRequestFinished);
    WebInspector.showPanel("network");
    InspectorTest.recordNetwork();
    InspectorTest.evaluateInPage("loadResources()");
}

function addScriptElement(src)
{
    var element = document.createElement("script");
    element.src = src;
    document.body.appendChild(element);
}

function loadResources()
{
    addScriptElement("../http/tests/inspector/network-test.js");
    addScriptElement("non-existent-file.js");

    // Test that data-url doesn't appear in network panel.
    addScriptElement("data:application/javascript,var x = 0;");
}

</script>
</head>
<body onload="runTest()">
</body>
</html>