summaryrefslogtreecommitdiff
path: root/dom/security/test/csp/file_inlinestyle_main_allowed.html
blob: 9b533ef07413cc3f593061324f1092f4b9d3eeb9 (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
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<html>
  <head>
    <title>CSP inline script tests</title>
    <!-- content= "div#linkstylediv { color: #0f0; }" -->
    <link rel="stylesheet" type="text/css"
          href='file_CSP.sjs?type=text/css&content=div%23linkstylediv%20%7B%20color%3A%20%230f0%3B%20%7D' />
    <!-- content= "div#modifycsstextdiv { color: #f00; }" -->
    <link rel="stylesheet" type="text/css"
          href='file_CSP.sjs?type=text/css&content=div%23modifycsstextdiv%20%7B%20color%3A%20%23f00%3B%20%7D' />
    <script>
      function cssTest() {
        // CSSStyleDeclaration.cssText
        var elem = document.getElementById('csstextstylediv');
        elem.style.cssText = "color: #00FF00;";

        // If I call getComputedStyle as below, this test passes as the parent page
        // correctly detects that the text is colored green - if I remove this, getComputedStyle
        // thinks the text is black when called by the parent page.
        getComputedStyle(elem, null).color;

        document.styleSheets[1].cssRules[0].style.cssText = "color: #00FF00;";
        elem = document.getElementById('modifycsstextdiv');
        getComputedStyle(elem, null).color;
      }
    </script>
  </head>
  <body onload='cssTest()'>

    <style type="text/css">
      div#inlinestylediv {
        color: #00FF00;
      }
    </style>

    <div id='linkstylediv'>Link tag (external) stylesheet test (should be green)</div>
    <div id='inlinestylediv'>Inline stylesheet test (should be green)</div>
    <div id='attrstylediv' style="color: #00FF00;">Attribute stylesheet test (should be green)</div>
    <div id='csstextstylediv'>style.cssText test (should be green)</div>
    <div id='modifycsstextdiv'> modify rule from style sheet via cssText(should be green) </div>

    <!-- tests for SMIL stuff - animations -->
    <svg xmlns="http://www.w3.org/2000/svg"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         width="100%"
         height="100px">

      <!-- Animates XML attribute, which is mapped into style. -->
      <text id="xmlTest" x="0" y="15">
         This should be green since the animation should be allowed by CSP.

        <animate attributeName="fill" attributeType="XML"
                  values="lime;green;lime" dur="2s"
                  repeatCount="indefinite" />
      </text>

      <!-- Animates override value for CSS property. -->
      <text id="cssOverrideTest" x="0" y="35">
         This should be green since the animation should be allowed by CSP.

        <animate attributeName="fill" attributeType="CSS"
                  values="lime;green;lime" dur="2s"
                  repeatCount="indefinite" />
      </text>

      <!-- Animates override value for CSS property targeted via ID. -->
      <text id="cssOverrideTestById" x="0" y="55">
         This should be green since the animation should be allowed by CSP.
      </text>
      <animate xlink:href="#cssOverrideTestById"
               attributeName="fill"
               values="lime;green;lime"
               dur="2s" repeatCount="indefinite" />

      <!-- Sets value for CSS property targeted via ID. -->
      <text id="cssSetTestById" x="0" y="75">
         This should be green since the &lt;set&gt; should be allowed by CSP.
      </text>
      <set xlink:href="#cssSetTestById"
               attributeName="fill"
               to="lime" />
    </svg>
  </body>
</html>