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

Side by Side Diff: test/GlobalJsObject.cpp

Issue 29367003: Issue #4711 - Rewrite legacy thread facilities
Patch Set: Created Dec. 7, 2016, 4:44 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
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 #include "BaseJsTest.h" 18 #include "BaseJsTest.h"
19 #include "../src/Thread.h"
20 19
21 namespace 20 namespace
22 { 21 {
23 class GlobalJsObjectTest : public BaseJsTest 22 class GlobalJsObjectTest : public BaseJsTest
24 { 23 {
25 }; 24 };
26 } 25 }
27 26
28 TEST_F(GlobalJsObjectTest, SetTimeout) 27 TEST_F(GlobalJsObjectTest, SetTimeout)
29 { 28 {
30 jsEngine->Evaluate("setTimeout(function() {foo = 'bar';}, 100)"); 29 jsEngine->Evaluate("setTimeout(function() {foo = 'bar';}, 100)");
31 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined()); 30 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined());
32 AdblockPlus::Sleep(200); 31 std::this_thread::sleep_for(std::chrono::milliseconds(200));
33 ASSERT_EQ("bar", jsEngine->Evaluate("this.foo")->AsString()); 32 ASSERT_EQ("bar", jsEngine->Evaluate("this.foo")->AsString());
34 } 33 }
35 34
36 TEST_F(GlobalJsObjectTest, SetTimeoutWithArgs) 35 TEST_F(GlobalJsObjectTest, SetTimeoutWithArgs)
37 { 36 {
38 jsEngine->Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')"); 37 jsEngine->Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')");
39 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined()); 38 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined());
40 AdblockPlus::Sleep(200); 39 std::this_thread::sleep_for(std::chrono::milliseconds(200));
41 ASSERT_EQ("foobar", jsEngine->Evaluate("this.foo")->AsString()); 40 ASSERT_EQ("foobar", jsEngine->Evaluate("this.foo")->AsString());
42 } 41 }
43 42
44 TEST_F(GlobalJsObjectTest, SetTimeoutWithInvalidArgs) 43 TEST_F(GlobalJsObjectTest, SetTimeoutWithInvalidArgs)
45 { 44 {
46 ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout()")); 45 ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout()"));
47 ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout('', 1)")); 46 ASSERT_ANY_THROW(jsEngine->Evaluate("setTimeout('', 1)"));
48 } 47 }
49 48
50 TEST_F(GlobalJsObjectTest, SetMultipleTimeouts) 49 TEST_F(GlobalJsObjectTest, SetMultipleTimeouts)
51 { 50 {
52 jsEngine->Evaluate("foo = []"); 51 jsEngine->Evaluate("foo = []");
53 jsEngine->Evaluate("setTimeout(function(s) {foo.push('1');}, 100)"); 52 jsEngine->Evaluate("setTimeout(function(s) {foo.push('1');}, 100)");
54 jsEngine->Evaluate("setTimeout(function(s) {foo.push('2');}, 150)"); 53 jsEngine->Evaluate("setTimeout(function(s) {foo.push('2');}, 150)");
55 AdblockPlus::Sleep(200); 54 std::this_thread::sleep_for(std::chrono::milliseconds(200));
56 ASSERT_EQ("1,2", jsEngine->Evaluate("this.foo")->AsString()); 55 ASSERT_EQ("1,2", jsEngine->Evaluate("this.foo")->AsString());
57 } 56 }
OLDNEW
« src/Thread.h ('K') | « test/FilterEngine.cpp ('k') | test/Prefs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld