Skip to content

Commit 85ed8b1

Browse files
committed
improve tests
1 parent 736d2b8 commit 85ed8b1

File tree

2 files changed

+51
-47
lines changed

2 files changed

+51
-47
lines changed

src/test/java/org/htmlunit/html/HtmlPage3Test.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,4 +637,54 @@ public void onLoadHandler_idChange() throws Exception {
637637

638638
loadPageVerifyTitle2(html);
639639
}
640+
641+
/**
642+
* Tests getElementById() of child element after appendChild(), removeChild(), then appendChild()
643+
* of the parent element.
644+
*
645+
* @throws Exception if the test fails
646+
*/
647+
@Test
648+
@Alerts("[object HTMLTableRowElement]")
649+
public void getElementById_AfterAppendRemoveAppendChild() throws Exception {
650+
final String content = "<html><head>\n"
651+
+ "<script>\n"
652+
+ LOG_TITLE_FUNCTION
653+
+ " function test() {\n"
654+
+ " var table = document.createElement('table');\n"
655+
+ " var tr = document.createElement('tr');\n"
656+
+ " tr.id = 'myTR';\n"
657+
+ " table.appendChild(tr);\n"
658+
+ " document.body.appendChild(table);\n"
659+
+ " document.body.removeChild(table);\n"
660+
+ " document.body.appendChild(table);\n"
661+
+ " log(document.getElementById('myTR'));\n"
662+
+ " }\n"
663+
+ "</script></head>\n"
664+
+ "<body onload='test()'>\n"
665+
+ "</body></html>";
666+
loadPageVerifyTitle2(content);
667+
}
668+
669+
/**
670+
* @throws Exception if the test fails
671+
*/
672+
@Test
673+
@Alerts("null")
674+
public void getElementById_AfterAppendingToNewlyCreatedElement() throws Exception {
675+
final String content = "<html><head>\n"
676+
+ "<script>\n"
677+
+ LOG_TITLE_FUNCTION
678+
+ " function test() {\n"
679+
+ " var table = document.createElement('table');\n"
680+
+ " var tr = document.createElement('tr');\n"
681+
+ " tr.id = 'myTR';\n"
682+
+ " table.appendChild(tr);\n"
683+
+ " log(document.getElementById('myTR'));\n"
684+
+ " }\n"
685+
+ "</script></head>\n"
686+
+ "<body onload='test()'>\n"
687+
+ "</body></html>";
688+
loadPageVerifyTitle2(content);
689+
}
640690
}

src/test/java/org/htmlunit/html/HtmlPageTest.java

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,52 +1748,6 @@ public void title_EmptyXmlTagExpanded() throws Exception {
17481748
assertTrue(page.asXml().indexOf("</title>") != -1);
17491749
}
17501750

1751-
/**
1752-
* Tests getElementById() of child element after appendChild(), removeChild(), then appendChild()
1753-
* of the parent element.
1754-
*
1755-
* @throws Exception if the test fails
1756-
*/
1757-
@Test
1758-
public void getElementById_AfterAppendRemoveAppendChild() throws Exception {
1759-
final String content = "<html><head><title>foo</title><script>\n"
1760-
+ " function test() {\n"
1761-
+ " var table = document.createElement('table');\n"
1762-
+ " var tr = document.createElement('tr');\n"
1763-
+ " tr.id = 'myTR';\n"
1764-
+ " table.appendChild(tr);\n"
1765-
+ " document.body.appendChild(table);\n"
1766-
+ " document.body.removeChild(table);\n"
1767-
+ " document.body.appendChild(table);\n"
1768-
+ " alert(document.getElementById('myTR'));\n"
1769-
+ " }\n"
1770-
+ "</script></head><body onload='test()'>\n"
1771-
+ "</body></html>";
1772-
final List<String> collectedAlerts = new ArrayList<>();
1773-
loadPage(content, collectedAlerts);
1774-
assertFalse("null".equals(collectedAlerts.get(0)));
1775-
}
1776-
1777-
/**
1778-
* @throws Exception if the test fails
1779-
*/
1780-
@Test
1781-
public void getElementById_AfterAppendingToNewlyCreatedElement() throws Exception {
1782-
final String content = "<html><head><title>foo</title><script>\n"
1783-
+ " function test() {\n"
1784-
+ " var table = document.createElement('table');\n"
1785-
+ " var tr = document.createElement('tr');\n"
1786-
+ " tr.id = 'myTR';\n"
1787-
+ " table.appendChild(tr);\n"
1788-
+ " alert(document.getElementById('myTR'));\n"
1789-
+ " }\n"
1790-
+ "</script></head><body onload='test()'>\n"
1791-
+ "</body></html>";
1792-
final List<String> collectedAlerts = new ArrayList<>();
1793-
loadPage(content, collectedAlerts);
1794-
assertTrue("null".equals(collectedAlerts.get(0)));
1795-
}
1796-
17971751
/**
17981752
* @throws Exception if the test fails
17991753
*/
@@ -1905,7 +1859,7 @@ public void asNormalizedText() throws Exception {
19051859
+ "</table></body></html>";
19061860

19071861
final HtmlPage page = loadPage(htmlContent);
1908-
page.asNormalizedText();
1862+
assertEquals("test\na", page.asNormalizedText());
19091863
}
19101864

19111865
/**

0 commit comments

Comments
 (0)