use of com.gargoylesoftware.htmlunit.DialogWindow 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.DialogWindow in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method showModelessDialog.
/**
* Creates a modeless dialog box that displays the specified HTML document.
* @param url the URL of the document to load and display
* @param arguments object to be made available via <tt>window.dialogArguments</tt> in the dialog window
* @param features string that specifies the window ornaments for the dialog window
* @return a reference to the new window object created for the modeless dialog
* @see <a href="http://msdn.microsoft.com/en-us/library/ms536761.aspx">MSDN Documentation</a>
*/
@JsxFunction(IE)
public Object showModelessDialog(final String url, final Object arguments, final String features) {
final WebWindow webWindow = getWebWindow();
final WebClient client = webWindow.getWebClient();
try {
final URL completeUrl = ((HtmlPage) getDomNodeOrDie()).getFullyQualifiedUrl(url);
final DialogWindow dialog = client.openDialogWindow(completeUrl, webWindow, arguments);
return dialog.getScriptableObject();
} catch (final IOException e) {
throw Context.throwAsScriptRuntimeEx(e);
}
}
use of com.gargoylesoftware.htmlunit.DialogWindow in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method showModalDialog.
/**
* Creates a modal dialog box that displays the specified HTML document.
* @param url the URL of the document to load and display
* @param arguments object to be made available via <tt>window.dialogArguments</tt> in the dialog window
* @param features string that specifies the window ornaments for the dialog window
* @return the value of the {@code returnValue} property as set by the modal dialog's window
* @see <a href="http://msdn.microsoft.com/en-us/library/ms536759.aspx">MSDN Documentation</a>
* @see <a href="https://developer.mozilla.org/en/DOM/window.showModalDialog">Mozilla Documentation</a>
*/
@JsxFunction(IE)
public Object showModalDialog(final String url, final Object arguments, final String features) {
final WebWindow webWindow = getWebWindow();
final WebClient client = webWindow.getWebClient();
try {
final URL completeUrl = ((HtmlPage) getDomNodeOrDie()).getFullyQualifiedUrl(url);
final DialogWindow dialog = client.openDialogWindow(completeUrl, webWindow, arguments);
// TODO: Theoretically, we shouldn't return until the dialog window has been close()'ed...
// But we have to return so that the window can be close()'ed...
// Maybe we can use Rhino's continuation support to save state and restart when
// the dialog window is close()'ed? Would only work in interpreted mode, though.
final ScriptableObject jsDialog = dialog.getScriptableObject();
return jsDialog.get("returnValue", jsDialog);
} catch (final IOException e) {
throw Context.throwAsScriptRuntimeEx(e);
}
}
Aggregations