Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / exceptions.html
blobe7e2278021cfe4d4152c422e4f8daa34de205c4b
1 <html>
2 <head>
3 <title>Test XMLHttpRequest exceptions</title>
4 <meta http-equiv="content-type" content="text/html;charset=utf-8">
5 <body>
6 <p>Test that XMLHttpRequest raises exceptions when it should.</p>
7 <script>
9 if (window.testRunner)
10 testRunner.dumpAsText();
12 var console_messages = document.createElement("ul");
13 document.body.appendChild(console_messages);
15 function log(message)
17 var item = document.createElement("li");
18 item.appendChild(document.createTextNode(message));
19 console_messages.appendChild(item);
22 function shouldThrow(_a, _e) {
23 var exception;
24 var _av;
25 try {
26 _av = eval(_a);
27 } catch (e) {
28 exception = e.description ? e.description : e;
31 var _ev;
32 if (_e)
33 _ev = eval(_e);
35 if (exception) {
36 if (typeof _e == "undefined" || exception == _ev)
37 log("PASS: " + _a + " threw exception " + exception + ".");
38 else
39 log("FAIL: " + _a + " should throw exception " + _ev + ". Threw exception " + exception + ".");
40 } else if (typeof _av == "undefined")
41 log("FAIL: " + _a + " should throw exception " + _e + ". Was undefined.");
42 else
43 log("FAIL: " + _a + " should throw exception " + _e + ". Was " + _av + ".");
46 // -------------------------
48 if (window.XMLHttpRequest) {
49 req = new XMLHttpRequest();
50 } else {
51 try {
52 req = new ActiveXObject("Msxml2.XMLHTTP");
53 } catch (ex) {
54 req = new ActiveXObject("Microsoft.XMLHTTP");
57 log("new XMLHttpRequest()");
59 shouldThrow('req.setRequestHeader("Foo", "bar")');
60 shouldThrow('req.send(null)');
62 req.open('GET', 'resources/zero-length.txt', false);
63 log("open()");
65 shouldThrow('req.setRequestHeader()');
66 shouldThrow('req.setRequestHeader("Foo")');
68 req.send(null);
69 log("send()");
71 shouldThrow('req.send(null)');
72 shouldThrow('req.setRequestHeader("Foo", "bar")');
73 shouldThrow('req.getResponseHeader()');
75 shouldThrow('req.open()');
76 shouldThrow('req.open(null)');
78 </script>
79 </body>
80 </html>