Skip to content

Commit

Permalink
more details for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Feb 3, 2025
1 parent 266e078 commit c893a66
Show file tree
Hide file tree
Showing 209 changed files with 1,104 additions and 1,090 deletions.
22 changes: 18 additions & 4 deletions src/test/java/org/htmlunit/WebDriverTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,21 @@
*/
public abstract class WebDriverTestCase extends WebTestCase {

private static final String LOG_EX_FUNCTION =
" function logEx(e) {\n"
+ " let rx = /\\[object (.*)\\]/;\n"
+ " let toStr = Object.prototype.toString.call(e);\n"
+ " let match = rx.exec(toStr);\n"
+ " if (match != null) { toStr = match[1]; }\n"
+ " log(e.name + '/' + toStr);\n"
+ "}\n";

/**
* Function used in many tests.
*/
public static final String LOG_TITLE_FUNCTION =
" function log(msg) { window.document.title += msg + '\\u00a7'; }\n";
" function log(msg) { window.document.title += msg + '\\u00a7'; }\n"
+ LOG_EX_FUNCTION;

/**
* Function used in many tests.
Expand All @@ -162,13 +172,16 @@ public abstract class WebDriverTestCase extends WebTestCase {
+ "msg = msg.replace(/\\r/g, '\\\\r'); "
+ "msg = msg.replace(/\\t/g, '\\\\t'); "
+ "msg = msg.replace(/\\u001e/g, '\\\\u001e'); "
+ "window.document.title += msg + '\u00A7';}\n";
+ "window.document.title += msg + '\u00A7';}\n"

+ LOG_EX_FUNCTION;

/**
* Function used in many tests.
*/
public static final String LOG_WINDOW_NAME_FUNCTION =
" function log(msg) { window.top.name += msg + '\\u00a7'; }\n window.top.name = '';";
" function log(msg) { window.top.name += msg + '\\u00a7'; }\n window.top.name = '';"
+ LOG_EX_FUNCTION;

/**
* Function used in many tests.
Expand All @@ -182,7 +195,8 @@ public abstract class WebDriverTestCase extends WebTestCase {
* Function used in many tests.
*/
public static final String LOG_TEXTAREA_FUNCTION = " function log(msg) { "
+ "document.getElementById('myLog').value += msg + '\u00A7';}\n";
+ "document.getElementById('myLog').value += msg + '\u00A7';}\n"
+ LOG_EX_FUNCTION;

/**
* HtmlSniped to insert text area used for logging.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void test(final String className) throws Exception {
+ " log('' + e.data);\n"
+ " };\n"
+ " setTimeout(function() { myWorker.postMessage('test');}, 10);\n"
+ "} catch(e) { log(e.name); }\n"
+ "} catch(e) { logEx(e); }\n"
+ "</script></body></html>\n";

final String workerJs = "onmessage = function(e) {\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void test(final String className) throws Exception {
+ " log('' + e.data);\n"
+ " };\n"
+ " setTimeout(function() { myWorker.postMessage('test');}, 10);\n"
+ "} catch(e) { log(e.name); }\n"
+ "} catch(e) { logEx(e); }\n"
+ "</script></body></html>\n";

final String workerJs = "onmessage = function(e) {\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void test(final String tagName) throws Exception {
+ " var e = document.getElementById('outer');\n"
+ " try {\n"
+ " log(e == null ? e : e.children.length);\n"
+ " } catch(e) { log(e.name); }"
+ " } catch(e) { logEx(e); }"
+ "}\n"
+ "</script>\n"
+ "</head><body onload='test()'>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void testString(final String preparation, final String string) throws Ex
+ " try{\n"
+ " " + preparation + "\n"
+ " process(" + string + ");\n"
+ " } catch (e) {log(e.name); return;}\n"
+ " } catch (e) {logEx(e); return;}\n"
+ " }\n"
+ "\n"
+ " /*\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void testString(final String preparation, final String string) throws Ex
+ " try{\n"
+ " " + preparation + "\n"
+ " process(" + string + ");\n"
+ " } catch (e) {log(e.name);return;}\n"
+ " } catch (e) {logEx(e);return;}\n"
+ " }\n"
+ "\n"
+ " /*\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void testString(final String preparation, final String string) throws Ex
+ " try{\n"
+ " " + preparation + "\n"
+ " process(" + string + ");\n"
+ " } catch (e) {log(e.name);return;}\n"
+ " } catch (e) {logEx(e);return;}\n"
+ " }\n"
+ "\n"
+ " /*\n"
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/htmlunit/general/HostClassNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void test(final String className) throws Exception {
// normalize FF output
+ " clsName = clsName.replace('{\\n [native code]\\n}', '{ [native code] }');\n"
+ " log(clsName);\n"
+ " } catch(e) {log(e.name)}\n"
+ " } catch(e) {logEx(e)}\n"
+ " }\n"
+ "</script></head>\n"
+ "<body onload='test()'>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void test(final String className) throws Exception {

+ " try {\n"
+ " log(new " + className + "());\n"
+ " } catch(e) {log(e.name)}\n"
+ " } catch(e) {logEx(e)}\n"
+ "</script>\n"
+ "</body></html>";

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/htmlunit/general/HostTypeOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void test(final String className) throws Exception {
+ " function test() {\n"
+ " try {\n"
+ " log(typeof " + className + ");\n"
+ " } catch(e) {log(e.name)}\n"
+ " } catch(e) {logEx(e)}\n"
+ " }\n"
+ "</script></head><body onload='test()'>\n"
+ "</body></html>";
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/htmlunit/html/DomNode2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void appendChild_recursive() throws Exception {
+ " var e = document.createElement('div');\n"
+ " try {\n"
+ " log(e.appendChild(e) === e);\n"
+ " } catch(e) {log(e.name);}\n"
+ " } catch(e) {logEx(e);}\n"
+ " log(e.childNodes.length);\n"
+ "}\n"
+ "</script>\n"
Expand All @@ -72,7 +72,7 @@ public void appendChild_recursive_parent() throws Exception {
+ " try {\n"
+ " log(e1.appendChild(e2) === e2);\n"
+ " log(e2.appendChild(e1) === e1);\n"
+ " } catch(e) {log(e.name);}\n"
+ " } catch(e) {logEx(e);}\n"
+ " log(e1.childNodes.length);\n"
+ " log(e2.childNodes.length);\n"
+ "}\n"
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/htmlunit/html/HtmlColorInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void defaultValues() throws Exception {
+ " input = document.createElement('input');\n"
+ " input.type = 'color';\n"
+ " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " var builder = document.createElement('div');\n"
+ " builder.innerHTML = '<input type=\"color\">';\n"
Expand Down Expand Up @@ -85,7 +85,7 @@ public void defaultValuesAfterClone() throws Exception {
+ " input.type = 'color';\n"
+ " input = input.cloneNode(false);\n"
+ " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " var builder = document.createElement('div');\n"
+ " builder.innerHTML = '<input type=\"color\">';\n"
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/htmlunit/html/HtmlDateInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void defaultValues() throws Exception {
+ " input = document.createElement('input');\n"
+ " input.type = 'date';\n"
+ " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " var builder = document.createElement('div');\n"
+ " builder.innerHTML = '<input type=\"date\">';\n"
Expand Down Expand Up @@ -87,7 +87,7 @@ public void defaultValuesAfterClone() throws Exception {
+ " input.type = 'date';\n"
+ " input = input.cloneNode(false);\n"
+ " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " var builder = document.createElement('div');\n"
+ " builder.innerHTML = '<input type=\"date\">';\n"
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/htmlunit/html/HtmlDateTimeInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void defaultValues() throws Exception {
+ " input = document.createElement('input');\n"
+ " input.type = 'datetime';\n"
+ " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " var builder = document.createElement('div');\n"
+ " builder.innerHTML = '<input type=\"datetime\">';\n"
Expand Down Expand Up @@ -86,7 +86,7 @@ public void defaultValuesAfterClone() throws Exception {
+ " input.type = 'datetime';\n"
+ " input = input.cloneNode(false);\n"
+ " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " var builder = document.createElement('div');\n"
+ " builder.innerHTML = '<input type=\"datetime\">';\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void defaultValues() throws Exception {
+ " input = document.createElement('input');\n"
+ " input.type = 'datetime-local';\n"
+ " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " var builder = document.createElement('div');\n"
+ " builder.innerHTML = '<input type=\"datetime-local\">';\n"
Expand Down Expand Up @@ -86,7 +86,7 @@ public void defaultValuesAfterClone() throws Exception {
+ " input.type = 'datetime-local';\n"
+ " input = input.cloneNode(false);\n"
+ " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " var builder = document.createElement('div');\n"
+ " builder.innerHTML = '<input type=\"datetime-local\">';\n"
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/htmlunit/html/HtmlEmailInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void defaultValues() throws Exception {
+ " input = document.createElement('input');\n"
+ " input.type = 'email';\n"
+ " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " var builder = document.createElement('div');\n"
+ " builder.innerHTML = '<input type=\"email\">';\n"
Expand Down Expand Up @@ -88,7 +88,7 @@ public void defaultValuesAfterClone() throws Exception {
+ " input.type = 'email';\n"
+ " input = input.cloneNode(false);\n"
+ " log(input.value + '-' + input.defaultValue + '-' + input.getAttribute('value'));\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " var builder = document.createElement('div');\n"
+ " builder.innerHTML = '<input type=\"email\">';\n"
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/htmlunit/html/HtmlFieldSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void align() throws Exception {
+ " function set(fs, value) {\n"
+ " try {\n"
+ " fs.align = value;\n"
+ " } catch (e) { log(e.name) }\n"
+ " } catch (e) { logEx(e) }\n"
+ " }\n"
+ " var fs1 = document.getElementById('fs1');\n"
+ " var fs2 = document.getElementById('fs2');\n"
Expand Down
32 changes: 16 additions & 16 deletions src/test/java/org/htmlunit/html/HtmlFileInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ public void setValueOnChange() throws Exception {
+ " var input = document.getElementById('f');\n"
+ " try{\n"
+ " input.value = 'HtmlUnit';\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " log(input.value + '-' + input.defaultValue "
+ "+ '-' + input.getAttribute('value') "
+ "+ '-' + input.files.length);\n"

+ " try{\n"
+ " input.value = '';\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " log(input.value + '-' + input.defaultValue "
+ "+ '-' + input.getAttribute('value') "
+ "+ '-' + input.files.length);\n"
Expand Down Expand Up @@ -234,14 +234,14 @@ public void setDefaultValueOnChange() throws Exception {
+ " var input = document.getElementById('f');\n"
+ " try{\n"
+ " input.defaultValue = 'HtmlUnit';\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " log(input.value + '-' + input.defaultValue "
+ "+ '-' + input.getAttribute('value') "
+ "+ '-' + input.files.length);\n"

+ " try{\n"
+ " input.defaultValue = '';\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " log(input.value + '-' + input.defaultValue "
+ "+ '-' + input.getAttribute('value') "
+ "+ '-' + input.files.length);\n"
Expand Down Expand Up @@ -351,7 +351,7 @@ public void resetByClick() throws Exception {

+ " try{\n"
+ " file.value = 'newValue';\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " log(file.value + '-' + file.defaultValue + '-' + file.getAttribute('value'));\n"

+ " document.getElementById('testReset').click;\n"
Expand Down Expand Up @@ -394,7 +394,7 @@ public void resetByJS() throws Exception {

+ " try{\n"
+ " file.value = 'newValue';\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " log(file.value + '-' + file.defaultValue + '-' + file.getAttribute('value'));\n"

+ " document.forms[0].reset;\n"
Expand Down Expand Up @@ -436,7 +436,7 @@ public void value() throws Exception {

+ " try{\n"
+ " file.value = 'newValue';\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " log(file.value + '-' + file.defaultValue + '-' + file.getAttribute('value'));\n"

+ " file.setAttribute('value', 'attribValue');\n"
Expand Down Expand Up @@ -506,7 +506,7 @@ public void selection() throws Exception {
+ " } catch(e) { log('ex end'); }\n"
+ " try {\n"
+ " return element.value.substring(element.selectionStart, element.selectionEnd);\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " }\n"
+ "</script></head>\n"
+ "<body onload='test()'>\n"
Expand Down Expand Up @@ -558,28 +558,28 @@ private void selection2(final int selectionStart, final int selectionEnd) throws

+ " try {\n"
+ " log(input.selectionStart + ',' + input.selectionEnd);\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " try{\n"
+ " input.value = '12345678900';\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " try {\n"
+ " log(input.selectionStart + ',' + input.selectionEnd);\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " try {\n"
+ " input.selectionStart = " + selectionStart + ";\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " try {\n"
+ " log(input.selectionStart + ',' + input.selectionEnd);\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"

+ " try {\n"
+ " input.selectionEnd = " + selectionEnd + ";\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ " try {\n"
+ " log(input.selectionStart + ',' + input.selectionEnd);\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ "</script>\n"
+ "</body>\n"
+ "</html>";
Expand Down Expand Up @@ -617,7 +617,7 @@ public void selectionOnUpdate() throws Exception {

+ " input.value = 'a';\n"
+ " log(input.selectionStart + ',' + input.selectionEnd);\n"
+ " } catch(e) { log(e.name); }\n"
+ " } catch(e) { logEx(e); }\n"
+ "</script>\n"
+ "</body>\n"
+ "</html>";
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/htmlunit/html/HtmlForm2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ public void asFunction() throws Exception {
+ LOG_TITLE_FUNCTION
+ "function test() {\n"
+ " var f1 = document.forms[0];\n"
+ " try { log(f1('textfieldid').id) } catch (e) { log(e.name) }\n"
+ " try { log(f1('textfieldname').name) } catch (e) { log(e.name) }\n"
+ " try { log(f1(0).id) } catch (e) { log(e.name) }\n"
+ " try { log(f1('textfieldid').id) } catch (e) { logEx(e) }\n"
+ " try { log(f1('textfieldname').name) } catch (e) { logEx(e) }\n"
+ " try { log(f1(0).id) } catch (e) { logEx(e) }\n"
+ "}\n"
+ "</script></head><body onload='test()'>\n"
+ "<p>hello world</p>\n"
Expand All @@ -159,10 +159,10 @@ public void asFunctionFormsFunction() throws Exception {
+ "function test() {\n"
+ " try {\n"
+ " var f1 = document.forms(0);\n"
+ " try { log(f1('textfieldid').id) } catch (e) { log(e.name) }\n"
+ " try { log(f1('textfieldname').name) } catch (e) { log(e.name) }\n"
+ " try { log(f1(0).id) } catch (e) { log(e.name) }\n"
+ " } catch (e) { log(e.name) }\n"
+ " try { log(f1('textfieldid').id) } catch (e) { logEx(e) }\n"
+ " try { log(f1('textfieldname').name) } catch (e) { logEx(e) }\n"
+ " try { log(f1(0).id) } catch (e) { logEx(e) }\n"
+ " } catch (e) { logEx(e) }\n"
+ "}\n"
+ "</script></head><body onload='test()'>\n"
+ "<p>hello world</p>\n"
Expand Down
Loading

0 comments on commit c893a66

Please sign in to comment.