3 function testInvalidMethod() {
4 var result
= 'FAILURE';
6 var req
= new XMLHttpRequest();
9 req
.open('test\r\nfoobar', window
.location
, true)
11 if (e
.code
== DOMException
.SYNTAX_ERR
)
15 debug('testInvalidMethod: ' + result
);
18 function testInvalidHeaderName() {
19 var result
= 'FAILURE';
21 var req
= new XMLHttpRequest();
22 req
.open('GET', window
.location
, true)
25 req
.setRequestHeader("host:", "example.com");
27 if (e
.code
== DOMException
.SYNTAX_ERR
)
31 debug('testInvalidHeaderName: ' + result
);
34 function testInvalidHeaderValues() {
35 var result
= 'FAILURE';
38 var req
= new XMLHttpRequest();
39 req
.open('GET', window
.location
, true)
42 req
.setRequestHeader("X-Hack", "Test\r\nHost: www.example.com\r\n\r\nGET / HTTP/1.1");
44 if (e
.code
== DOMException
.SYNTAX_ERR
)
49 req
.setRequestHeader("X-Hack", "Test\nHost: www.example.com\n\nGET / HTTP/1.1");
51 if (e
.code
== DOMException
.SYNTAX_ERR
)
56 req
.setRequestHeader("X-Hack", "Test\rHost: www.example.com\r\rGET / HTTP/1.1");
58 if (e
.code
== DOMException
.SYNTAX_ERR
)
62 if (successCount
== 3)
65 debug('testInvalidHeaderValues: ' + result
);
69 var console
= document
.getElementById('console');
70 var li
= document
.createElement('li');
71 li
.appendChild(document
.createTextNode(str
));
72 console
.appendChild(li
);
76 if (window
.testRunner
)
77 testRunner
.dumpAsText();
80 testInvalidHeaderName();
81 testInvalidHeaderValues();
84 <body onload=
"runTest()">
85 This tests that setting invalid header names, values and using an invalid method causes XMLHttpRequest to throw the appropriate exceptions.