"Not enough arguments" error should be TypeError
[WebKit-https.git] / LayoutTests / http / tests / xmlhttprequest / exceptions.html
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>
8
9     if (window.layoutTestController)
10         layoutTestController.dumpAsText();
11
12     var console_messages = document.createElement("ul");
13     document.body.appendChild(console_messages);
14     
15     function log(message)
16     {
17         var item = document.createElement("li");
18         item.appendChild(document.createTextNode(message));
19         console_messages.appendChild(item);
20     }
21     
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;
29         }
30         
31         var _ev;
32         if (_e)
33             _ev =  eval(_e);
34         
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 + ".");
44     }
45
46 // -------------------------
47     
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");
55         }
56     }
57     log("new XMLHttpRequest()");
58
59     shouldThrow('req.setRequestHeader("Foo", "bar")');
60     shouldThrow('req.send(null)');
61     
62     req.open('GET', 'resources/zero-length.txt', false);
63     log("open()");
64     
65     shouldThrow('req.setRequestHeader()');
66     shouldThrow('req.setRequestHeader("Foo")');
67     shouldThrow('req.status()');
68     shouldThrow('req.statusText()');
69     
70     req.send(null);
71     log("send()");
72
73     shouldThrow('req.send(null)');
74     shouldThrow('req.setRequestHeader("Foo", "bar")');
75     shouldThrow('req.getResponseHeader()');
76
77     shouldThrow('req.open()');
78     shouldThrow('req.open(null)');
79    
80 </script>
81 </body>
82 </html>