summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/inspector/cookie-resource-match.html
blob: cf92910166505ba602f115c7d06d18cf00a36666 (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
<html>
<head>
<script src="../http/tests/inspector/inspector-test.js"></script>
<script>

function test() {

    var cookies = [
        createCookie("insecureOnlyWebkit", "1234567890", false, "webkit.org", "/"),
        createCookie("insecureAllWebkit", "1234567890123456", false, ".webkit.org", "/"),
        createCookie("insecureAllWebkitPath", "1234567890123456", false, ".webkit.org", "/path"),
        createCookie("secureOnlyWebkitPath", "bar", true, "webkit.org", "/path"),
        createCookie("secureAllWebkit", "foo", true, ".webkit.org", "/"),
        createCookie("secureAllWebkitPath", "foo", true, ".webkit.org", "/path"),
        createCookie("insecureOnlyWebkitPort", "1234567890", false, "webkit.org", "/", 80),
        createCookie("insecureAllWebkitPort", "1234567890123456", false, ".webkit.org", "/", 80),
        createCookie("insecureAllWebkitPathPort", "1234567890123456", false, ".webkit.org", "/path", 80),
        createCookie("secureOnlyWebkitPathPort", "bar", true, "webkit.org", "/path", 80),
        createCookie("secureAllWebkitPort", "foo", true, ".webkit.org", "/", 80),
        createCookie("secureAllWebkitPathPort", "foo", true, ".webkit.org", "/path", 80),
        createCookie("nonMatching1", "bar", false, "webkit.zoo", "/"),
        createCookie("nonMatching2", "bar", false, "webkit.org", "/badPath"),
        createCookie("nonMatching3", "bar", true, ".moo.com", "/")
    ];

    var resourceURLs = [
        "http://webkit.org", // 0
        "http://www.webkit.org:81", // 1
        "http://webkit.org/path", // 2
        "http://www.webkit.org/path", // 3
        "https://webkit.org/", // 4
        "https://www.webkit.org/", // 5
        "https://webkit.org:81/path", // 6
        "https://www.webkit.org/path", // 7

        "http://webkit.org:80", // 8
        "http://www.webkit.org:80", // 9
        "http://webkit.org:80/path", // 10
        "http://www.webkit.org:80/path", // 11
        "https://webkit.org:80/", // 12
        "https://www.webkit.org:80/", // 13
        "https://webkit.org:80/path", // 14
        "https://www.webkit.org:80/path", // 15

        "http://www.boo.com:80", // 16
        "https://www.boo.com:80/path", // 17
        "http://www.moo.com:80/", // 18
        "http://www.boo.com:80", // 19
        "https://www.boo.com:80/path", // 20
        "http://www.moo.com:80/" // 21
    ];

    var result = [];
    for (var i = 0; i < cookies.length; ++i) {
        var cookieResult = [];
        for (var j = 0; j < resourceURLs.length; ++j) {
            if (WebInspector.Cookies.cookieMatchesResourceURL(cookies[i], resourceURLs[j]))
                cookieResult.push(j);
        }
        InspectorTest.addResult("[" + cookieResult + "]");
    }
    InspectorTest.completeTest();

    function createCookie(name, value, secure, domain, path, port)
    {
        var protocolCookie = {
            name: name,
            value: value,
            domain: domain,
            port: port,
            path: path,
            expires: "Thu Jan 01 1970 00:00:00 GMT",
            size: name.length + value.length,
            httpOnly: false,
            secure: secure,
            session: true
        };
        return WebInspector.Cookies.buildCookieProtocolObject(protocolCookie);
    }
}
</script>
</head>

<body onload="runTest()">
<p>
Tests that cookies are matched up with resources correctly.
</p>

</body>
</html>