[HtmlUnit] SVN: [15521] trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ javascript/host/Window3Test.java
rbri--- via HtmlUnit-develop <[email protected]> Thu, 16 Aug 2018 06:25:07 +0000
| Newsgroups | gmane.comp.java.htmlunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Revision: 15521
http://sourceforge.net/p/htmlunit/code/15521
Author: rbri
Date: 2018-08-16 06:25:01 +0000 (Thu, 16 Aug 2018)
Log Message:
-----------
make tests more robust
Modified Paths:
--------------
trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java
Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2018-08-15 08:09:56 UTC (rev 15520)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2018-08-16 06:25:01 UTC (rev 15521)
@@ -1627,7 +1627,7 @@
+ "<html><head>\n"
+ "<script>\n"
+ " function log(msg) {\n"
- + " document.getElementById('log').value += msg + '\\n';\n"
+ + " window.parent.document.title += msg + ';';\n"
+ " }\n"
// These 'load' events and 'onload' property below target 'document' when fired
@@ -1682,12 +1682,11 @@
+ "function (event) { var x = event; "
+ "window.setTimeout(function () { log('after', x.eventPhase) }, 100) }, true)\n"
+ "</script>\n"
- + " <textarea id='log' rows=40 cols=80></textarea>\n"
+ "</body></html>";
final WebDriver driver = loadPage2(html);
Thread.sleep(200);
- final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", "");
+ final String text = driver.getTitle().trim().replaceAll(";", "\n").trim();
assertEquals(String.join("\n", getExpectedAlerts()), text);
}
@@ -1699,17 +1698,27 @@
* @throws Exception if the test fails
*/
@Test
- @Alerts(DEFAULT = {"document DOMContentLoaded",
+ @Alerts(DEFAULT = {"document at load capture",
+ "element 1 onload",
+ "window at error capture",
+ "document at error capture",
+ "element 2 onerror",
+ "document DOMContentLoaded",
"window DOMContentLoaded",
"window at load",
"window at load capture",
"body onload"},
- IE = {"document DOMContentLoaded",
+ IE = {"document at load capture",
+ "element 1 onload",
+ "window at error capture",
+ "document at error capture",
+ "element 2 onerror",
+ "document DOMContentLoaded",
"window DOMContentLoaded",
"window at load",
"window at load capture",
- "document at load capture",
- "body onload"})
+ "body onload",
+ "document at load capture"})
public void onloadScript() throws Exception {
getMockWebConnection().setResponse(URL_SECOND, "");
@@ -1717,7 +1726,7 @@
+ "<html><head>\n"
+ "<script>\n"
+ " function log(msg) {\n"
- + " document.getElementById('log').value += msg + '\\n';\n"
+ + " window.parent.document.title += msg + ';';\n"
+ " }\n"
+ " window.addEventListener('load', function () { log('window at load') })\n"
@@ -1739,13 +1748,11 @@
+ "onerror='log(\"element 1 onerror\")'></script>\n"
+ " <script src='missing.txt' onload='log(\"element 2 onload\")' "
+ "onerror='log(\"element 2 onerror\")'></script>\n"
-
- + " <textarea id='log' rows=40 cols=80></textarea>\n"
+ "</body></html>";
final WebDriver driver = loadPage2(html);
Thread.sleep(200);
- final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", "");
+ final String text = driver.getTitle().trim().replaceAll(";", "\n").trim();
assertEquals(String.join("\n", getExpectedAlerts()), text);
}
@@ -1800,7 +1807,7 @@
+ "<html><head>\n"
+ "<script>\n"
+ " function log(msg) {\n"
- + " document.getElementById('log').value += msg + '\\n';\n"
+ + " window.parent.document.title += msg + ';';\n"
+ " }\n"
+ " window.addEventListener('load', function () { log('window at load') })\n"
@@ -1823,12 +1830,11 @@
+ " <img src='' onload='log(\"element 2 onload\")' "
+ "onerror='log(\"element 2 onerror\")'>\n"
- + " <textarea id='log' rows=40 cols=80></textarea>\n"
+ "</body></html>";
final WebDriver driver = loadPage2(html);
Thread.sleep(200);
- final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", "");
+ final String text = driver.getTitle().trim().replaceAll(";", "\n").trim();
assertEquals(String.join("\n", getExpectedAlerts()), text);
}
@@ -1991,13 +1997,12 @@
+ "<html><head>\n"
+ "<script>\n"
+ " function log(msg) {\n"
- + " document.getElementById('log').value += msg + '\\n';\n"
+ + " window.parent.document.title += msg + ';';\n"
+ " }\n"
+ "</script>\n"
+ "</head>\n"
+ "<body>\n"
+ " <input id='tester' type='button' value='test' onclick='log(\"onclick\")'>\n"
- + " <textarea id='log' rows=40 cols=80></textarea>\n"
+ "<script>\n"
+ " window.addEventListener('click', function () { log('window at click 1') })\n"
@@ -2016,7 +2021,7 @@
final WebDriver driver = loadPage2(html);
driver.findElement(By.id("tester")).click();
- final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", "");
+ final String text = driver.getTitle().trim().replaceAll(";", "\n").trim();
assertEquals(String.join("\n", getExpectedAlerts()), text);
}
@@ -2051,7 +2056,7 @@
+ "<html><head>\n"
+ "<script>\n"
+ " function log(msg) {\n"
- + " document.getElementById('log').value += msg + '\\n';\n"
+ + " window.parent.document.title += msg + ';';\n"
+ " }\n"
+ "</script>\n"
+ "</head>\n"
@@ -2063,8 +2068,6 @@
+ " </div>\n"
+ " </div>\n"
- + " <textarea id='log' rows=40 cols=80></textarea>\n"
-
+ "<script>\n"
+ " window.addEventListener('click', function () { log('window at click 1') })\n"
+ " window.addEventListener('click', function () { log('window at click 1 capture') }, true)\n"
@@ -2094,7 +2097,7 @@
final WebDriver driver = loadPage2(html);
driver.findElement(By.id("d3")).click();
- final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", "");
+ final String text = driver.getTitle().trim().replaceAll(";", "\n").trim();
assertEquals(String.join("\n", getExpectedAlerts()), text);
}
@@ -2126,7 +2129,7 @@
+ "<html><head>\n"
+ "<script>\n"
+ " function log(msg) {\n"
- + " document.getElementById('log').value += msg + '\\n';\n"
+ + " window.parent.document.title += msg + ';';\n"
+ " }\n"
+ " function detachAndClick() {\n"
@@ -2147,8 +2150,6 @@
+ " </div>\n"
+ " <input id='detach_click' type='button' value='Detach & click' onclick='detachAndClick()'>\n"
- + " <textarea id='log' rows=40 cols=80></textarea>\n"
-
+ "<script>\n"
+ " d2 = window.d2, d3 = window.d3\n" // Save because "Detach & click" removes them
+ " window.addEventListener('click', function () { log('window at click 1') })\n"
@@ -2179,7 +2180,7 @@
final WebDriver driver = loadPage2(html);
driver.findElement(By.id("detach_click")).click();
- final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", "");
+ final String text = driver.getTitle().trim().replaceAll(";", "\n").trim();
assertEquals(String.join("\n", getExpectedAlerts()), text);
}
@@ -2200,7 +2201,7 @@
+ "<html><head>\n"
+ "<script>\n"
+ " function log(msg) {\n"
- + " document.getElementById('log').value += msg + '\\n';\n"
+ + " window.parent.document.title += msg + ';';\n"
+ " }\n"
+ "</script>\n"
+ "</head>\n"
@@ -2238,7 +2239,7 @@
driver.findElement(By.id("a1")).click();
driver.findElement(By.id("a2")).click();
- final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", "");
+ final String text = driver.getTitle().trim().replaceAll(";", "\n").trim();
assertEquals(String.join("\n", getExpectedAlerts()), text);
}
}
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot