use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlPreformattedTextTest method simpleScriptable.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("[object HTMLPreElement]")
public void simpleScriptable() throws Exception {
final String html = "<html><head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + " function test() {\n" + " log(document.getElementById('myId'));\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" + " <pre id='myId'>Some Text</pre>\n" + "</body></html>";
final WebDriver driver = loadPageVerifyTitle2(html);
if (driver instanceof HtmlUnitDriver) {
final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
assertTrue(HtmlPreformattedText.class.isInstance(page.getHtmlElementById("myId")));
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class HtmlProgressTest method simpleScriptable.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("[object HTMLProgressElement]")
public void simpleScriptable() throws Exception {
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" + LOG_TITLE_FUNCTION + " function test() {\n" + " log(document.getElementById('myId'));\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" + " <progress id='myId'></progress>\n" + "</body></html>";
final WebDriver driver = loadPageVerifyTitle2(html);
if (driver instanceof HtmlUnitDriver) {
final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
if ("[object HTMLProgressElement]".equals(getExpectedAlerts()[0])) {
assertTrue(HtmlProgress.class.isInstance(page.getHtmlElementById("myId")));
} else {
assertTrue(HtmlUnknownElement.class.isInstance(page.getHtmlElementById("myId")));
}
}
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class WindowConcurrency2Test method setIntervalZeroDelay.
/**
* When <tt>setInterval()</tt> is called with a 0 millisecond delay, Internet Explorer turns it
* into a <tt>setTimeout()</tt> call, and Firefox imposes a minimum timer restriction.
*
* @throws Exception if an error occurs
*/
@Test
@Alerts("xxx")
public void setIntervalZeroDelay() throws Exception {
final String html = "<html><body><div id='d'></div>\n" + "<script>\n" + " var count = 0;\n" + " function doTimeout() {\n" + " document.getElementById('d').innerHTML += 'x';\n" + " count++;\n" + " if (count > 2) {\n" + " clearInterval(id);\n" + " }\n" + " }\n" + " var id = setInterval(doTimeout, 0);\n" + "</script>\n" + "</body></html>";
final WebDriver driver = loadPage2(html);
verifyAlerts(() -> driver.findElement(By.id("d")).getText(), getExpectedAlerts()[0]);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class WindowTest method showModalDialog.
/**
* Basic test for the <tt>showModalDialog</tt> method. See bug #703.
* @throws Exception if an error occurs
*/
@Test
@Alerts(DEFAULT = { "undefined", "Jane", "Smith", "sdg", "finished" }, CHROME = "not available", EDGE = "not available", FF = "not available", FF_ESR = "not available")
public void showModalDialog() throws Exception {
final String html1 = "<html><head><script>\n" + " function test() {\n" + " if (!window.showModalDialog) {alert('not available'); return; }\n" + " alert(window.returnValue);\n" + " var o = new Object();\n" + " o.firstName = 'Jane';\n" + " o.lastName = 'Smith';\n" + " var ret = showModalDialog('myDialog.html', o, 'dialogHeight:300px; dialogLeft:200px;');\n" + " alert(ret);\n" + " alert('finished');\n" + " }\n" + "</script></head><body>\n" + " <button onclick='test()' id='b'>Test</button>\n" + "</body></html>";
final String html2 = "<html><head><script>\n" + " var o = window.dialogArguments;\n" + " alert(o.firstName);\n" + " alert(o.lastName);\n" + " window.returnValue = 'sdg';\n" + "</script></head>\n" + "<body>foo</body></html>";
final WebClient client = getWebClient();
final List<String> actual = new ArrayList<>();
client.setAlertHandler(new CollectingAlertHandler(actual));
final MockWebConnection conn = new MockWebConnection();
conn.setResponse(URL_FIRST, html1);
conn.setResponse(new URL(URL_FIRST, "myDialog.html"), html2);
client.setWebConnection(conn);
final HtmlPage page = client.getPage(URL_FIRST);
final HtmlElement button = page.getHtmlElementById("b");
final HtmlPage dialogPage = button.click();
if (getExpectedAlerts().length > 1) {
final DialogWindow dialog = (DialogWindow) dialogPage.getEnclosingWindow();
dialog.close();
}
assertEquals(getExpectedAlerts(), actual);
}
use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.
the class WindowTest method onbeforeunload_calledBeforeDownload.
/**
* Download of next page is done first after onbeforeunload is done.
* @throws Exception if an error occurs
*/
@Test
@Alerts("x")
public void onbeforeunload_calledBeforeDownload() throws Exception {
final String html = "<html><body><script>\n" + " window.onbeforeunload = function() { alert('x'); return 'hello'; };\n" + " window.location = 'foo.html';\n" + "</script></body></html>";
final WebClient webClient = getWebClientWithMockWebConnection();
getMockWebConnection().setDefaultResponse("");
final OnbeforeunloadHandler handler = new OnbeforeunloadHandler() {
@Override
public boolean handleEvent(final Page page, final String returnValue) {
final String[] expectedRequests = { "" };
assertEquals(expectedRequests, getMockWebConnection().getRequestedUrls(URL_FIRST));
return true;
}
};
webClient.setOnbeforeunloadHandler(handler);
loadPageWithAlerts(html);
final String[] expectedRequests = { "", "foo.html" };
assertEquals(expectedRequests, getMockWebConnection().getRequestedUrls(URL_FIRST));
}
Aggregations