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

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

Issue 29344967: Issue 4031 - Implement tests for libadblockplus-android (Closed)
Patch Set: Created May 27, 2016, 1:38 p.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.AdblockPlusException;
21
22 import org.junit.Test;
23
24 public class GlobalJsObjectTest extends BaseJsTest {
25
26 @Test
27 public void testSetTimeout() throws InterruptedException {
28 jsEngine.evaluate("setTimeout(function() {foo = 'bar';}, 100)");
29 assertTrue(jsEngine.evaluate("this.foo").isUndefined());
30 Thread.sleep(200);
31 assertEquals("bar", jsEngine.evaluate("this.foo").asString());
32 }
33
34 @Test
35 public void testSetTimeoutWithArgs() throws InterruptedException {
36 jsEngine.evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')");
37 assertTrue(jsEngine.evaluate("this.foo").isUndefined());
38 Thread.sleep(200);
39 assertEquals("foobar", jsEngine.evaluate("this.foo").asString());
40 }
41
42 @Test
43 public void testSetTimeoutWithInvalidArgs() {
44 try {
45 jsEngine.evaluate("setTimeout()");
46 fail();
47 } catch (AdblockPlusException e) {
48 // ignored
49 }
50
51 try {
52 jsEngine.evaluate("setTimeout('', 1)");
53 fail();
54 } catch (AdblockPlusException e) {
55 // ignored
56 }
57 }
58
59 @Test
60 public void testSetMultipleTimeouts() throws InterruptedException {
61 jsEngine.evaluate("foo = []");
62 jsEngine.evaluate("setTimeout(function(s) {foo.push('1');}, 100)");
63 jsEngine.evaluate("setTimeout(function(s) {foo.push('2');}, 150)");
64 Thread.sleep(200);
65 assertEquals("1,2", jsEngine.evaluate("this.foo").asString());
66 }
67
68 }
OLDNEW

Powered by Google App Engine
This is Rietveld