Skip to content

Commit 96c6eb8

Browse files
committed
document last changes and migrate the test to webdriver test case
1 parent b04cabb commit 96c6eb8

3 files changed

Lines changed: 135 additions & 23 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
<body>
1010
<release version="5.0.0" date="April 01, 2026" description="jdk17, Bugfixes">
11+
<action type="fix" dev="Lai Quang Duong">
12+
HtmlInputElement's of type email/url/date/time have to fire the input event.
13+
</action>
1114
<action type="fix" dev="Lai Quang Duong">
1215
Align cookie max-age handling for huge values with the spec.
1316
</action>

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

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* @author Sudhan Moghe
4141
* @author Frank Danek
4242
* @author Ronald Brill
43+
* @author Lai Quang Duong
4344
*/
4445
public class HtmlElement2Test extends WebDriverTestCase {
4546

@@ -491,4 +492,135 @@ public void setGetStyle() throws Exception {
491492

492493
loadPageVerifyTitle2(html);
493494
}
495+
496+
/**
497+
* @throws Exception if an error occurs
498+
*/
499+
@Test
500+
@Alerts("input[object HTMLInputElement]")
501+
public void typeFiresInputEvent() throws Exception {
502+
typeFiresInputEvent("text", "a");
503+
typeFiresInputEvent("tel", "a");
504+
typeFiresInputEvent("number", "1");
505+
typeFiresInputEvent("search", "1");
506+
typeFiresInputEvent("password", "7");
507+
typeFiresInputEvent("email", "x");
508+
typeFiresInputEvent("url", "h");
509+
}
510+
511+
/**
512+
* @throws Exception if an error occurs
513+
*/
514+
@Test
515+
@Alerts("input[object HTMLInputElement]")
516+
@HtmlUnitNYI(
517+
CHROME = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
518+
"input[object HTMLInputElement]", "input[object HTMLInputElement]"},
519+
EDGE = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
520+
"input[object HTMLInputElement]", "input[object HTMLInputElement]"},
521+
FF = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
522+
"input[object HTMLInputElement]", "input[object HTMLInputElement]"},
523+
FF_ESR = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
524+
"input[object HTMLInputElement]", "input[object HTMLInputElement]"})
525+
public void typeFiresInputEventDate() throws Exception {
526+
// date and time are a bit tricky they only trigger if the input is correct
527+
typeFiresInputEvent("date", "01026");
528+
}
529+
530+
/**
531+
* @throws Exception if an error occurs
532+
*/
533+
@Test
534+
@Alerts("input[object HTMLInputElement]")
535+
@HtmlUnitNYI(
536+
CHROME = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
537+
"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]"},
538+
EDGE = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
539+
"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]"},
540+
FF = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
541+
"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]"},
542+
FF_ESR = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
543+
"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]"})
544+
public void typeFiresInputEventTime() throws Exception {
545+
typeFiresInputEvent("time", "1122PM");
546+
}
547+
548+
/**
549+
* @throws Exception if an error occurs
550+
*/
551+
@Test
552+
@Alerts({"input[object HTMLInputElement]", "input[object HTMLInputElement]"})
553+
public void typeFiresInputEventEachKey() throws Exception {
554+
typeFiresInputEvent("text", "ab");
555+
typeFiresInputEvent("tel", "a1");
556+
typeFiresInputEvent("number", "12");
557+
typeFiresInputEvent("search", "1a");
558+
typeFiresInputEvent("password", "7x");
559+
typeFiresInputEvent("email", "xy");
560+
typeFiresInputEvent("url", "ht");
561+
}
562+
563+
/**
564+
* @throws Exception if an error occurs
565+
*/
566+
@Test
567+
@Alerts(DEFAULT = {"input[object HTMLInputElement]", "input[object HTMLInputElement]"},
568+
FF = "input[object HTMLInputElement]",
569+
FF_ESR = "input[object HTMLInputElement]")
570+
@HtmlUnitNYI(
571+
CHROME = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
572+
"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]"},
573+
EDGE = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
574+
"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]"},
575+
FF = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
576+
"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]"},
577+
FF_ESR = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
578+
"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]"})
579+
public void typeFiresInputEventEachKeyDate() throws Exception {
580+
typeFiresInputEvent("date", "010268");
581+
}
582+
583+
/**
584+
* @throws Exception if an error occurs
585+
*/
586+
@Test
587+
@Alerts("input[object HTMLInputElement]")
588+
@HtmlUnitNYI(
589+
CHROME = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
590+
"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]"},
591+
EDGE = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
592+
"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]"},
593+
FF = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
594+
"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]"},
595+
FF_ESR = {"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]",
596+
"input[object HTMLInputElement]", "input[object HTMLInputElement]", "input[object HTMLInputElement]"})
597+
public void typeFiresInputEventEachKeyTime() throws Exception {
598+
typeFiresInputEvent("time", "1122PM");
599+
}
600+
601+
/**
602+
* @throws Exception if an error occurs
603+
*/
604+
private void typeFiresInputEvent(String type, final String value) throws Exception {
605+
final String html = DOCTYPE_HTML
606+
+ "<html>\n"
607+
+ "<head>\n"
608+
+ "<script>\n"
609+
+ LOG_TITLE_FUNCTION
610+
+ "</script>\n"
611+
+ "</head>\n"
612+
+ "<body>\n"
613+
+ "<input type='" + type + "' id='t'>\n"
614+
+ "<script>\n"
615+
+ " document.getElementById('t').addEventListener('input', function(e) {\n"
616+
+ " log('input' + e.target);\n"
617+
+ " });\n"
618+
+ "</script>\n"
619+
+ "</body></html>";
620+
621+
final WebDriver driver = loadPage2(html);
622+
final WebElement div = driver.findElement(By.id("t"));
623+
div.sendKeys(value);
624+
verifyTitle2(driver, getExpectedAlerts());
625+
}
494626
}

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,27 +1269,4 @@ public void acceptChar() throws Exception {
12691269
input.type(value);
12701270
assertEquals(value, input.getValue());
12711271
}
1272-
1273-
/**
1274-
* @throws Exception if an error occurs
1275-
*/
1276-
@Test
1277-
public void typeFiresInputEvent() throws Exception {
1278-
final String[] types = {"text", "tel", "number", "search", "password", "email", "url", "date", "time"};
1279-
1280-
for (final String type : types) {
1281-
final String html = DOCTYPE_HTML
1282-
+ "<html><body>\n"
1283-
+ "<input type='" + type + "' id='t'>\n"
1284-
+ "<script>\n"
1285-
+ " document.getElementById('t').addEventListener('input', function() {\n"
1286-
+ " document.title += 'input';\n"
1287-
+ " });\n"
1288-
+ "</script>\n"
1289-
+ "</body></html>";
1290-
final HtmlPage page = loadPage(html);
1291-
page.getHtmlElementById("t").type("ab");
1292-
assertEquals("input event for type=" + type, "inputinput", page.getTitleText());
1293-
}
1294-
}
12951272
}

0 commit comments

Comments
 (0)