OLD | NEW |
1 #include <AdblockPlus.h> | 1 #include <AdblockPlus.h> |
2 #include <gtest/gtest.h> | 2 #include <gtest/gtest.h> |
3 | 3 |
4 #include "../src/Thread.h" | 4 #include "../src/Thread.h" |
5 | 5 |
6 TEST(GlobalJsObjectTest, SetTimeout) | 6 TEST(GlobalJsObjectTest, SetTimeout) |
7 { | 7 { |
8 AdblockPlus::JsEngine jsEngine(0, 0, 0); | 8 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, 0); |
9 jsEngine.Evaluate("setTimeout(function() {foo = 'bar';}, 100)"); | 9 jsEngine.Evaluate("setTimeout(function() {foo = 'bar';}, 100)"); |
10 ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo")); | 10 ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo")); |
11 AdblockPlus::Sleep(200); | 11 AdblockPlus::Sleep(200); |
12 ASSERT_EQ("bar", jsEngine.Evaluate("foo")); | 12 ASSERT_EQ("bar", jsEngine.Evaluate("foo")); |
13 } | 13 } |
14 | 14 |
15 TEST(GlobalJsObjectTest, SetTimeoutWithArgs) | 15 TEST(GlobalJsObjectTest, SetTimeoutWithArgs) |
16 { | 16 { |
17 AdblockPlus::JsEngine jsEngine(0, 0, 0); | 17 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, 0); |
18 jsEngine.Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')"); | 18 jsEngine.Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')"); |
19 ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo")); | 19 ASSERT_EQ("undefined", jsEngine.Evaluate("typeof foo")); |
20 AdblockPlus::Sleep(200); | 20 AdblockPlus::Sleep(200); |
21 ASSERT_EQ("foobar", jsEngine.Evaluate("foo")); | 21 ASSERT_EQ("foobar", jsEngine.Evaluate("foo")); |
22 } | 22 } |
23 | 23 |
24 TEST(GlobalJsObjectTest, SetTimeoutWithInvalidArgs) | 24 TEST(GlobalJsObjectTest, SetTimeoutWithInvalidArgs) |
25 { | 25 { |
26 AdblockPlus::JsEngine jsEngine(0, 0, 0); | 26 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, 0); |
27 ASSERT_ANY_THROW(jsEngine.Evaluate("setTimeout()")); | 27 ASSERT_ANY_THROW(jsEngine.Evaluate("setTimeout()")); |
28 ASSERT_ANY_THROW(jsEngine.Evaluate("setTimeout('', 1)")); | 28 ASSERT_ANY_THROW(jsEngine.Evaluate("setTimeout('', 1)")); |
29 ASSERT_ANY_THROW(jsEngine.Evaluate("setTimeout(function(){}, '')")); | 29 ASSERT_ANY_THROW(jsEngine.Evaluate("setTimeout(function(){}, '')")); |
30 } | 30 } |
31 | 31 |
32 TEST(GlobalJsObjectTest, SetMultipleTimeouts) | 32 TEST(GlobalJsObjectTest, SetMultipleTimeouts) |
33 { | 33 { |
34 AdblockPlus::JsEngine jsEngine(0, 0, 0); | 34 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, 0); |
35 jsEngine.Evaluate("foo = []"); | 35 jsEngine.Evaluate("foo = []"); |
36 jsEngine.Evaluate("setTimeout(function(s) {foo.push('1');}, 100)"); | 36 jsEngine.Evaluate("setTimeout(function(s) {foo.push('1');}, 100)"); |
37 jsEngine.Evaluate("setTimeout(function(s) {foo.push('2');}, 150)"); | 37 jsEngine.Evaluate("setTimeout(function(s) {foo.push('2');}, 150)"); |
38 AdblockPlus::Sleep(200); | 38 AdblockPlus::Sleep(200); |
39 ASSERT_EQ("1,2", jsEngine.Evaluate("foo")); | 39 ASSERT_EQ("1,2", jsEngine.Evaluate("foo")); |
40 } | 40 } |
OLD | NEW |