Skip to content

Commit 1fb09eb

Browse files
committed
more on error handling
1 parent e73723f commit 1fb09eb

File tree

7 files changed

+125
-114
lines changed

7 files changed

+125
-114
lines changed

src/test/java/org/htmlunit/javascript/host/xml/XMLDocument2Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public void createElement_namespace() throws Exception {
217217
* @throws Exception if the test fails
218218
*/
219219
@Test
220-
@Alerts("exception")
220+
@Alerts("ReferenceError")
221221
public void text() throws Exception {
222222
final String html = "<html><head>\n"
223223
+ "<script>\n"
@@ -226,7 +226,7 @@ public void text() throws Exception {
226226
+ " try {\n"
227227
+ " new ActiveXObject('Microsoft.XMLDOM');\n"
228228
+ " } catch (e) {\n"
229-
+ " log('exception');\n"
229+
+ " log(e.name);\n"
230230
+ " return;\n"
231231
+ " }\n"
232232
+ " var xmldoc = new ActiveXObject('Microsoft.XMLDOM');\n"

src/test/java/org/htmlunit/javascript/host/xml/XMLDocumentTest.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void async() throws Exception {
135135
* @throws Exception if the test fails
136136
*/
137137
@Test
138-
@Alerts("exception")
138+
@Alerts("TypeError")
139139
public void load() throws Exception {
140140
final String html = "<html><head>\n"
141141
+ "<script>\n"
@@ -150,7 +150,7 @@ public void load() throws Exception {
150150
+ " log(doc.childNodes[0].childNodes.length);\n"
151151
+ " log(doc.childNodes[0].childNodes[0].nodeName);\n"
152152
+ " log(doc.getElementsByTagName('books').item(0).attributes.length);\n"
153-
+ " } catch(e) { log('exception'); }\n"
153+
+ " } catch(e) { log(e.name); }\n"
154154
+ " }\n"
155155
+ "</script></head>\n"
156156
+ "<body onload='test()'>\n"
@@ -172,7 +172,7 @@ public void load() throws Exception {
172172
* @throws Exception if the test fails
173173
*/
174174
@Test
175-
@Alerts("exception")
175+
@Alerts("TypeError")
176176
// TODO what is the difference to load()?
177177
public void load_relativeURL() throws Exception {
178178
final String html = "<html><head>\n"
@@ -188,7 +188,7 @@ public void load_relativeURL() throws Exception {
188188
+ " log(doc.childNodes[0].childNodes.length);\n"
189189
+ " log(doc.childNodes[0].childNodes[0].nodeName);\n"
190190
+ " log(doc.getElementsByTagName('books').item(0).attributes.length);\n"
191-
+ " } catch(e) { log('exception'); }\n"
191+
+ " } catch(e) { log(e.name); }\n"
192192
+ " }\n"
193193
+ "</script></head>\n"
194194
+ "<body onload='test()'>\n"
@@ -229,7 +229,7 @@ public void preserveWhiteSpace() throws Exception {
229229
* @throws Exception if the test fails
230230
*/
231231
@Test
232-
@Alerts("exception")
232+
@Alerts("TypeError")
233233
public void setProperty() throws Exception {
234234
final String html = "<html><head>\n"
235235
+ "<script>\n"
@@ -239,7 +239,7 @@ public void setProperty() throws Exception {
239239
+ " try {\n"
240240
+ " doc.setProperty('SelectionNamespaces', \"xmlns:xsl='http://www.w3.org/1999/XSL/Transform'\");\n"
241241
+ " doc.setProperty('SelectionLanguage', 'XPath');\n"
242-
+ " } catch(e) { log('exception'); }\n"
242+
+ " } catch(e) { log(e.name); }\n"
243243
+ " }\n"
244244
+ "</script></head><body onload='test()'>\n"
245245
+ "</body></html>";
@@ -250,7 +250,7 @@ public void setProperty() throws Exception {
250250
* @throws Exception if the test fails
251251
*/
252252
@Test
253-
@Alerts("exception")
253+
@Alerts("TypeError")
254254
public void selectNodes() throws Exception {
255255
final String html = "<html><head>\n"
256256
+ "<script>\n"
@@ -261,7 +261,7 @@ public void selectNodes() throws Exception {
261261
+ " var nodes = doc.selectNodes('/books');\n"
262262
+ " log(nodes.length);\n"
263263
+ " log(nodes[0].tagName);\n"
264-
+ " } catch(e) { log('exception'); }\n"
264+
+ " } catch(e) { log(e.name); }\n"
265265
+ " }\n"
266266
+ LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
267267
+ "</script></head>\n"
@@ -284,7 +284,7 @@ public void selectNodes() throws Exception {
284284
* @throws Exception if the test fails
285285
*/
286286
@Test
287-
@Alerts("exception")
287+
@Alerts("TypeError")
288288
public void selectNodes_caseSensitive() throws Exception {
289289
final String html = "<html><head>\n"
290290
+ "<script>\n"
@@ -294,7 +294,7 @@ public void selectNodes_caseSensitive() throws Exception {
294294
+ " try {\n"
295295
+ " log(doc.selectNodes('/bOoKs').length);\n"
296296
+ " log(doc.selectNodes('/books').length);\n"
297-
+ " } catch(e) { log('exception'); }\n"
297+
+ " } catch(e) { log(e.name); }\n"
298298
+ " }\n"
299299
+ LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
300300
+ "</script></head>\n"
@@ -317,7 +317,7 @@ public void selectNodes_caseSensitive() throws Exception {
317317
* @throws Exception if the test fails
318318
*/
319319
@Test
320-
@Alerts("exception")
320+
@Alerts("TypeError")
321321
public void selectNodes_namespace() throws Exception {
322322
final String html = "<html><head>\n"
323323
+ "<script>\n"
@@ -327,7 +327,7 @@ public void selectNodes_namespace() throws Exception {
327327
+ " try {\n"
328328
+ " log(doc.selectNodes('//ns1:title').length);\n"
329329
+ " log(doc.selectNodes('//ns2:title').length);\n"
330-
+ " } catch(e) { log('exception'); }\n"
330+
+ " } catch(e) { log(e.name); }\n"
331331
+ " }\n"
332332
+ LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
333333
+ "</script></head>\n"
@@ -357,7 +357,7 @@ public void selectNodes_namespace() throws Exception {
357357
* @throws Exception if the test fails
358358
*/
359359
@Test
360-
@Alerts("exception")
360+
@Alerts("TypeError")
361361
public void selectNodes_nextNodeAndReset() throws Exception {
362362
final String html = "<html><head>\n"
363363
+ "<script>\n"
@@ -371,7 +371,7 @@ public void selectNodes_nextNodeAndReset() throws Exception {
371371
+ " nodes.reset();\n"
372372
+ " log(nodes.nextNode().nodeName);\n"
373373
+ " log(nodes.nextNode());\n"
374-
+ " } catch(e) { log('exception'); }\n"
374+
+ " } catch(e) { log(e.name); }\n"
375375
+ " }\n"
376376
+ LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
377377
+ "</script></head>\n"
@@ -412,7 +412,7 @@ public void selectNodes_fromRoot() throws Exception {
412412
+ " try {\n"
413413
+ " log(child.selectNodes('title').length);\n"
414414
+ " } catch(e) { log('exception title'); }\n"
415-
+ " } catch(e) { log('exception'); }\n"
415+
+ " } catch(e) { log(e.name); }\n"
416416
+ " }\n"
417417
+ LOAD_XML_DOCUMENT_FROM_FILE_FUNCTION
418418
+ "</script></head>\n"
@@ -428,7 +428,7 @@ public void selectNodes_fromRoot() throws Exception {
428428
* @throws Exception if the test fails
429429
*/
430430
@Test
431-
@Alerts("exception")
431+
@Alerts("TypeError")
432432
public void selectSingleNode() throws Exception {
433433
final String html = "<html><head>\n"
434434
+ "<script>\n"
@@ -441,7 +441,7 @@ public void selectSingleNode() throws Exception {
441441
+ " log(doc.selectNodes('/')[0].nodeName);\n"
442442
+ " log(doc.selectSingleNode('*').nodeName);\n"
443443
+ " log(doc.selectNodes('*')[0].selectSingleNode('/').nodeName);\n"
444-
+ " } catch(e) { log('exception'); }\n"
444+
+ " } catch(e) { log(e.name); }\n"
445445
+ " }\n"
446446
+ LOAD_XML_DOCUMENT_FROM_STRING_FUNCTION
447447
+ "</script></head><body onload='test()'>\n"
@@ -505,7 +505,7 @@ public void loadXML_XMLSpaceAttribute() throws Exception {
505505
* @throws Exception if the test fails
506506
*/
507507
@Test
508-
@Alerts("exception")
508+
@Alerts("ReferenceError")
509509
public void parseError() throws Exception {
510510
final String html = "<html><head>\n"
511511
+ "<script>\n"
@@ -531,7 +531,7 @@ public void parseError() throws Exception {
531531
+ " log(doc.parseError.reason !== '');\n"
532532
+ " log(doc.parseError.srcText !== '');\n"
533533
+ " log(doc.parseError.url !== '');\n"
534-
+ " } catch(e) { log('exception'); }\n"
534+
+ " } catch(e) { log(e.name); }\n"
535535
+ " }\n"
536536
+ "</script></head>\n"
537537
+ "<body onload='test()'>\n"
@@ -581,15 +581,15 @@ public void createNSResolver() throws Exception {
581581
* @throws Exception if the test fails
582582
*/
583583
@Test
584-
@Alerts("exception")
584+
@Alerts("TypeError")
585585
public void xmlInsideHtml() throws Exception {
586586
final String html = "<html><head>\n"
587587
+ "<script>\n"
588588
+ LOG_TITLE_FUNCTION
589589
+ " function test() {\n"
590590
+ " try {\n"
591591
+ " log(messageTableHeaders.documentElement.nodeName);\n"
592-
+ " } catch(e) {log('exception'); }\n"
592+
+ " } catch(e) {log(e.name); }\n"
593593
+ " }\n"
594594
+ "</script>\n"
595595
+ "</head>\n"
@@ -617,7 +617,7 @@ public void instanceOf() throws Exception {
617617
+ " var x = " + callLoadXMLDocumentFromString("'<x/>'") + ";\n"
618618
+ " try {\n"
619619
+ " log(x instanceof XMLDocument);\n"
620-
+ " }catch(e) {log('exception')}\n"
620+
+ " }catch(e) {log(e.name)}\n"
621621
+ " }\n"
622622
+ LOAD_XML_DOCUMENT_FROM_STRING_FUNCTION
623623
+ "</script>\n"
@@ -828,7 +828,7 @@ public void getElementById_xml() throws Exception {
828828
+ " log(doc.getElementById('item2') != null);\n"
829829
+ " log(doc.getElementById('item3') != null);\n"
830830
+ " log(doc.getElementById('item4') != null);\n"
831-
+ " } catch(e) { log('exception'); }\n"
831+
+ " } catch(e) { log(e.name); }\n"
832832
+ " }\n"
833833
+ LOAD_XML_DOCUMENT_FROM_STRING_FUNCTION
834834
+ "</script></head>\n"
@@ -855,7 +855,7 @@ public void getElementById_html() throws Exception {
855855
+ " var doc = " + callLoadXMLDocumentFromString("text") + ";\n"
856856
+ " log(doc.getElementById('form1') != null);\n"
857857
+ " log(doc.getElementById('div1') != null);\n"
858-
+ " } catch(e) { log('exception'); }\n"
858+
+ " } catch(e) { log(e.name); }\n"
859859
+ " }\n"
860860
+ LOAD_XML_DOCUMENT_FROM_STRING_FUNCTION
861861
+ "</script></head>\n"
@@ -881,7 +881,7 @@ public void getElementById_xhtml() throws Exception {
881881
+ " var doc = " + callLoadXMLDocumentFromString("text") + ";\n"
882882
+ " log(doc.getElementById('form1') != null);\n"
883883
+ " log(doc.getElementById('div1') != null);\n"
884-
+ " } catch(e) { log('exception'); }\n"
884+
+ " } catch(e) { log(e.name); }\n"
885885
+ " }\n"
886886
+ LOAD_XML_DOCUMENT_FROM_STRING_FUNCTION
887887
+ "</script></head>\n"
@@ -908,7 +908,7 @@ public void xpathWithNamespaces() throws Exception {
908908
+ " log(doc.evaluate('count(//book)', doc.documentElement, "
909909
+ "null, XPathResult.NUMBER_TYPE, null).numberValue);\n"
910910
+ " } catch (e) {\n"
911-
+ " log('exception');\n"
911+
+ " log(e.name);\n"
912912
+ " }\n"
913913
+ " }\n"
914914
+ " }\n"

src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public void openThrowOnEmptyUrl() throws Exception {
277277
+ " xhr.open('GET', values[i], false);\n"
278278
+ " xhr.send('');\n"
279279
+ " log('pass');\n"
280-
+ " } catch(e) { log('exception') }\n"
280+
+ " } catch(e) { log(e.name) }\n"
281281
+ "}\n"
282282
+ "</script>\n"
283283
+ "</head>\n"
@@ -412,7 +412,7 @@ private void sameOriginPolicy(final String url) throws Exception {
412412
+ " try {\n"
413413
+ " xhr.open('GET', '" + url + "', false);\n"
414414
+ " log('ok');\n"
415-
+ " } catch(e) { log('exception'); }\n"
415+
+ " } catch(e) { log(e.name); }\n"
416416
+ "}\n"
417417
+ "</script>\n"
418418
+ "</head>\n"
@@ -745,7 +745,7 @@ public void sameOriginCorsSimple() throws Exception {
745745
+ " log('ok');\n"
746746
+ " xhr.send();\n"
747747
+ " log(xhr.readyState);\n"
748-
+ " } catch(e) { log('exception'); }\n"
748+
+ " } catch(e) { log(e.name); }\n"
749749
+ "}\n"
750750
+ "</script>\n"
751751
+ "</head>\n"
@@ -780,7 +780,7 @@ public void baseUrlAbsoluteRequest() throws Exception {
780780
+ " log('ok');\n"
781781
+ " xhr.send();\n"
782782
+ " log(xhr.readyState);\n"
783-
+ " } catch(e) { log('exception'); }\n"
783+
+ " } catch(e) { log(e.name); }\n"
784784
+ "}\n"
785785
+ "</script>\n"
786786
+ "</head>\n"
@@ -824,7 +824,7 @@ public void baseUrlAbsoluteRequestOtherUrl() throws Exception {
824824
+ " log('ok');\n"
825825
+ " xhr.send();\n"
826826
+ " log(xhr.readyState);\n"
827-
+ " } catch(e) { log('exception'); }\n"
827+
+ " } catch(e) { log(e.name); }\n"
828828
+ "}\n"
829829
+ "</script>\n"
830830
+ "</head>\n"
@@ -1269,7 +1269,7 @@ private void postRedirect(final int code, final HttpMethod httpMethod,
12691269
+ " try {\n"
12701270
+ " xhr.open('POST', 'redirect.html', false);\n"
12711271
+ " xhr.send('" + content + "');\n"
1272-
+ " } catch(e) { log('exception'); }\n"
1272+
+ " } catch(e) { log(e.name); }\n"
12731273
+ " }\n"
12741274
+ "</script></head>\n"
12751275
+ "<body onload='test()'></body></html>";

src/test/java/org/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void noCorsHeaderCallsErrorHandler() throws Exception {
7373
+ " log(event.total > 0);\n"
7474
+ " };\n"
7575
+ " xhr.send();\n"
76-
+ " } catch(e) { log('exception'); }\n"
76+
+ " } catch(e) { log(e.name); }\n"
7777
+ "}\n"
7878
+ "</script>\n"
7979
+ "</head>\n"
@@ -200,7 +200,7 @@ public void simplePost() throws Exception {
200200
* @throws Exception if the test fails.
201201
*/
202202
@Test
203-
@Alerts("exception")
203+
@Alerts("NetworkError")
204204
public void simplePut() throws Exception {
205205
expandExpectedAlertsVariables(new URL("http://localhost:" + PORT));
206206

@@ -216,7 +216,7 @@ public void simplePut() throws Exception {
216216
+ " log(xhr.readyState);\n"
217217
+ " log(xhr.status);\n"
218218
+ " log(xhr.responseXML.firstChild.firstChild.nodeValue);\n"
219-
+ " } catch(e) { log('exception') }\n"
219+
+ " } catch(e) { log(e.name) }\n"
220220
+ "}\n"
221221
+ "</script>\n"
222222
+ "</head>\n"
@@ -277,7 +277,7 @@ protected void doPut(final HttpServletRequest request, final HttpServletResponse
277277
* @throws Exception if the test fails.
278278
*/
279279
@Test
280-
@Alerts({"exception", "4", "0", ""})
280+
@Alerts({"NetworkError", "4", "0", ""})
281281
public void noAccessControlAllowOrigin() throws Exception {
282282
incorrectAccessControlAllowOrigin(null);
283283
}
@@ -294,7 +294,7 @@ private void incorrectAccessControlAllowOrigin(final String header) throws Excep
294294
+ " var url = 'http://' + window.location.hostname + ':" + PORT2 + "/simple2';\n"
295295
+ " xhr.open('GET', url, false);\n"
296296
+ " xhr.send();\n"
297-
+ " } catch(e) { log('exception') }\n"
297+
+ " } catch(e) { log(e.name) }\n"
298298
+ " log(xhr.readyState);\n"
299299
+ " log(xhr.status);\n"
300300
+ " log(xhr.responseText);\n"
@@ -316,7 +316,7 @@ private void incorrectAccessControlAllowOrigin(final String header) throws Excep
316316
* @throws Exception if the test fails.
317317
*/
318318
@Test
319-
@Alerts({"exception", "4", "0", ""})
319+
@Alerts({"NetworkError", "4", "0", ""})
320320
public void nonMatchingAccessControlAllowOrigin() throws Exception {
321321
incorrectAccessControlAllowOrigin("http://www.sourceforge.net");
322322
}
@@ -535,7 +535,7 @@ protected void doGet(final HttpServletRequest request, final HttpServletResponse
535535
* @throws Exception if the test fails.
536536
*/
537537
@Test
538-
@Alerts({"exception", "4", "0"})
538+
@Alerts({"NetworkError", "4", "0"})
539539
// unstable test case, this will fail on real Chrome if individually run, but will succeed if run with other cases
540540
public void preflight_incorrect_headers() throws Exception {
541541
expandExpectedAlertsVariables(new URL("http://localhost:" + PORT));
@@ -550,7 +550,7 @@ public void preflight_incorrect_headers() throws Exception {
550550
+ " xhr.open('GET', url, false);\n"
551551
+ " xhr.setRequestHeader('X-PINGOTHER', 'pingpong');\n"
552552
+ " xhr.send();\n"
553-
+ " } catch(e) { log('exception') }\n"
553+
+ " } catch(e) { log(e.name) }\n"
554554
+ " log(xhr.readyState);\n"
555555
+ " log(xhr.status);\n"
556556
+ "}\n"
@@ -588,7 +588,7 @@ public void preflight_many_header_values() throws Exception {
588588
+ " xhr.setRequestHeader('X-PING', 'ping');\n"
589589
+ " xhr.setRequestHeader('X-PONG', 'pong');\n"
590590
+ " xhr.send();\n"
591-
+ " } catch(e) { log('exception') }\n"
591+
+ " } catch(e) { log(e.name) }\n"
592592
+ " log(xhr.readyState);\n"
593593
+ " log(xhr.status);\n"
594594
+ " log(xhr.responseXML.firstChild.childNodes[3].tagName);\n"
@@ -856,7 +856,7 @@ private void testWithCredentials(final String accessControlAllowOrigin,
856856
+ " xhr.withCredentials = true;\n"
857857
+ " xhr.onreadystatechange = onReadyStateChange;\n"
858858
+ " xhr.send();\n"
859-
+ " } catch(e) { log('exception') }\n"
859+
+ " } catch(e) { log(e.name) }\n"
860860
+ " log(xhr.readyState);\n"
861861
+ " try {\n"
862862
+ " log(xhr.status);\n"

0 commit comments

Comments
 (0)