Skip to content

Commit

Permalink
adapt last neko changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jan 3, 2024
1 parent eadfafb commit 2edd006
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 34 deletions.
6 changes: 6 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<action type="fix" dev="rbri">
SymbolConstants are readonly.
</action>
<action type="fix" dev="rbri">
neko: frameset tags ignored in some more cases, handling of text before the frameset also fixed.
</action>
<action type="fix" dev="rbri">
neko: frameset tags closing the head.
</action>
<action type="fix" dev="rbri">
WebClientOptions.setMaxInMemory(int) should not create temp files if the limit is set to something &lt;= 0.
</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ public void startEntity(final String name) {
public void ignoredEndElement(final QName element, final Augmentations augs) {
// HTMLTagBalancer brings us here if </form> was found in the source on a different
// DOM tree depth (either above or below) to the <form> that started it
if ("form".equals(element.localpart) && consumingForm_ != null) {
if ("form".equals(element.getLocalpart()) && consumingForm_ != null) {
consumingForm_ = null;

if (findElementOnStack("table", "form") instanceof HtmlTable) {
Expand Down Expand Up @@ -794,7 +794,7 @@ public void ignoredStartElement(final QName elem, final XMLAttributes attrs, fin
// when multiple html/body elements are encountered, the attributes of the discarded
// elements are used when not previously defined
if (attrs != null && body_ != null) {
String lp = elem.localpart;
String lp = elem.getLocalpart();
if (lp != null && lp.length() == 4) {
lp = lp.toLowerCase(Locale.ROOT);
if ("body".equals(lp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ public void parseFragment(final DomNode parent, final DomNode context, final Str
ancestors.add(0, new QName(null, node.getNodeName(), null, null));
node = node.getParentNode();
}
if (ancestors.isEmpty() || !"html".equals(ancestors.get(0).localpart)) {
if (ancestors.isEmpty() || !"html".equals(ancestors.get(0).getLocalpart())) {
ancestors.add(0, new QName(null, "html", null, null));
}
if (ancestors.size() == 1 || !"body".equals(ancestors.get(1).localpart)) {
if (ancestors.size() == 1 || !"body".equals(ancestors.get(1).getLocalpart())) {
ancestors.add(1, new QName(null, "body", null, null));
}

Expand Down
202 changes: 172 additions & 30 deletions src/test/java/org/htmlunit/html/parser/MalformedHtmlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.htmlunit.junit.BrowserRunner;
import org.htmlunit.junit.BrowserRunner.Alerts;
import org.htmlunit.junit.BrowserRunner.HtmlUnitNYI;
import org.htmlunit.junit.BrowserRunner.NotYetImplemented;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
Expand Down Expand Up @@ -363,7 +362,27 @@ public void sectionWithUnknownClosingTag() throws Exception {
"outerA", "BODY:null", "1", "#text:V", "true", "false",
"outerA", "DIV:null", "1", "#text:W", "false", "false",
"innerA", "DIV:null", "1", "#text:X", "false", "true"})
@NotYetImplemented
@HtmlUnitNYI(
CHROME = {"4", "#text:\\n\\s\\s", "A:null", "A:null", "#text:YZ\\n\\n",
"2", "innerDiv", "A:null", "1", "#text:W", "exception",
"outerA", "BODY:null", "2", "#text:V", "true", "false",
"innerA", "BODY:null", "1", "#text:X", "false", "true", "exception"},
EDGE = {"4", "#text:\\n\\s\\s", "A:null", "A:null", "#text:YZ\\n\\n",
"2", "innerDiv", "A:null", "1", "#text:W", "exception",
"outerA", "BODY:null", "2", "#text:V", "true", "false",
"innerA", "BODY:null", "1", "#text:X", "false", "true", "exception"},
FF = {"4", "#text:\\n\\s\\s", "A:null", "A:null", "#text:YZ\\n\\n",
"2", "innerDiv", "A:null", "1", "#text:W", "exception",
"outerA", "BODY:null", "2", "#text:V", "true", "false",
"innerA", "BODY:null", "1", "#text:X", "false", "true", "exception"},
FF_ESR = {"4", "#text:\\n\\s\\s", "A:null", "A:null", "#text:YZ\\n\\n",
"2", "innerDiv", "A:null", "1", "#text:W", "exception",
"outerA", "BODY:null", "2", "#text:V", "true", "false",
"innerA", "BODY:null", "1", "#text:X", "false", "true", "exception"},
IE = {"4", "#text:\\n\\s\\s", "A:null", "A:null", "#text:YZ\\n\\n",
"2", "innerDiv", "A:null", "1", "#text:W", "exception",
"outerA", "BODY:null", "2", "#text:V", "true", "false",
"innerA", "BODY:null", "1", "#text:X", "false", "true", "exception"})
// Input:
// <a id="outerA">V<div id="innerDiv">W<a id="innerA">X</a>Y</div>Z</a>
// CHROME and IE generate:
Expand Down Expand Up @@ -1093,10 +1112,15 @@ public void synthesizedDivInForm() throws Exception {
* @throws Exception if an error occurs
*/
@Test
@Alerts("frame loaded")
@Alerts({"frame loaded", "1", "0"})
@HtmlUnitNYI(CHROME = {"", "0", "1"},
EDGE = {"", "0", "1"},
FF = {"", "0", "1"},
FF_ESR = {"", "0", "1"},
IE = {"", "0", "1"})
public void siblingWithoutContentBeforeFrameset() throws Exception {
final String html = "<html>\n"
+ "<div><span></span></div>\n"
+ "<div id='div1'><span></span></div>\n"
+ "<frameset>\n"
+ " <frame name='main' src='" + URL_SECOND + "' />\n"
+ "</frameset>\n"
Expand All @@ -1109,18 +1133,26 @@ public void siblingWithoutContentBeforeFrameset() throws Exception {
+ "</body></html>";

getMockWebConnection().setResponse(URL_SECOND, html2);
final WebDriver webDriver = loadPageWithAlerts2(html);
assertEquals(1, webDriver.findElements(By.name("main")).size());

final WebDriver webDriver = loadPage2(html);
assertEquals(getExpectedAlerts()[0], String.join("§", getCollectedAlerts(webDriver)));
assertEquals(Integer.parseInt(getExpectedAlerts()[1]), webDriver.findElements(By.name("main")).size());
assertEquals(Integer.parseInt(getExpectedAlerts()[2]), webDriver.findElements(By.id("div1")).size());
}

/**
* @throws Exception if an error occurs
*/
@Test
@Alerts("frame loaded")
@Alerts({"frame loaded", "1", "0"})
@HtmlUnitNYI(CHROME = {"", "0", "1"},
EDGE = {"", "0", "1"},
FF = {"", "0", "1"},
FF_ESR = {"", "0", "1"},
IE = {"", "0", "1"})
public void siblingWithWhitespaceContentBeforeFrameset() throws Exception {
final String html = "<html>\n"
+ "<div> \t \r \r\n</div>\n"
+ "<div id='div1'> \t \r \r\n</div>\n"
+ "<frameset>\n"
+ " <frame name='main' src='" + URL_SECOND + "' />\n"
+ "</frameset>\n"
Expand All @@ -1133,17 +1165,21 @@ public void siblingWithWhitespaceContentBeforeFrameset() throws Exception {
+ "</body></html>";

getMockWebConnection().setResponse(URL_SECOND, html2);
final WebDriver webDriver = loadPageWithAlerts2(html);
assertEquals(1, webDriver.findElements(By.name("main")).size());

final WebDriver webDriver = loadPage2(html);
assertEquals(getExpectedAlerts()[0], String.join("§", getCollectedAlerts(webDriver)));
assertEquals(Integer.parseInt(getExpectedAlerts()[1]), webDriver.findElements(By.name("main")).size());
assertEquals(Integer.parseInt(getExpectedAlerts()[2]), webDriver.findElements(By.id("div1")).size());
}

/**
* @throws Exception if an error occurs
*/
@Test
@Alerts({"", "0", "1"})
public void siblingWithNbspContentBeforeFrameset() throws Exception {
final String html = "<html>\n"
+ "<div>&nbsp;</div>\n"
+ "<div id='div1'>&nbsp;</div>\n"
+ "<frameset>\n"
+ " <frame name='main' src='" + URL_SECOND + "' />\n"
+ "</div>\n"
Expand All @@ -1156,17 +1192,49 @@ public void siblingWithNbspContentBeforeFrameset() throws Exception {
+ "</body></html>";

getMockWebConnection().setResponse(URL_SECOND, html2);
final WebDriver webDriver = loadPageWithAlerts2(html);
assertEquals(0, webDriver.findElements(By.name("main")).size());

final WebDriver webDriver = loadPage2(html);
assertEquals(getExpectedAlerts()[0], String.join("§", getCollectedAlerts(webDriver)));
assertEquals(Integer.parseInt(getExpectedAlerts()[1]), webDriver.findElements(By.name("main")).size());
assertEquals(Integer.parseInt(getExpectedAlerts()[2]), webDriver.findElements(By.id("div1")).size());
}

/**
* @throws Exception if an error occurs
*/
@Test
@Alerts({"", "0", "1"})
public void siblingWithContentBeforeFrameset() throws Exception {
final String html = "<html>\n"
+ "<div><span>CONTENT</span></div>\n"
+ "<div id='div1'><span>CONTENT</span></div>\n"
+ "<frameset>\n"
+ " <frame name='main' src='" + URL_SECOND + "' />\n"
+ "</frameset>\n"
+ "</html>";

final String html2 = "<html><body>\n"
+ "<script>\n"
+ " alert('frame loaded');\n"
+ "</script>\n"
+ "</body></html>";

getMockWebConnection().setResponse(URL_SECOND, html2);

final WebDriver webDriver = loadPage2(html);
assertEquals(getExpectedAlerts()[0], String.join("§", getCollectedAlerts(webDriver)));
assertEquals(Integer.parseInt(getExpectedAlerts()[1]), webDriver.findElements(By.name("main")).size());
assertEquals(Integer.parseInt(getExpectedAlerts()[2]), webDriver.findElements(By.id("div1")).size());
}

/**
* @throws Exception if an error occurs
*/
@Test
@Alerts({"", "0", "1"})
public void siblingWithoutContentAndBodyBeforeFrameset() throws Exception {
final String html = "<html>\n"
+ "<div id='div1'><span></span></div>\n"
+ "<body>\n"
+ "<frameset>\n"
+ " <frame name='main' src='" + URL_SECOND + "' />\n"
+ "</frameset>\n"
Expand All @@ -1179,16 +1247,52 @@ public void siblingWithContentBeforeFrameset() throws Exception {
+ "</body></html>";

getMockWebConnection().setResponse(URL_SECOND, html2);
final WebDriver webDriver = loadPageWithAlerts2(html);
assertEquals(0, webDriver.findElements(By.name("main")).size());

final WebDriver webDriver = loadPage2(html);
assertEquals(getExpectedAlerts()[0], String.join("§", getCollectedAlerts(webDriver)));
assertEquals(Integer.parseInt(getExpectedAlerts()[1]), webDriver.findElements(By.name("main")).size());
assertEquals(Integer.parseInt(getExpectedAlerts()[2]), webDriver.findElements(By.id("div1")).size());
}


/**
* @throws Exception if an error occurs
*/
@Test
@Alerts("frame loaded")
@NotYetImplemented
@Alerts({"", "0", "1"})
public void siblingWithContentAndBodyBeforeFrameset() throws Exception {
final String html = "<html>\n"
+ "<div id='div1'>x<span></span></div>\n"
+ "<body>\n"
+ "<frameset>\n"
+ " <frame name='main' src='" + URL_SECOND + "' />\n"
+ "</frameset>\n"
+ "</html>";

final String html2 = "<html><body>\n"
+ "<script>\n"
+ " alert('frame loaded');\n"
+ "</script>\n"
+ "</body></html>";

getMockWebConnection().setResponse(URL_SECOND, html2);

final WebDriver webDriver = loadPage2(html);
assertEquals(getExpectedAlerts()[0], String.join("§", getCollectedAlerts(webDriver)));
assertEquals(Integer.parseInt(getExpectedAlerts()[1]), webDriver.findElements(By.name("main")).size());
assertEquals(Integer.parseInt(getExpectedAlerts()[2]), webDriver.findElements(By.id("div1")).size());
}

/**
* @throws Exception if an error occurs
*/
@Test
@Alerts({"frame loaded", "1", "0"})
@HtmlUnitNYI(CHROME = {"", "0", "1"},
EDGE = {"", "0", "1"},
FF = {"", "0", "1"},
FF_ESR = {"", "0", "1"},
IE = {"", "0", "1"})
public void framesetInsideDiv() throws Exception {
final String html = "<html>\n"
+ "<div id='tester'>\n"
Expand All @@ -1205,17 +1309,23 @@ public void framesetInsideDiv() throws Exception {
+ "</body></html>";

getMockWebConnection().setResponse(URL_SECOND, html2);
final WebDriver webDriver = loadPageWithAlerts2(html);
assertEquals(1, webDriver.findElements(By.name("main")).size());
assertEquals(0, webDriver.findElements(By.id("tester")).size());

final WebDriver webDriver = loadPage2(html);
assertEquals(getExpectedAlerts()[0], String.join("§", getCollectedAlerts(webDriver)));
assertEquals(Integer.parseInt(getExpectedAlerts()[1]), webDriver.findElements(By.name("main")).size());
assertEquals(Integer.parseInt(getExpectedAlerts()[2]), webDriver.findElements(By.id("tester")).size());
}

/**
* @throws Exception if an error occurs
*/
@Test
@Alerts("frame loaded")
@NotYetImplemented
@Alerts({"frame loaded", "1", "0"})
@HtmlUnitNYI(CHROME = {"", "0", "1"},
EDGE = {"", "0", "1"},
FF = {"", "0", "1"},
FF_ESR = {"", "0", "1"},
IE = {"", "0", "1"})
public void framesetInsideForm() throws Exception {
final String html = "<html>\n"
+ "<form id='tester'>\n"
Expand All @@ -1232,16 +1342,46 @@ public void framesetInsideForm() throws Exception {
+ "</body></html>";

getMockWebConnection().setResponse(URL_SECOND, html2);
final WebDriver webDriver = loadPageWithAlerts2(html);
assertEquals(1, webDriver.findElements(By.name("main")).size());
assertEquals(0, webDriver.findElements(By.id("tester")).size());

final WebDriver webDriver = loadPage2(html);
assertEquals(getExpectedAlerts()[0], String.join("§", getCollectedAlerts(webDriver)));
assertEquals(Integer.parseInt(getExpectedAlerts()[1]), webDriver.findElements(By.name("main")).size());
assertEquals(Integer.parseInt(getExpectedAlerts()[2]), webDriver.findElements(By.id("tester")).size());
}

/**
* @throws Exception if an error occurs
*/
@Test
@NotYetImplemented
@Alerts({"", "0", "1"})
public void framesetInsideFormContent() throws Exception {
final String html = "<html>\n"
+ "<form id='tester'>Content\n"
+ " <frameset>\n"
+ " <frame name='main' src='" + URL_SECOND + "' />\n"
+ " </frameset>\n"
+ "</form>\n"
+ "</html>";

final String html2 = "<html><body>\n"
+ "<script>\n"
+ " alert('frame loaded');\n"
+ "</script>\n"
+ "</body></html>";

getMockWebConnection().setResponse(URL_SECOND, html2);

final WebDriver webDriver = loadPage2(html);
assertEquals(getExpectedAlerts()[0], String.join("§", getCollectedAlerts(webDriver)));
assertEquals(Integer.parseInt(getExpectedAlerts()[1]), webDriver.findElements(By.name("main")).size());
assertEquals(Integer.parseInt(getExpectedAlerts()[2]), webDriver.findElements(By.id("tester")).size());
}

/**
* @throws Exception if an error occurs
*/
@Test
@Alerts({"", "0", "1"})
public void framesetInsideTable() throws Exception {
final String html = "<html>\n"
+ "<table id='tester'>\n"
Expand All @@ -1258,9 +1398,11 @@ public void framesetInsideTable() throws Exception {
+ "</body></html>";

getMockWebConnection().setResponse(URL_SECOND, html2);
final WebDriver webDriver = loadPageWithAlerts2(html);
assertEquals(0, webDriver.findElements(By.name("main")).size());
assertEquals(1, webDriver.findElements(By.id("tester")).size());

final WebDriver webDriver = loadPage2(html);
assertEquals(getExpectedAlerts()[0], String.join("§", getCollectedAlerts(webDriver)));
assertEquals(Integer.parseInt(getExpectedAlerts()[1]), webDriver.findElements(By.name("main")).size());
assertEquals(Integer.parseInt(getExpectedAlerts()[2]), webDriver.findElements(By.id("tester")).size());
}

/**
Expand Down

0 comments on commit 2edd006

Please sign in to comment.