summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/the-window-object/security-window/window-security.sub.html
blob: 9a9ef358ec13ee8f3f0320ea3792cf6ce6975453 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test: Window Security</title>
<link rel="author" title="Intel" href="http://www.intel.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/multipage/browsers.html#the-window-object" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/multipage/timers.html#timers" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/multipage/webappapis.html#atob" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#windowsessionstorage" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#windowlocalstorage" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/multipage/browsers.html#window" />
<link rel="help" href="http://dev.w3.org/csswg/cssom/#extensions-to-the-window-interface" />
<link rel="help" href="http://dev.w3.org/csswg/cssom-view/#extensions-to-the-window-interface" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<div id="log"></div>
<script>
var t = async_test("Window Security testing");

function fr_load() {
  fr = document.getElementById("fr");

  t.step(function () {
    //SecurityError should be thrown
    [
      //attributes
      {name: "applicationCache"},
      {name: "devicePixelRatio"},
      {name: "document"},
      {name: "external"},
      {name: "frameElement"},
      {name: "history"},
      {name: "innerWidth"},
      {name: "innerHeight"},
      {name: "locationbar"},
      {name: "localStorage"},
      {name: "menubar"},
      {name: "name"},
      {name: "navigator"},
      {name: "onabort"},
      {name: "onafterprint"},
      {name: "onbeforeprint"},
      {name: "onbeforeunload"},
      {name: "onblur"},
      {name: "oncancel"},
      {name: "oncanplay"},
      {name: "oncanplaythrough"},
      {name: "onchange"},
      {name: "onclick"},
      {name: "onclose"},
      {name: "oncontextmenu"},
      {name: "oncuechange"},
      {name: "ondblclick"},
      {name: "ondrag"},
      {name: "ondragend"},
      {name: "ondragenter"},
      {name: "ondragleave"},
      {name: "ondragover"},
      {name: "ondragstart"},
      {name: "ondrop"},
      {name: "ondurationchange"},
      {name: "onemptied"},
      {name: "onended"},
      {name: "onerror"},
      {name: "onfocus"},
      {name: "onhashchange"},
      {name: "oninput"},
      {name: "oninvalid"},
      {name: "onkeydown"},
      {name: "onkeypress"},
      {name: "onkeyup"},
      {name: "onload"},
      {name: "onloadeddata"},
      {name: "onloadedmetadata"},
      {name: "onloadstart"},
      {name: "onmessage"},
      {name: "onmousedown"},
      {name: "onmousemove"},
      {name: "onmouseout"},
      {name: "onmouseover"},
      {name: "onmouseup"},
      {name: "onmousewheel"},
      {name: "onoffline"},
      {name: "ononline"},
      {name: "onpause"},
      {name: "onplay"},
      {name: "onplaying"},
      {name: "onpagehide"},
      {name: "onpageshow"},
      {name: "onpopstate"},
      {name: "onprogress"},
      {name: "onratechange"},
      {name: "onreset"},
      {name: "onresize"},
      {name: "onscroll"},
      {name: "onseeked"},
      {name: "onseeking"},
      {name: "onselect"},
      {name: "onshow"},
      {name: "onstalled"},
      {name: "onstorage"},
      {name: "onsubmit"},
      {name: "onsuspend"},
      {name: "ontimeupdate"},
      {name: "onunload"},
      {name: "onvolumechange"},
      {name: "onwaiting"},
      {name: "pageXOffset"},
      {name: "pageYOffset"},
      {name: "personalbar"},
      {name: "screen"},
      {name: "scrollbars"},
      {name: "statusbar"},
      {name: "status"},
      {name: "screenX"},
      {name: "screenY"},
      {name: "sessionStorage"},
      {name: "toolbar"},
      //methods
      {name: "alert", isMethod: true},
      {name: "clearInterval", isMethod: true, args:[1]},
      {name: "clearTimeout", isMethod: true, args:[function () {}, 1]},
      {name: "confirm", isMethod: true},
      {name: "getComputedStyle", isMethod: true, args:[document.body, null]},
      {name: "getSelection", isMethod: true},
      {name: "matchMedia", isMethod: true, args:["(min-width:50px)"]},
      {name: "moveBy", isMethod: true, args:[10, 10]},
      {name: "moveTo", isMethod: true, args:[10, 10]},
      {name: "open", isMethod: true},
      {name: "print", isMethod: true},
      {name: "prompt", isMethod: true},
      {name: "resizeTo", isMethod: true, args:[10, 10]},
      {name: "resizeBy", isMethod: true, args:[10, 10]},
      {name: "scroll", isMethod: true, args:[10, 10]},
      {name: "scrollTo", isMethod: true, args:[10, 10]},
      {name: "scrollBy", isMethod: true, args:[10, 10]},
      {name: "setInterval", isMethod: true, args:[function () {}, 1]},
      {name: "setTimeout", isMethod: true, args:[function () {}, 1]},
      {name: "showModalDialog", isMethod: true, args:["auto:blank", "dialog"]},
      {name: "stop", isMethod: true},
    ].forEach(function (item) {
      test(function () {
        assert_true(item.name in window, "window." + item.name + " should exist.");
        assert_throws("SecurityError", function () {
          if (item.isMethod)
            if (item.args)
              fr.contentWindow[item.name](item.args[0], item.args[1]);
            else
              fr.contentWindow[item.name]();
          else
            fr.contentWindow[item.name];
        }, "A SecurityError exception should be thrown.");
      }, "A SecurityError exception must be thrown when window." + item.name + " is accessed from a different origin.");
    });

    //SecurityError should not be thrown
    [
      //attributes
      {name: "closed"},
      {name: "frames"},
      {name: "length"},
      {name: "location"},
      {name: "opener"},
      {name: "parent"},
      {name: "self"},
      {name: "top"},
      {name: "window"},
      //methods
      {name: "blur", isMethod: true},
      {name: "close", isMethod: true},
      {name: "focus", isMethod: true},
      {name: "postMessage", isMethod: true, args: [{msg: 'foo'}, "*"]}
    ].forEach(function (item) {
      test(function () {
        assert_true(item.name in window, "window." + item.name + " should exist.");
        try {
          if (item.isMethod)
            if (item.args)
              fr.contentWindow[item.name](item.args[0], item.args[1]);
            else
               fr.contentWindow[item.name]();
          else
            fr.contentWindow[item.name];
        } catch (e) {
          assert_unreached("An unexpected exception was thrown.");
        }
      }, "A SecurityError exception should not be thrown when window." + item.name + " is accessed from a different origin.");
    });
  });
  t.done();
}

</script>
<script>
onload = function() {
  var frame = document.createElement('iframe');
  frame.id = "fr";
  frame.setAttribute("style", "display:none");
  frame.setAttribute('src', get_host_info().HTTP_REMOTE_ORIGIN + "/");
  frame.setAttribute("onload", "fr_load()");
  document.body.appendChild(frame);
}
</script>