use of com.gargoylesoftware.htmlunit.WebConsole.Logger in project htmlunit by HtmlUnit.
the class WindowTest method dump.
/**
* @throws Exception if the test fails
*/
@Test
@Alerts(DEFAULT = "", FF = "info: Dumper", FF_ESR = "info: Dumper")
public void dump() throws Exception {
final WebConsole console = getWebClient().getWebConsole();
final List<String> messages = new ArrayList<>();
console.setLogger(new Logger() {
@Override
public void warn(final Object message) {
}
@Override
public void trace(final Object message) {
}
@Override
public void info(final Object message) {
messages.add("info: " + message);
}
@Override
public void error(final Object message) {
}
@Override
public void debug(final Object message) {
}
@Override
public boolean isTraceEnabled() {
return false;
}
@Override
public boolean isDebugEnabled() {
return false;
}
@Override
public boolean isInfoEnabled() {
return true;
}
@Override
public boolean isWarnEnabled() {
return true;
}
@Override
public boolean isErrorEnabled() {
return true;
}
});
final String html = "<html><head><title>foo</title><script>\n" + "function test() {\n" + " if (window.dump) {\n" + " window.dump('Dumper');\n" + " }\n" + "}\n" + "</script></head><body onload='test()'></body></html>";
loadPage(html);
assertEquals(getExpectedAlerts(), messages);
}
use of com.gargoylesoftware.htmlunit.WebConsole.Logger in project htmlunit by HtmlUnit.
the class Console2Test method log.
private void log(final String logInput) throws Exception {
final WebConsole console = getWebClient().getWebConsole();
final List<String> messages = new ArrayList<>();
console.setLogger(new Logger() {
@Override
public void warn(final Object message) {
}
@Override
public void trace(final Object message) {
}
@Override
public void info(final Object message) {
messages.add("info: " + message);
}
@Override
public void error(final Object message) {
}
@Override
public void debug(final Object message) {
}
@Override
public boolean isTraceEnabled() {
return false;
}
@Override
public boolean isDebugEnabled() {
return false;
}
@Override
public boolean isInfoEnabled() {
return true;
}
@Override
public boolean isWarnEnabled() {
return true;
}
@Override
public boolean isErrorEnabled() {
return true;
}
});
final String html = "<html><head><title>foo</title><script>\n" + "function test() {\n" + " window.console.log(" + logInput + ");\n" + "}\n" + "</script></head><body onload='test()'></body></html>";
loadPage(html);
assertEquals(getExpectedAlerts(), messages);
}
Aggregations