4 <meta http-equiv=
"Content-Security-Policy" content=
"connect-src http://example.com">
7 <script src=
"../../resources/js-test.js"></script>
9 description("This tests that exceptions thrown by XHR.open() have reasonable messages.");
13 var xhr
= new XMLHttpRequest();
14 xhr
.open("TRACE", "http://example.com/");
15 testFailed("xhr.open should throw an exception with a forbidden method type.");
18 shouldBeEqualToString("xhrException.message", "Failed to execute 'open' on 'XMLHttpRequest': 'TRACE' HTTP method is unsupported.");
22 var xhr
= new XMLHttpRequest();
23 xhr
.open("GET", "http://not.example.com/");
24 testFailed("xhr.open to a URL blocked by CSP should throw an exception.");
27 shouldBeEqualToString("xhrException.message", "Failed to execute 'open' on 'XMLHttpRequest': Refused to connect to 'http://not.example.com/' because it violates the document's Content Security Policy.");
30 var badString
= { toString: function() { throw "Exception in toString()"; } };
31 var xhr
= new XMLHttpRequest();
32 shouldBe("xhr.readyState", "XMLHttpRequest.UNSENT");
33 shouldThrow("xhr.open('GET', 'resources/xmlhttprequest-get-data.xml', true, badString, 'password');", "'Exception in toString()'");
34 shouldBe("xhr.readyState", "XMLHttpRequest.UNSENT");
35 shouldThrow("xhr.open('GET', 'resources/xmlhttprequest-get-data.xml', true, 'username', badString);", "'Exception in toString()'");
36 shouldBe("xhr.readyState", "XMLHttpRequest.UNSENT");