summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/cssom/stylesheet-same-origin.sub.html
blob: 6ad55190dab366f2d9e4bdf7755750d7f5945bbe (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
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>CSSOM - CSSStylesheet should support origins</title>
    <link rel="help" href="https://drafts.csswg.org/cssom/#the-cssstylesheet-interface">
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>

    <link id="crossorigin" href="http://www1.{{host}}:{{ports[http][1]}}/css/cssom/stylesheet-same-origin.css" rel="stylesheet">
    <link id="sameorigin" href="stylesheet-same-origin.css" rel="stylesheet">
    <link id="sameorigindata" href="data:text/css,.green-text{color:rgb(0, 255, 0)}" rel="stylesheet">
    <link id="redirect-sameorigin-to-crossorigin"
          href="/common/redirect.py?location=http://www1.{{host}}:{{ports[http][1]}}/css/cssom/stylesheet-same-origin.css"
          rel="stylesheet">
    <link id="redirect-crossorigin-to-sameorigin"
          href="http://www1.{{host}}:{{ports[http][1]}}/common/redirect.py?location=http://{{host}}:{{ports[http][0]}}/css/cssom/stylesheet-same-origin.css"
          rel="stylesheet">
    <link id="loaderror" href="support/malformed-http-response.asis" rel="stylesheet">

    <script>
        var crossorigin = document.getElementById("crossorigin").sheet;
        var redirectSameOriginToCrossOrigin = document.getElementById("redirect-sameorigin-to-crossorigin").sheet;
        var redirectCrossOriginToSameOrigin = document.getElementById("redirect-crossorigin-to-sameorigin").sheet;
        var loadError = document.getElementById("loaderror").sheet;
        var sameorigin = document.getElementById("sameorigin").sheet;
        var sameorigindata = document.getElementById("sameorigindata").sheet;

        function doOriginCleanCheck(sheet, name) {
            assert_equals(sheet.cssRules.length, 1, name + " stylesheet.cssRules should be accessible.");
            sheet.insertRule("#test { margin: 10px; }", 1);
            assert_equals(sheet.cssRules.length, 2, name + " stylesheet.insertRule should be accessible.");
            sheet.deleteRule(0);
            assert_equals(sheet.cssRules.length, 1, name + " stylesheet.deleteRule should be accessible.");
        }

        function doOriginDirtyCheck(sheet) {
            assert_throws_dom("SecurityError",
                function () {
                    sheet.cssRules;
                },
                'stylesheet.cssRules should throw SecurityError.');
            assert_throws_dom("SecurityError",
                function () {
                    sheet.insertRule("#test { margin: 10px; }", 1);
                },
                'stylesheet.insertRule should throw SecurityError.');

            assert_throws_dom("SecurityError",
                function () {
                    sheet.deleteRule(0);
                },
                'stylesheet.deleteRule should throw SecurityError.');
        }

        test(function() {
            doOriginDirtyCheck(crossorigin);
        }, "Origin-clean check in cross-origin CSSOM Stylesheets");

        test(function() {
            doOriginDirtyCheck(redirectSameOriginToCrossOrigin);
        }, "Origin-clean check in cross-origin CSSOM Stylesheets (redirect from same-origin to cross-origin)");

        test(function() {
            doOriginDirtyCheck(redirectCrossOriginToSameOrigin);
        }, "Origin-clean check in cross-origin CSSOM Stylesheets (redirect from cross-origin to same-origin)");

       test(function() {
            doOriginDirtyCheck(loadError);
        }, "Origin-clean check in loading error CSSOM Stylesheets");

        test(function() {
            doOriginCleanCheck(sameorigin, "Same-origin");
        }, "Origin-clean check in same-origin CSSOM Stylesheets");

        test(function() {
            doOriginCleanCheck(sameorigindata, "data:css");
        }, "Origin-clean check in data:css CSSOM Stylesheets");

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