Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/ConsoleJsObjectTest.java

Issue 29344967: Issue 4031 - Implement tests for libadblockplus-android (Closed)
Patch Set: fix typo ".. file[s]" Created Sept. 15, 2016, 10:44 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/ConsoleJsObjectTest.java
diff --git a/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/ConsoleJsObjectTest.java b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/ConsoleJsObjectTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..5547511da3fdbbd0e7ae61a7b806cc4c8748c80e
--- /dev/null
+++ b/libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/ConsoleJsObjectTest.java
@@ -0,0 +1,102 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2016 Eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.adblockplus.libadblockplus.tests;
+
+import org.adblockplus.libadblockplus.LogSystem;
+import org.adblockplus.libadblockplus.MockLogSystem;
+
+import org.junit.Test;
+
+public class ConsoleJsObjectTest extends BaseJsTest
+{
+ protected MockLogSystem mockLogSystem;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ mockLogSystem = new MockLogSystem();
+ jsEngine.setLogSystem(mockLogSystem);
+ }
+
+ @Test
+ public void testConsoleLogCall()
+ {
+ jsEngine.evaluate("\n\nconsole.log('foo', 'bar');\n\n", "eval");
+ assertEquals(LogSystem.LogLevel.LOG, mockLogSystem.getLastLogLevel());
+ assertEquals("foo bar", mockLogSystem.getLastMessage());
+ assertEquals("eval:3", mockLogSystem.getLastSource());
+ }
+
+ @Test
+ public void testConsoleDebugCall()
+ {
+ jsEngine.evaluate("console.debug('foo', 'bar')");
+ assertEquals(LogSystem.LogLevel.LOG, mockLogSystem.getLastLogLevel());
+ assertEquals("foo bar", mockLogSystem.getLastMessage());
+ assertEquals(":1", mockLogSystem.getLastSource());
+ }
+
+ @Test
+ public void testConsoleInfoCall()
+ {
+ jsEngine.evaluate("console.info('foo', 'bar')");
+ assertEquals(LogSystem.LogLevel.INFO, mockLogSystem.getLastLogLevel());
+ assertEquals("foo bar", mockLogSystem.getLastMessage());
+ assertEquals(":1", mockLogSystem.getLastSource());
+ }
+
+ @Test
+ public void testConsoleWarnCall()
+ {
+ jsEngine.evaluate("console.warn('foo', 'bar')");
+ assertEquals(LogSystem.LogLevel.WARN, mockLogSystem.getLastLogLevel());
+ assertEquals("foo bar", mockLogSystem.getLastMessage());
+ assertEquals(":1", mockLogSystem.getLastSource());
+ }
+
+ @Test
+ public void testConsoleErrorCall()
+ {
+ jsEngine.evaluate("console.error('foo', 'bar')");
+ assertEquals(LogSystem.LogLevel.ERROR, mockLogSystem.getLastLogLevel());
+ assertEquals("foo bar", mockLogSystem.getLastMessage());
+ assertEquals(":1", mockLogSystem.getLastSource());
+ }
+
+ @Test
+ public void testConsoleTraceCall()
+ {
+ jsEngine.evaluate(
+ "\n" +
+ "function foo()\n" +
+ "{\n" +
+ " (function() {\n" +
+ " console.trace();\n" +
+ " })();\n" +
+ "}\n" +
+ "foo();", "eval");
+ assertEquals(LogSystem.LogLevel.TRACE, mockLogSystem.getLastLogLevel());
+ assertEquals(
+ "1: /* anonymous */() at eval:5\n" +
+ "2: foo() at eval:6\n" +
+ "3: /* anonymous */() at eval:8\n", mockLogSystem.getLastMessage());
+ assertEquals("", mockLogSystem.getLastSource());
+ }
+}

Powered by Google App Engine
This is Rietveld