| <html> | |
| <head> | |
| <title>Test XMLHttpRequest exceptions</title> | |
| <meta http-equiv="content-type" content="text/html;charset=utf-8"> | |
| <body> | |
| <p>Test that XMLHttpRequest raises exceptions when it should.</p> | |
| <script> | |
| if (window.testRunner) | |
| testRunner.dumpAsText(); | |
| var console_messages = document.createElement("ul"); | |
| document.body.appendChild(console_messages); | |
| function log(message) | |
| { | |
| var item = document.createElement("li"); | |
| item.appendChild(document.createTextNode(message)); | |
| console_messages.appendChild(item); | |
| } | |
| function shouldThrow(_a, _e) { | |
| var exception; | |
| var _av; | |
| try { | |
| _av = eval(_a); | |
| } catch (e) { | |
| exception = e.description ? e.description : e; | |
| } | |
| var _ev; | |
| if (_e) | |
| _ev = eval(_e); | |
| if (exception) { | |
| if (typeof _e == "undefined" || exception == _ev) | |
| log("PASS: " + _a + " threw exception " + exception + "."); | |
| else | |
| log("FAIL: " + _a + " should throw exception " + _ev + ". Threw exception " + exception + "."); | |
| } else if (typeof _av == "undefined") | |
| log("FAIL: " + _a + " should throw exception " + _e + ". Was undefined."); | |
| else | |
| log("FAIL: " + _a + " should throw exception " + _e + ". Was " + _av + "."); | |
| } | |
| // ------------------------- | |
| if (window.XMLHttpRequest) { | |
| req = new XMLHttpRequest(); | |
| } else { | |
| try { | |
| req = new ActiveXObject("Msxml2.XMLHTTP"); | |
| } catch (ex) { | |
| req = new ActiveXObject("Microsoft.XMLHTTP"); | |
| } | |
| } | |
| log("new XMLHttpRequest()"); | |
| shouldThrow('req.setRequestHeader("Foo", "bar")'); | |
| shouldThrow('req.send(null)'); | |
| req.open('GET', 'resources/zero-length.txt', false); | |
| log("open()"); | |
| shouldThrow('req.setRequestHeader()'); | |
| shouldThrow('req.setRequestHeader("Foo")'); | |
| shouldThrow('req.status()'); | |
| shouldThrow('req.statusText()'); | |
| req.send(null); | |
| log("send()"); | |
| shouldThrow('req.send(null)'); | |
| shouldThrow('req.setRequestHeader("Foo", "bar")'); | |
| shouldThrow('req.getResponseHeader()'); | |
| shouldThrow('req.open()'); | |
| shouldThrow('req.open(null)'); | |
| </script> | |
| </body> | |
| </html> |