Skip to content

Commit

Permalink
test for the correct error
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Feb 7, 2025
1 parent c8c1e17 commit ced83a1
Show file tree
Hide file tree
Showing 21 changed files with 38 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Crypto() {
*/
@JsxConstructor
public void jsConstructor() {
throw JavaScriptEngine.reportRuntimeError("Illegal constructor.");
throw JavaScriptEngine.typeError("Illegal constructor.");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SubtleCrypto extends HtmlUnitScriptable {
*/
@JsxConstructor
public void jsConstructor() {
throw JavaScriptEngine.reportRuntimeError("Illegal constructor.");
throw JavaScriptEngine.typeError("Illegal constructor.");
}

private NativePromise notImplemented() {
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/org/htmlunit/html/HtmlHeading2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ public void setAlign() throws Exception {
+ " function setAlign(elem, value) {\n"
+ " try {\n"
+ " elem.align = value;\n"
+ " } catch(e) {\n"
+ " log('error');\n"
+ " }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"

+ " var elem = document.getElementById('e1');\n"
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/htmlunit/html/HtmlInput3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ private void changeType(final String inputAttribs, final String value, final Str
+ " try {\n"
+ " input.type = '" + targetType + "';\n"
+ " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
+ " } catch(e) { log('error'); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"
+ "</script>\n"
+ "</head><body onload='test()'>\n"
Expand Down Expand Up @@ -677,7 +677,7 @@ private void changeTypeDetached(final String value, final String targetType) thr
+ " try {\n"
+ " input.type = '" + targetType + "';\n"
+ " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
+ " } catch(e) { log('error'); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"
+ "</script>\n"
+ "</head><body onload='test()'>\n"
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/org/htmlunit/html/HtmlOutputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public void align() throws Exception {
+ " function set(fs, value) {\n"
+ " try {\n"
+ " fs.align = value;\n"
+ " } catch(e) {\n"
+ " log('error');\n"
+ " }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"
+ " var o1 = document.getElementById('o1');\n"
+ " var o2 = document.getElementById('o2');\n"
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/htmlunit/html/HtmlScript2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ public void addEventListener_NoContent() throws Exception {
+ " function test() {\n"
+ " var s1 = document.createElement('script');\n"
+ " s1.src = '" + scriptUrl + "';\n"
+ " s1.addEventListener('load', function() {log('load')}, false);\n"
+ " s1.addEventListener('error', function() {log('error')}, false);\n"
+ " s1.addEventListener('load', function() { log('load'); }, false);\n"
+ " s1.addEventListener('error', function() { logEx(e); }, false);\n"
+ " document.body.insertBefore(s1, document.body.firstChild);\n"
+ " }\n"
+ "</script>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ public void decode2() throws Exception {
* @throws Exception on test failure
*/
@Test
@Alerts("ex")
@Alerts("RangeError")
public void decodeReplacement() throws Exception {
final String html = "<html>\n"
+ "<head>\n"
Expand All @@ -740,7 +740,7 @@ public void decodeReplacement() throws Exception {
+ " function doTest() {\n"
+ " try {\n"
+ " var dec = new TextDecoder('iso-2022-kr');\n"
+ " } catch(e) { log('ex'); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"
+ " </script>\n"
+ "</head>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void ctorLengthZero() throws Exception {
* @throws Exception if the test fails
*/
@Test
@Alerts("exception true")
@Alerts("RangeError")
public void ctorLengthNegative() throws Exception {
final String html
= "<html><head>\n"
Expand All @@ -64,7 +64,7 @@ public void ctorLengthNegative() throws Exception {
+ " try {\n"
+ " var buff = new ArrayBuffer(-1);\n"
+ " log(buff.byteLength);\n"
+ " } catch(e) { log('exception ' + (e instanceof RangeError)); }"
+ " } catch(e) { logEx(e); }"
+ "}\n"
+ "</script></head><body onload='test()'>\n"
+ "</body></html>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CryptoTest extends WebDriverTestCase {
* @throws Exception if the test fails
*/
@Test
@Alerts({"function", "error"})
@Alerts({"function", "TypeError"})
public void ctor() throws Exception {
final String html
= "<html>\n"
Expand All @@ -46,7 +46,7 @@ public void ctor() throws Exception {
+ " try {\n"
+ " log(typeof Crypto);\n"
+ " new Crypto();\n"
+ " } catch(e) { log('error'); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"
+ " </script>\n"
+ "</head>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SubtleCryptoTest extends WebDriverTestCase {
* @throws Exception if the test fails
*/
@Test
@Alerts({"function", "error"})
@Alerts({"function", "TypeError"})
public void ctor() throws Exception {
final String html
= "<html>\n"
Expand All @@ -48,7 +48,7 @@ public void ctor() throws Exception {
+ " try {\n"
+ " log(typeof SubtleCrypto);\n"
+ " new SubtleCrypto();\n"
+ " } catch(e) { log('error'); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"
+ " </script>\n"
+ "</head>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,7 @@ public void insertRuleWithIndexNull() throws Exception {
+ " log(rules.item(i).cssText);\n"
+ " log(rules.item(i).parentRule);\n"
+ " }\n"
+ " } catch(e) {\n"
+ " log('exception'+e);\n"
+ " }\n"
+ " } catch(e) { logEx(e); }\n"
+ "</script>\n"

+ "</body></html>";
Expand Down Expand Up @@ -855,9 +853,7 @@ public void insertRuleWithIndexNaN() throws Exception {
+ " log(rules.item(i).cssText);\n"
+ " log(rules.item(i).parentRule);\n"
+ " }\n"
+ " } catch(e) {\n"
+ " log('exception'+e);\n"
+ " }\n"
+ " } catch(e) { logEx(e); }\n"
+ "</script>\n"

+ "</body></html>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,7 @@ public void escapedId() throws Exception {

+ " log(document.querySelectorAll('#silly\\\\~id')[0].id);\n"
+ " log(document.querySelectorAll(\"#silly\\\\~id\")[0].id);\n"
+ "} catch(e) {log('exception ' + e)}\n"
+ "} catch(e) { logEx(e); }\n"
+ "</script></body></html>";

loadPageVerifyTitle2(html);
Expand Down Expand Up @@ -2453,7 +2453,7 @@ public void xmlTagName() throws Exception {

+ " res = de.querySelectorAll('rEsulT');\n"
+ " log(res.length);\n"
+ " } catch(e) {log('exception ' + e)}\n"
+ " } catch(e) { logEx(e); }\n"
+ "</script></body></html>";

loadPageVerifyTitle2(html);
Expand Down Expand Up @@ -2507,7 +2507,7 @@ public void xmlAttribute() throws Exception {
+ " log(res.length);\n"
+ " log(res[0].innerHTML);\n"

+ " } catch(e) {log('exception ' + e)}\n"
+ " } catch(e) { logEx(e); }\n"
+ "</script></body></html>";

loadPageVerifyTitle2(html);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3522,7 +3522,7 @@ public void widthAbsolute() throws Exception {
* @throws Exception if an error occurs
*/
@Test
@Alerts("exception true")
@Alerts("TypeError")
public void ctor() throws Exception {
final String html =
"<html>\n"
Expand All @@ -3536,9 +3536,7 @@ public void ctor() throws Exception {
+ " try {"
+ " var c = new CSSStyleDeclaration();\n"
+ " log(c);\n"
+ " } catch(e) {\n"
+ " log('exception ' + (e instanceof TypeError));\n"
+ " }\n"
+ " } catch(e) { logEx(e); }\n"
+ " </script>\n"
+ "</body></html>";

Expand Down Expand Up @@ -3573,9 +3571,7 @@ public void item() throws Exception {
+ " try {\n"
+ " log(decl.item(-1));\n"
+ " log(typeof decl.item(-1));\n"
+ " } catch(e) {\n"
+ " log('exception ');\n"
+ " }\n"
+ " } catch(e) { logEx(e); }\n"
+ "</script>\n"

+ "</body></html>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,15 @@ public void arrayIndexOutOfBoundAccess() throws Exception {

+ " try {\n"
+ " log(document.styleSheets[0]);\n"
+ " }\n"
+ " catch(e) {\n"
+ " log('exception for 0');\n"
+ " }\n"
+ " } catch(e) { logEx(e); }\n"

+ " try {\n"
+ " log(document.styleSheets[46]);\n"
+ " }\n"
+ " catch(e) {\n"
+ " log('exception for 46');\n"
+ " }\n"
+ " } catch(e) { logEx(e); }\n"

+ " try {\n"
+ " log(document.styleSheets[-2]);\n"
+ " }\n"
+ " catch(e) {\n"
+ " log('exception for -2');\n"
+ " }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"
+ " </script>\n"
+ " </head>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void prototype() throws Exception {
+ " function test() {\n"
+ " try {\n"
+ " log(typeof AbstractRange === 'function');\n"
+ " } catch(e) { log('exception' + e) }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"
+ "</script></head><body onload='test()'>\n"
+ "</body></html>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ public void queryCommandEnabled() throws Exception {
+ LOG_TITLE_FUNCTION
+ "function x() {\n"
+ " var d = window.frames['f'].document;\n"
+ " try { log(d.queryCommandEnabled('SelectAll')); } catch(e) { log('error'); }\n"
+ " try { log(d.queryCommandEnabled('sElectaLL')); } catch(e) { log('error'); }\n"
+ " try { log(d.queryCommandEnabled('SelectAll')); } catch(e) { logEx(e); }\n"
+ " try { log(d.queryCommandEnabled('sElectaLL')); } catch(e) { logEx(e); }\n"
+ "}\n"
+ "</script></body></html>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ public void getElementsByTagNameXml() throws Exception {

+ " res = xmlDoc.getElementsByTagName('rEsulT');\n"
+ " log(res.length);\n"
+ " } catch(e) {log('exception ' + e)}\n"
+ " } catch(e) { logEx(e); }\n"
+ "</script></body></html>";

loadPageVerifyTitle2(html);
Expand Down
8 changes: 2 additions & 6 deletions src/test/java/org/htmlunit/javascript/host/dom/NodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,7 @@ public void replaceChild() throws Exception {
+ " log(parent.innerHTML);\n"
+ " log(parent.replaceChild(fragment, parent.firstChild).id);\n"
+ " log(parent.innerHTML);\n"
+ " } catch(e) {\n"
+ " log('exception thrown');\n"
+ " }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"
+ "</script></head><body onload='test()'>\n"
+ " <div id='myDiv'><div id='myDiv2'></div><div id='myDiv3'></div></div>\n"
Expand Down Expand Up @@ -612,9 +610,7 @@ public void replaceChild_EmptyDocumentFragment() throws Exception {
+ " log(parent.innerHTML);\n"
+ " log(parent.replaceChild(fragment, parent.firstChild).id);\n"
+ " log(parent.innerHTML);\n"
+ " } catch(e) {\n"
+ " log('exception thrown');\n"
+ " }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"
+ "</script></head><body onload='test()'>\n"
+ " <div id='myDiv'><div id='myDiv2'></div><div id='myDiv3'></div></div>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class XPathResultTest extends WebDriverTestCase {
* @throws Exception if the test fails
*/
@Test
@Alerts({"function", "error"})
@Alerts({"function", "TypeError"})
public void ctor() throws Exception {
final String html
= "<html>\n"
Expand All @@ -52,7 +52,7 @@ public void ctor() throws Exception {
+ " try {\n"
+ " log(typeof XPathResult);\n"
+ " new XPathResult();\n"
+ " } catch(e) { log('error'); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"
+ " </script>\n"
+ "</head>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,7 @@ public void addEventListener_HandlerNull() throws Exception {
+ LOG_TITLE_FUNCTION
+ "try {\n"
+ " window.addEventListener('mousedown', null, true);\n"
+ "} catch (err) {\n"
+ " log('error');\n"
+ "}\n"
+ "} catch(e) { logEx(e); }\n"
+ "</script>\n"
+ "</body></html>";
loadPageVerifyTitle2(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ public void initHashChangeEvent() throws Exception {
+ " try {\n"
+ " var event = document.createEvent('HashChangeEvent');\n"
+ " log(event);\n"
+ " } catch(e) { log('exception createEvent'); return; }\n"
+ " } catch(e) { log('exception createEvent'); logEx(e); return; }\n"

+ " if (!event.initHashChangeEvent) {log('missing initHashChangeEvent'); return;}\n"

+ " try {\n"
+ " event.initHashChangeEvent('hashchange', true, false, '" + URL_FIRST + "', '"
+ URL_FIRST + "#1');\n"
+ " dump(event);\n"
+ " } catch(e) { log('exception initHashChangeEvent') }\n"
+ " } catch(e) { log('exception initHashChangeEvent'); logEx(e); }\n"
+ " }\n"
+ DUMP_EVENT_FUNCTION
+ "</script></head><body onload='test()'>\n"
Expand Down

0 comments on commit ced83a1

Please sign in to comment.