| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 package org.adblockplus.libadblockplus.tests; | 18 package org.adblockplus.libadblockplus.tests; |
| 19 | 19 |
| 20 import org.adblockplus.libadblockplus.LogSystem; | 20 import org.adblockplus.libadblockplus.LogSystem; |
| 21 import org.adblockplus.libadblockplus.MockLogSystem; | 21 import org.adblockplus.libadblockplus.MockLogSystem; |
| 22 | 22 |
| 23 import org.junit.Test; | 23 import org.junit.Test; |
| 24 | 24 |
| 25 public class ConsoleJsObjectTest extends BaseJsTest { | 25 public class ConsoleJsObjectTest extends BaseJsTest |
| 26 { |
| 27 protected MockLogSystem mockLogSystem; |
| 26 | 28 |
| 27 protected MockLogSystem mockLogSystem; | 29 @Override |
| 30 protected void setUp() throws Exception |
| 31 { |
| 32 super.setUp(); |
| 28 | 33 |
| 29 @Override | 34 mockLogSystem = new MockLogSystem(); |
| 30 protected void setUp() throws Exception { | 35 jsEngine.setLogSystem(mockLogSystem); |
| 31 super.setUp(); | 36 } |
| 32 | 37 |
| 33 mockLogSystem = new MockLogSystem(); | 38 @Test |
| 34 jsEngine.setLogSystem(mockLogSystem); | 39 public void testConsoleLogCall() |
| 35 } | 40 { |
| 41 jsEngine.evaluate("\n\nconsole.log('foo', 'bar');\n\n", "eval"); |
| 42 assertEquals(LogSystem.LogLevel.LOG, mockLogSystem.getLastLogLevel()); |
| 43 assertEquals("foo bar", mockLogSystem.getLastMessage()); |
| 44 assertEquals("eval:3", mockLogSystem.getLastSource()); |
| 45 } |
| 36 | 46 |
| 37 @Test | 47 @Test |
| 38 public void testConsoleLogCall() { | 48 public void testConsoleDebugCall() |
| 39 jsEngine.evaluate("\n\nconsole.log('foo', 'bar');\n\n", "eval"); | 49 { |
| 40 assertEquals(LogSystem.LogLevel.LOG, mockLogSystem.getLastLogLevel()); | 50 jsEngine.evaluate("console.debug('foo', 'bar')"); |
| 41 assertEquals("foo bar", mockLogSystem.getLastMessage()); | 51 assertEquals(LogSystem.LogLevel.LOG, mockLogSystem.getLastLogLevel()); |
| 42 assertEquals("eval:3", mockLogSystem.getLastSource()); | 52 assertEquals("foo bar", mockLogSystem.getLastMessage()); |
| 43 } | 53 assertEquals(":1", mockLogSystem.getLastSource()); |
| 54 } |
| 44 | 55 |
| 45 @Test | 56 @Test |
| 46 public void testConsoleDebugCall() { | 57 public void testConsoleInfoCall() |
| 47 jsEngine.evaluate("console.debug('foo', 'bar')"); | 58 { |
| 48 assertEquals(LogSystem.LogLevel.LOG, mockLogSystem.getLastLogLevel()); | 59 jsEngine.evaluate("console.info('foo', 'bar')"); |
| 49 assertEquals("foo bar", mockLogSystem.getLastMessage()); | 60 assertEquals(LogSystem.LogLevel.INFO, mockLogSystem.getLastLogLevel()); |
| 50 assertEquals(":1", mockLogSystem.getLastSource()); | 61 assertEquals("foo bar", mockLogSystem.getLastMessage()); |
| 51 } | 62 assertEquals(":1", mockLogSystem.getLastSource()); |
| 63 } |
| 52 | 64 |
| 53 @Test | 65 @Test |
| 54 public void testConsoleInfoCall() { | 66 public void testConsoleWarnCall() |
| 55 jsEngine.evaluate("console.info('foo', 'bar')"); | 67 { |
| 56 assertEquals(LogSystem.LogLevel.INFO, mockLogSystem.getLastLogLevel()); | 68 jsEngine.evaluate("console.warn('foo', 'bar')"); |
| 57 assertEquals("foo bar", mockLogSystem.getLastMessage()); | 69 assertEquals(LogSystem.LogLevel.WARN, mockLogSystem.getLastLogLevel()); |
| 58 assertEquals(":1", mockLogSystem.getLastSource()); | 70 assertEquals("foo bar", mockLogSystem.getLastMessage()); |
| 59 } | 71 assertEquals(":1", mockLogSystem.getLastSource()); |
| 72 } |
| 60 | 73 |
| 61 @Test | 74 @Test |
| 62 public void testConsoleWarnCall() { | 75 public void testConsoleErrorCall() |
| 63 jsEngine.evaluate("console.warn('foo', 'bar')"); | 76 { |
| 64 assertEquals(LogSystem.LogLevel.WARN, mockLogSystem.getLastLogLevel()); | 77 jsEngine.evaluate("console.error('foo', 'bar')"); |
| 65 assertEquals("foo bar", mockLogSystem.getLastMessage()); | 78 assertEquals(LogSystem.LogLevel.ERROR, mockLogSystem.getLastLogLevel()); |
| 66 assertEquals(":1", mockLogSystem.getLastSource()); | 79 assertEquals("foo bar", mockLogSystem.getLastMessage()); |
| 67 } | 80 assertEquals(":1", mockLogSystem.getLastSource()); |
| 81 } |
| 68 | 82 |
| 69 @Test | 83 @Test |
| 70 public void testConsoleErrorCall() { | 84 public void testConsoleTraceCall() |
| 71 jsEngine.evaluate("console.error('foo', 'bar')"); | 85 { |
| 72 assertEquals(LogSystem.LogLevel.ERROR, mockLogSystem.getLastLogLevel()); | 86 jsEngine.evaluate( |
| 73 assertEquals("foo bar", mockLogSystem.getLastMessage()); | 87 "\n" + |
| 74 assertEquals(":1", mockLogSystem.getLastSource()); | 88 "function foo()\n" + |
| 75 } | 89 "{\n" + |
| 76 | 90 " (function() {\n" + |
| 77 @Test | 91 " console.trace();\n" + |
| 78 public void testConsoleTraceCall() { | 92 " })();\n" + |
| 79 jsEngine.evaluate( | 93 "}\n" + |
| 80 "\n" + | 94 "foo();", "eval"); |
| 81 "function foo()\n" + | 95 assertEquals(LogSystem.LogLevel.TRACE, mockLogSystem.getLastLogLevel()); |
| 82 "{\n" + | 96 assertEquals( |
| 83 " (function() {\n" + | 97 "1: /* anonymous */() at eval:5\n" + |
| 84 " console.trace();\n" + | 98 "2: foo() at eval:6\n" + |
| 85 " })();\n" + | 99 "3: /* anonymous */() at eval:8\n", mockLogSystem.getLastMessage()); |
| 86 "}\n" + | 100 assertEquals("", mockLogSystem.getLastSource()); |
| 87 "foo();", "eval"); | 101 } |
| 88 assertEquals(LogSystem.LogLevel.TRACE, mockLogSystem.getLastLogLevel()); | |
| 89 assertEquals( | |
| 90 "1: /* anonymous */() at eval:5\n" + | |
| 91 "2: foo() at eval:6\n" + | |
| 92 "3: /* anonymous */() at eval:8\n", mockLogSystem.getLastMessage()); | |
| 93 assertEquals("", mockLogSystem.getLastSource()); | |
| 94 } | |
| 95 } | 102 } |
| LEFT | RIGHT |