Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/html/dom/documents/dom-tree-accessors/Document.currentScript.html

Issue 2446483002: Import wpt@c5a14f553cba5f197743b9af605a84eddd8692a2 (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE HTML>
2 <meta charset=utf-8>
3 <title>Document.currentScript</title>
4 <link rel=help href="https://html.spec.whatwg.org/multipage/#dom-document-curren tscript">
5 <link rel=help href="https://html.spec.whatwg.org/multipage/#execute-the-script- block">
6 <script src="/resources/testharness.js"></script>
7 <script src="/resources/testharnessreport.js"></script>
8 <script src="/common/get-host-info.sub.js"></script>
9 <div id="log"></div>
10 <script>
11 var data = {
12 "parse-inline" : [],
13 "parse-ext" : [],
14 "dom-inline" : [],
15 "dom-ext" : [],
16 "nested" : ["nested-outer","nested-inner","nested-outer"],
17 "script-exec" : ["script-exec-before-after","script-exec-before-after"],
18 "script-load-error" : [null],
19 "script-window-error" : ["script-error-compile","script-error-runtime"],
20 "timeout" : [null],
21 "eval" : [],
22 "xhr-test" : [],
23 "script-svg" : [],
24 "script-async" : [],
25 "script-defer" : [],
26 "script-async-false" : [],
27 "iframe-src" : [],
28 "cross-origin" : [null],
29 "document-write" : []
30 };
31
32 var expected = {};
33 var actual = {};
34
35 Object.keys(data).forEach(function(id) {
36 var test_expected = data[id];
37 if(test_expected.length == 0) {
38 test_expected = [id];
39 }
40 expected[id] = test_expected;
41 actual[id] = [];
42 });
43
44 var tests = {};
45 setup({allow_uncaught_exception : true});
46
47 Object.keys(expected).forEach(function(id) {
48 var testmsg = "Script " + id;
49 tests[id] = async_test(testmsg);
50 });
51
52 function verify(id) {
53 tests[id].step(function() {
54 actual[id].push(document.currentScript);
55 })
56 }
57
58 function finish(id) {
59 tests[id].step(function() {
60 assert_array_equals(actual[id],expected[id].map(function(id) {
61 return document.getElementById(id);
62 }));
63 this.done();
64 })
65 }
66
67 </script>
68
69 <!-- Test parser inserted scripts -->
70 <script id="parse-inline">
71 verify('parse-inline');
72 finish('parse-inline')
73 </script>
74 <script id="parse-ext" src="data:text/plain,verify('parse-ext')"></script>
75 <script>finish('parse-ext');</script>
76
77 <!-- Test DOM inserted scripts -->
78 <script>
79 var s = document.createElement("script");
80 s.textContent = "verify('dom-inline');";
81 s.id = "dom-inline";
82 document.body.appendChild(s);
83 finish('dom-inline');
84
85 s = document.createElement("script");
86 s.src = "data:text/plain,verify('dom-ext');";
87 s.id = "dom-ext";
88 s.onload = function() {
89 finish('dom-ext');
90 }
91 document.body.appendChild(s);
92 </script>
93
94 <!-- Test Nested scripts -->
95 <script id="nested-outer">
96 verify("nested");
97 var s = document.createElement("script");
98 s.textContent = "verify('nested')";
99 s.id = "nested-inner";
100 document.body.appendChild(s);
101 verify("nested");
102 finish('nested');
103 </script>
104
105 <!-- Test script load error event listener -->
106 <script>
107 function testLoadFail() {
108 verify('script-load-error');
109 finish('script-load-error');
110 }
111 </script>
112
113 <script src="http://some.nonexistant.test/fail" id="script-load-error" onerror=" testLoadFail()">
114 </script>
115
116 <!-- Test for runtime and compile time errors -->
117 <script>
118 window.onerror = function() {
119 verify('script-window-error');
120 }
121
122 var s = document.createElement("script");
123 s.id = "script-error-compile";
124 s.textContent = "{";
125 document.body.appendChild(s);
126
127 window.onerror = function() {
128 verify('script-window-error');
129 }
130
131 s = document.createElement("script");
132 s.id = "script-error-runtime";
133 s.textContent = "undefinedfn();";
134 document.body.appendChild(s);
135
136 finish('script-window-error');
137 </script>
138
139 <!-- Verify in setTimeout -->
140 <script>
141 setTimeout(function() {
142 verify('timeout');
143 finish('timeout');
144 },0);
145 </script>
146
147 <!-- Verify in eval -->
148 <script id="eval">
149 eval('verify("eval")');
150 finish("eval");
151 </script>
152
153 <!-- Verify in synchronous xhr -->
154 <script id="xhr-test">
155 var request = new XMLHttpRequest();
156 request.open('GET','/',false);
157 request.send(null);
158
159 if(request.status === 200) {
160 verify('xhr-test');
161 finish('xhr-test');
162 }
163 </script>
164
165 <!-- Testing script within svg -->
166 <svg>
167 <script id="script-svg">
168 verify('script-svg');
169 finish('script-svg');
170 </script>
171 </svg>
172
173 <!-- Test script async and defer -->
174 <script id='script-async' async src='data:text/plain,verify("script-async"),fini sh("script-async")'></script>
175
176 <script id='script-defer' defer src='data:text/plain,verify("script-defer"),fini sh("script-defer")'></script>
177
178 <!-- Test async = false dynamic script loading -->
179 <script>
180 var s = document.createElement("script");
181 s.id = "script-async-false";
182 s.src = "data:text/plain,verify('script-async-false');"
183 s.onload = function() {
184 finish('script-async-false');
185 }
186 s.async = false;
187 document.body.appendChild(s);
188 </script>
189
190 <!-- Verify in iframe javascript uri scheme -->
191 <iframe src="javascript:parent.verify('iframe-src'),parent.finish('iframe-src')"
192 style="visibility:hidden;display:none">
193 </iframe>
194
195 <!-- Testing cross origin script -->
196 <script>
197 var s = document.createElement("script");
198 s.id = "cross-origin";
199 s.src = get_host_info(). HTTP_REMOTE_ORIGIN + "/html/dom/documents/dom-tree-acce ssors/cross-domain.js"
200 s.onload = function() {
201 verify('cross-origin')
202 finish('cross-origin');
203 }
204 document.body.appendChild(s);
205
206 </script>
207
208 <!-- Testing document.write -->
209 <script>
210 document.write('<script id="document-write">verify("document-write"); finish("do cument-write");</' + 'script>');
211 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698