From: <mgu...@us...> - 2012-12-18 14:42:28
|
Revision: 7880 http://sourceforge.net/p/htmlunit/code/7880 Author: mguillem Date: 2012-12-18 14:42:25 +0000 (Tue, 18 Dec 2012) Log Message: ----------- window.console is first defined in FF4 and (probably) in IE9 but is defined for Chrome Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Console.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ConsoleTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-12-18 13:55:30 UTC (rev 7879) +++ trunk/htmlunit/src/changes/changes.xml 2012-12-18 14:42:25 UTC (rev 7880) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes"> + <action type="update" dev="mguillem"> + JavaScript: adjust availability of window.console (Firefox 4+, IE9+ and Chrome). + </action> <action type="fix" dev="mguillem"> Fixed typo in method names of com.gargoylesoftware.htmlunit.WebConsole.Formatter. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Console.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Console.java 2012-12-18 13:55:30 UTC (rev 7879) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Console.java 2012-12-18 14:42:25 UTC (rev 7880) @@ -14,6 +14,10 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; + import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -35,6 +39,7 @@ import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; +import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; /** * A JavaScript object for a console. This implementation simulates Firefox's console, which utilizes FireBug API. @@ -42,7 +47,8 @@ * @version $Revision$ * @author Andrea Martino */ -@JsxClass +@JsxClass(browsers = { @WebBrowser(value = FF, minVersion = 4), @WebBrowser(value = IE, minVersion = 9), + @WebBrowser(CHROME) }) public class Console extends SimpleScriptable { private static final Map<String, Long> TIMERS = new HashMap<String, Long>(); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2012-12-18 13:55:30 UTC (rev 7879) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2012-12-18 14:42:25 UTC (rev 7880) @@ -605,7 +605,8 @@ * Returns the console property. * @return the console property */ - @JsxGetter(@WebBrowser(FF)) + @JsxGetter({ @WebBrowser(value = FF, minVersion = 4), @WebBrowser(value = IE, minVersion = 9), + @WebBrowser(CHROME) }) public ScriptableObject getConsole() { return console_; } @@ -614,7 +615,8 @@ * Sets the console. * @param console the console */ - @JsxSetter(@WebBrowser(FF)) + @JsxSetter({ @WebBrowser(value = FF, minVersion = 4), @WebBrowser(value = IE, minVersion = 9), + @WebBrowser(CHROME) }) public void setConsole(final ScriptableObject console) { console_ = console; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ConsoleTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ConsoleTest.java 2012-12-18 13:55:30 UTC (rev 7879) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ConsoleTest.java 2012-12-18 14:42:25 UTC (rev 7880) @@ -20,68 +20,98 @@ import java.util.List; import org.junit.Test; +import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; import com.gargoylesoftware.htmlunit.WebConsole; import com.gargoylesoftware.htmlunit.WebConsole.Logger; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** * Tests for {@link Console}. * * @version $Revision$ * @author Ahmed Ashour + * @author Marc Guillemot */ -@RunWith(BrowserRunner.class) -public class ConsoleTest extends SimpleWebTestCase { +@RunWith(Enclosed.class) +public class ConsoleTest { + /** + * The tests running through WebDriver. + */ + @RunWith(BrowserRunner.class) + public static class WebdriverBasedTests extends WebDriverTestCase { + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "false", + FF3_6 = "true", IE6 = "true", IE7 = "true", IE8 = "true") + public void undefined() throws Exception { + final String html + = "<html><body><script>\n" + + "alert(window.console == undefined)\n" + + "</script></body></html>"; + loadPageWithAlerts2(html); + } + } + /** - * @throws Exception if the test fails + * The tests NOT running through WebDriver. */ - @Test - @Browsers(FF) - public void log() throws Exception { - final WebConsole console = getWebClient().getWebConsole(); - final List<String> messages = new ArrayList<String>(); - console.setLogger(new Logger() { + @RunWith(BrowserRunner.class) + public static class SimpleTests extends SimpleWebTestCase { + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(FF) + public void log() throws Exception { + final WebConsole console = getWebClient().getWebConsole(); + final List<String> messages = new ArrayList<String>(); + console.setLogger(new Logger() { - @Override - public void warn(final Object message) { - } + @Override + public void warn(final Object message) { + } - @Override - public void trace(final Object message) { - } + @Override + public void trace(final Object message) { + } - @Override - public void info(final Object message) { - messages.add("info: " + message); - } + @Override + public void info(final Object message) { + messages.add("info: " + message); + } - @Override - public void error(final Object message) { - } + @Override + public void error(final Object message) { + } - @Override - public void debug(final Object message) { - } - }); + @Override + public void debug(final Object message) { + } + }); - final String html - = "<html><head><title>foo</title><script>\n" - + "function test() {\n" - + " if (window.console) {\n" - + " var arr = ['one', 'two', 'three', document.body.children];\n" - + " window.console.log(arr);\n" - + " window.dump('hello');\n" - + " }\n" - + "}\n" - + "</script></head><body onload='test()'></body></html>"; + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " if (window.console) {\n" + + " var arr = ['one', 'two', 'three', document.body.children];\n" + + " window.console.log(arr);\n" + + " window.dump('hello');\n" + + " }\n" + + "}\n" + + "</script></head><body onload='test()'></body></html>"; - loadPage(html); - assertEquals("info: [\"one\", \"two\", \"three\", ({})]", messages.get(0)); - assertEquals("info: hello", messages.get(1)); + loadPage(html); + assertEquals("info: [\"one\", \"two\", \"three\", ({})]", messages.get(0)); + assertEquals("info: hello", messages.get(1)); + } } } |