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

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

Issue 29344967: Issue 4031 - Implement tests for libadblockplus-android (Closed)
Patch Set: Updated tests, also moved to libadblockplus-android repo Created June 21, 2016, 10:51 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 package org.adblockplus.libadblockplus.tests;
19
20 import org.adblockplus.libadblockplus.LogSystem;
21 import org.adblockplus.libadblockplus.MockLogSystem;
22
23 import org.junit.Test;
24
25 public class ConsoleJsObjectTest extends BaseJsTest {
26
27 protected MockLogSystem mockLogSystem;
28
29 @Override
30 protected void setUp() throws Exception {
31 super.setUp();
32
33 mockLogSystem = new MockLogSystem();
34 jsEngine.setLogSystem(mockLogSystem);
35 }
36
37 @Test
38 public void testConsoleLogCall() {
39 jsEngine.evaluate("\n\nconsole.log('foo', 'bar');\n\n", "eval");
40 assertEquals(LogSystem.LogLevel.LOG, mockLogSystem.getLastLogLevel());
41 assertEquals("foo bar", mockLogSystem.getLastMessage());
42 assertEquals("eval:3", mockLogSystem.getLastSource());
43 }
44
45 @Test
46 public void testConsoleDebugCall() {
47 jsEngine.evaluate("console.debug('foo', 'bar')");
48 assertEquals(LogSystem.LogLevel.LOG, mockLogSystem.getLastLogLevel());
49 assertEquals("foo bar", mockLogSystem.getLastMessage());
50 assertEquals(":1", mockLogSystem.getLastSource());
51 }
52
53 @Test
54 public void testConsoleInfoCall() {
55 jsEngine.evaluate("console.info('foo', 'bar')");
56 assertEquals(LogSystem.LogLevel.INFO, mockLogSystem.getLastLogLevel());
57 assertEquals("foo bar", mockLogSystem.getLastMessage());
58 assertEquals(":1", mockLogSystem.getLastSource());
59 }
60
61 @Test
62 public void testConsoleWarnCall() {
63 jsEngine.evaluate("console.warn('foo', 'bar')");
64 assertEquals(LogSystem.LogLevel.WARN, mockLogSystem.getLastLogLevel());
65 assertEquals("foo bar", mockLogSystem.getLastMessage());
66 assertEquals(":1", mockLogSystem.getLastSource());
67 }
68
69 @Test
70 public void testConsoleErrorCall() {
71 jsEngine.evaluate("console.error('foo', 'bar')");
72 assertEquals(LogSystem.LogLevel.ERROR, mockLogSystem.getLastLogLevel());
73 assertEquals("foo bar", mockLogSystem.getLastMessage());
74 assertEquals(":1", mockLogSystem.getLastSource());
75 }
76
77 @Test
78 public void testConsoleTraceCall() {
79 jsEngine.evaluate(
80 "\n" +
81 "function foo()\n" +
82 "{\n" +
83 " (function() {\n" +
84 " console.trace();\n" +
85 " })();\n" +
86 "}\n" +
87 "foo();", "eval");
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld