File tree Expand file tree Collapse file tree
main/java/org/htmlunit/javascript/host/xml
java/org/htmlunit/javascript/host/xml
resources/testfiles/localxmlhttprequest Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -998,6 +998,7 @@ void doSend() {
998998 fireJavascriptEvent (Event .TYPE_READY_STATE_CHANGE );
999999 fireJavascriptEvent (Event .TYPE_ERROR );
10001000 fireJavascriptEvent (Event .TYPE_LOAD_END );
1001+ return ;
10011002 }
10021003 else {
10031004 throw JavaScriptEngine .asJavaScriptException (
Original file line number Diff line number Diff line change @@ -217,4 +217,21 @@ public void sendLocalSubFileAllowed() throws Exception {
217217 assertEquals (0 , client .waitForBackgroundJavaScriptStartingBefore (1000 ));
218218 assertEquals (getExpectedAlerts ()[0 ], page .getTitleText ());
219219 }
220+
221+ /**
222+ * @throws Exception if the test fails
223+ */
224+ @ Test
225+ @ Alerts ("readystatechange§1§0§readystatechange§4§0§error§" )
226+ public void sendLocalFileAsyncNotAllowed () throws Exception {
227+ final URL fileURL = getClass ().getClassLoader ().getResource ("testfiles/localxmlhttprequest/index_async.html" );
228+ final File file = new File (fileURL .toURI ());
229+ assertTrue ("File '" + file .getAbsolutePath () + "' does not exist" , file .exists ());
230+
231+ final WebClient client = getWebClient ();
232+ final HtmlPage page = client .getPage (fileURL );
233+
234+ assertEquals (0 , client .waitForBackgroundJavaScriptStartingBefore (1000 ));
235+ assertEquals (getExpectedAlerts ()[0 ], page .getTitleText ());
236+ }
220237}
Original file line number Diff line number Diff line change 1+ < html >
2+ < head > < script >
3+ function log ( msg ) { window . document . title += msg + '\u00a7' ; }
4+ function test ( ) {
5+ try {
6+ var xhr = new XMLHttpRequest ( ) ;
7+ xhr . onreadystatechange = function ( event ) {
8+ log ( event . type ) ;
9+ log ( xhr . readyState ) ;
10+ log ( xhr . responseText . length ) ;
11+ } ;
12+ xhr . onerror = function ( event ) {
13+ log ( event . type ) ;
14+ } ;
15+ xhr . open ( 'GET' , 'index_async.html' , true ) ;
16+ xhr . send ( '' ) ;
17+ } catch ( exception ) {
18+ log ( exception . name ) ;
19+ }
20+ }
21+ </ script > </ head >
22+ < body onload ='test() '>
23+ </ body > </ html >
You can’t perform that action at this time.
0 commit comments