Skip to content

Commit

Permalink
suppress some warnings and remove more alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jan 21, 2023
1 parent 0623cdd commit e7052c5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor;
import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;

/**
Expand Down Expand Up @@ -131,6 +132,7 @@ void setAddedNodes(final NodeList addedNodes) {
* @return the {@code addedNodes} property
*/
@JsxGetter
@SuppressFBWarnings("EI_EXPOSE_REP")
public NodeList getAddedNodes() {
return addedNodes_;
}
Expand All @@ -147,6 +149,7 @@ void setRemovedNodes(final NodeList removedNodes) {
* @return the {@code removedNodes} property
*/
@JsxGetter
@SuppressFBWarnings("EI_EXPOSE_REP")
public NodeList getRemovedNodes() {
return removedNodes_;
}
Expand All @@ -163,6 +166,7 @@ void setPreviousSibling(final Node previousSibling) {
* @return the {@code previousSibling} property
*/
@JsxGetter
@SuppressFBWarnings("EI_EXPOSE_REP")
public Node getPreviousSibling() {
return previousSibling_;
}
Expand All @@ -179,6 +183,7 @@ void setNextSibling(final Node nextSibling) {
* @return the {@code nextSibling} property
*/
@JsxGetter
@SuppressFBWarnings("EI_EXPOSE_REP")
public Node getNextSibling() {
return nextSibling_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl;
import com.sun.org.apache.xerces.internal.dom.DeferredNode;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
*
Expand All @@ -39,6 +41,10 @@ public final class XmlUtilsSunXercesHelper implements XmlUtilsHelperAPI {

// private static final Log LOG = LogFactory.getLog(XmlUtilsXerces.class);

/**
* Ctor.
*/
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
public XmlUtilsSunXercesHelper() {
// Force eager loading of classes in order to flush out any linkage errors early
Objects.hash(DeferredDocumentImpl.class, DeferredNode.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import com.gargoylesoftware.htmlunit.platform.XmlUtilsHelperAPI;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
*
Expand All @@ -39,6 +41,10 @@ public final class XmlUtilsXercesHelper implements XmlUtilsHelperAPI {

// private static final Log LOG = LogFactory.getLog(XmlUtilsXerces.class);

/**
* Ctor.
*/
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
public XmlUtilsXercesHelper() {
// Force eager loading of classes in order to flush out any linkage errors early
Objects.hash(DeferredDocumentImpl.class, DeferredNode.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ public void typeWhileDisabled() throws Exception {
@Alerts({"null", "null"})
public void typeDoesNotChangeValueAttribute() throws Exception {
final String html = "<html>\n"
+ "<head></head>\n"
+ "<head>\n"
+ "<script>" + LOG_TITLE_FUNCTION + "</script>\n"
+ "</head>\n"
+ "<body>\n"
+ " <input type='password' id='p'/>\n"
+ " <button id='check' onclick='alert(document.getElementById(\"p\").getAttribute(\"value\"));'>"
+ " <button id='check' onclick='log(document.getElementById(\"p\").getAttribute(\"value\"));'>"
+ "DoIt</button>\n"
+ "</body></html>";

Expand All @@ -124,11 +126,11 @@ public void typeDoesNotChangeValueAttribute() throws Exception {

final WebElement check = driver.findElement(By.id("check"));
check.click();
verifyAlerts(driver, getExpectedAlerts()[0]);
verifyTitle2(driver, getExpectedAlerts()[0]);

p.sendKeys("abc");
check.click();
verifyAlerts(driver, getExpectedAlerts()[1]);
verifyTitle2(driver, getExpectedAlerts());
}

/**
Expand All @@ -138,10 +140,12 @@ public void typeDoesNotChangeValueAttribute() throws Exception {
@Alerts({"HtmlUnit", "HtmlUnit"})
public void typeDoesNotChangeValueAttributeWithInitialValue() throws Exception {
final String html = "<html>\n"
+ "<head></head>\n"
+ "<head>\n"
+ "<script>" + LOG_TITLE_FUNCTION + "</script>\n"
+ "</head>\n"
+ "<body>\n"
+ " <input type='password' id='p' value='HtmlUnit'/>\n"
+ " <button id='check' onclick='alert(document.getElementById(\"p\").getAttribute(\"value\"));'>"
+ " <button id='check' onclick='log(document.getElementById(\"p\").getAttribute(\"value\"));'>"
+ "DoIt</button>\n"
+ "</body></html>";

Expand All @@ -150,11 +154,11 @@ public void typeDoesNotChangeValueAttributeWithInitialValue() throws Exception {

final WebElement check = driver.findElement(By.id("check"));
check.click();
verifyAlerts(driver, getExpectedAlerts()[0]);
verifyTitle2(driver, getExpectedAlerts()[0]);

p.sendKeys("abc");
check.click();
verifyAlerts(driver, getExpectedAlerts()[1]);
verifyTitle2(driver, getExpectedAlerts());
}

/**
Expand Down Expand Up @@ -215,12 +219,16 @@ public void preventDefault_OnKeyPress() throws Exception {
* @throws Exception if an error occurs
*/
@Test
@Alerts({"foo", "change", "boo", "blur", "boo", "blur"})
public void typeOnChange() throws Exception {
final String html =
"<html><head></head><body>\n"
"<html><head>\n"
+ "<script>" + LOG_TITLE_FUNCTION + "</script>\n"
+ "</head>\n"
+ "<body>\n"
+ "<input type='password' id='p' value='Hello world'"
+ " onChange='alert(\"foo\");alert(event.type);'"
+ " onBlur='alert(\"boo\");alert(event.type);'>\n"
+ " onChange='log(\"foo\");log(event.type);'"
+ " onBlur='log(\"boo\");log(event.type);'>\n"
+ "<button id='b'>some button</button>\n"
+ "</body></html>";

Expand All @@ -232,17 +240,16 @@ public void typeOnChange() throws Exception {

// trigger lost focus
driver.findElement(By.id("b")).click();
final String[] expectedAlerts1 = {"foo", "change", "boo", "blur"};
assertEquals(expectedAlerts1, getCollectedAlerts(driver, 4));
verifyTitle2(driver, getExpectedAlerts()[0], getExpectedAlerts()[1],
getExpectedAlerts()[2], getExpectedAlerts()[3]);

// set only the focus but change nothing
p.click();
assertTrue(getCollectedAlerts(driver, 1).isEmpty());

// trigger lost focus
driver.findElement(By.id("b")).click();
final String[] expectedAlerts2 = {"boo", "blur"};
assertEquals(expectedAlerts2, getCollectedAlerts(driver, 2));
verifyTitle2(driver, getExpectedAlerts());
}

/**
Expand All @@ -252,10 +259,12 @@ public void typeOnChange() throws Exception {
public void setValueOnChange() throws Exception {
final String html =
"<html>\n"
+ "<head></head>\n"
+ "<head>\n"
+ "<script>" + LOG_TITLE_FUNCTION + "</script>\n"
+ "</head>\n"
+ "<body>\n"
+ " <input type='password' id='p' value='Hello world'"
+ " onChange='alert(\"foo\");alert(event.type);'>\n"
+ " onChange='log(\"foo\");log(event.type);'>\n"
+ " <button id='b'>some button</button>\n"
+ " <button id='set' onclick='document.getElementById(\"p\").value=\"HtmlUnit\"'>setValue</button>\n"
+ "</body></html>";
Expand All @@ -280,7 +289,7 @@ public void setDefaultValueOnChange() throws Exception {
+ "<head></head>\n"
+ "<body>\n"
+ " <input type='password' id='p' value='Hello world'"
+ " onChange='alert(\"foo\");alert(event.type);'>\n"
+ " onChange='log(\"foo\");log(event.type);'>\n"
+ " <button id='b'>some button</button>\n"
+ " <button id='set' onclick='document.getElementById(\"p\").defaultValue=\"HtmlUnit\"'>"
+ "setValue</button>\n"
Expand All @@ -289,11 +298,11 @@ public void setDefaultValueOnChange() throws Exception {
final WebDriver driver = loadPage2(html);
driver.findElement(By.id("set")).click();

assertEquals(Collections.emptyList(), getCollectedAlerts(driver));
verifyTitle2(driver);

// trigger lost focus
driver.findElement(By.id("b")).click();
assertEquals(Collections.emptyList(), getCollectedAlerts(driver));
verifyTitle2(driver);
}

/**
Expand Down

0 comments on commit e7052c5

Please sign in to comment.