summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_css_cross_domain.html
blob: 8541c9c5ce875845fea42c1a5b0f8a90899ee9e8 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE HTML>
<html>
<!-- https://bugzilla.mozilla.org/show_bug.cgi?id=524223 -->
<head>
  <title>Test cross-domain CSS loading</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css"
        href="/tests/SimpleTest/test.css"/>
  <style type="text/css">
    hr { border: none; clear: both }
    .column {
        margin: 10px;
        float: left;
    }
    iframe {
        width: 40px;
        height: 680px;
        border: none;
        margin: 0;
        padding: 0;
    }
    h2 { font-weight: normal; padding: 0 }
    ol, h2 { font-size: 13px; line-height: 20px; }
    ol { padding-left: 1em;
         list-style-type: upper-roman }
    ol ol { list-style-type: upper-alpha }
    ol ol ol { list-style-type: decimal }
  </style>
</head>
<body>
<a target="_blank"
   href="https://bugzilla.mozilla.org/show_bug.cgi?id=524223">Mozilla
   Bug 524223</a>

<hr/>

<div class="column">
<h2>&nbsp;</h2>
<ol><li>text/css<ol><li>same origin<ol><li>valid</li>
                                       <li>malformed</li>
                                       <li>http error</li></ol></li>
                  <li>cross origin<ol><li>valid</li>
                                      <li>malformed</li>
                                      <li>http error</li></ol></li>
                  <li>same to cross<ol><li>valid</li>
                                       <li>malformed</li>
                                       <li>http error</li></ol></li>
                  <li>cross to same<ol><li>valid</li>
                                       <li>malformed</li>
                                       <li>http error</li></ol></li></ol></li>
    <li>text/html<ol><li>same origin<ol><li>valid</li>
                                        <li>malformed</li>
                                        <li>http error</li></ol></li>
                     <li>cross origin<ol><li>valid</li>
                                         <li>malformed</li>
                                         <li>http error</li></ol></li>
                     <li>same to cross<ol><li>valid</li>
                                          <li>malformed</li>
                                          <li>http error</li></ol></li>
                     <li>cross to same<ol><li>valid</li>
                                          <li>malformed</li>
                                          <li>http error</li></ol></li></ol></li>
</ol>
</div>

<div class="column">
<h2>Quirks</h2>
<div id="quirks-placeholder"></div>
</div>

<div class="column">
<h2>Standards</h2>
<div id="standards-placeholder"></div>
</div>

<script type="application/javascript">

const COLOR = {red: "rgb(255, 0, 0)", lime: "rgb(0, 255, 0)"};

// Cross origin requests with text/html as the contentType.
// These requests will be blocked by ORB (when ORB is enabled),
// thus the color of the element is not going to be changed.
const BLOCKED_BY_ORB = ["JD1i", "JD1l", "JD2i", "JD2l"];

/** Test for Bug 524223 **/
function check_iframe(ifr) {
  var doc = ifr.contentDocument;
  var cases = doc.getElementsByTagName("p");

  for (var i = 0; i < cases.length; i++) {
	  var color = doc.defaultView.getComputedStyle(cases[i])
        .getPropertyValue("background-color");

    var id = cases[i].id;
    // only 'quirks' can have requests that are blocked by ORB.
    if (BLOCKED_BY_ORB.includes(id) && ifr.id === "quirks") {
	    is(color, COLOR.red, ifr.id + " " + id);
    } else {
	    is(color, COLOR.lime, ifr.id + " " + id);
    }
  }
}

SimpleTest.waitForExplicitFinish();

function insertIFrames(src, id) {
  const quirks = document.createElement("iframe");
  quirks.src = "ccd-quirks.html";
  quirks.id = "quirks";
  document.getElementById("quirks-placeholder").replaceWith(quirks);

  const standards = document.createElement("iframe");
  standards.src = "ccd-standards.html";
  standards.id = "standards";
  document.getElementById("standards-placeholder").replaceWith(standards);
}

var hasQuirksLoaded = false;
var hasStandardsLoaded = false;

function quirksLoaded() {
  hasQuirksLoaded = true;
  MaybeRunTest();
}

function standardsLoaded() {
  hasStandardsLoaded = true;
  MaybeRunTest();
}

function runTest() {
  check_iframe(document.getElementById("quirks"));
  check_iframe(document.getElementById("standards"));
}

function MaybeRunTest() {
  if (!hasQuirksLoaded || !hasStandardsLoaded) {
      return;
  }

  runTest();
  SimpleTest.finish();
}

window.onload = async function() {
  await SpecialPowers.pushPrefEnv(
    {
      set: [
        ['browser.opaqueResponseBlocking', true],
        ['browser.opaqueResponseBlocking.javascriptValidator', true],
      ],
    }
  );
  insertIFrames();
};
</script>
</body>
</html>