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

Side by Side Diff: test/GlobalJsObject.cpp

Issue 10310030: Convert references to FileSystem & Co. into shared pointers (avoid use after free) (Closed)
Patch Set: Created April 18, 2013, 11:59 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
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(AdblockPlus::AppInfo(), 0, 0, 0); 8 AdblockPlus::JsEngine jsEngine;
9 jsEngine.Evaluate("setTimeout(function() {foo = 'bar';}, 100)"); 9 jsEngine.Evaluate("setTimeout(function() {foo = 'bar';}, 100)");
10 ASSERT_TRUE(jsEngine.Evaluate("this.foo")->IsUndefined()); 10 ASSERT_TRUE(jsEngine.Evaluate("this.foo")->IsUndefined());
11 AdblockPlus::Sleep(200); 11 AdblockPlus::Sleep(200);
12 ASSERT_EQ("bar", jsEngine.Evaluate("this.foo")->AsString()); 12 ASSERT_EQ("bar", jsEngine.Evaluate("this.foo")->AsString());
13 } 13 }
14 14
15 TEST(GlobalJsObjectTest, SetTimeoutWithArgs) 15 TEST(GlobalJsObjectTest, SetTimeoutWithArgs)
16 { 16 {
17 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, 0); 17 AdblockPlus::JsEngine jsEngine;
18 jsEngine.Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')"); 18 jsEngine.Evaluate("setTimeout(function(s) {foo = s;}, 100, 'foobar')");
19 ASSERT_TRUE(jsEngine.Evaluate("this.foo")->IsUndefined()); 19 ASSERT_TRUE(jsEngine.Evaluate("this.foo")->IsUndefined());
20 AdblockPlus::Sleep(200); 20 AdblockPlus::Sleep(200);
21 ASSERT_EQ("foobar", jsEngine.Evaluate("this.foo")->AsString()); 21 ASSERT_EQ("foobar", jsEngine.Evaluate("this.foo")->AsString());
22 } 22 }
23 23
24 TEST(GlobalJsObjectTest, SetTimeoutWithInvalidArgs) 24 TEST(GlobalJsObjectTest, SetTimeoutWithInvalidArgs)
25 { 25 {
26 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, 0); 26 AdblockPlus::JsEngine jsEngine;
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 } 29 }
30 30
31 TEST(GlobalJsObjectTest, SetMultipleTimeouts) 31 TEST(GlobalJsObjectTest, SetMultipleTimeouts)
32 { 32 {
33 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, 0); 33 AdblockPlus::JsEngine jsEngine;
34 jsEngine.Evaluate("foo = []"); 34 jsEngine.Evaluate("foo = []");
35 jsEngine.Evaluate("setTimeout(function(s) {foo.push('1');}, 100)"); 35 jsEngine.Evaluate("setTimeout(function(s) {foo.push('1');}, 100)");
36 jsEngine.Evaluate("setTimeout(function(s) {foo.push('2');}, 150)"); 36 jsEngine.Evaluate("setTimeout(function(s) {foo.push('2');}, 150)");
37 AdblockPlus::Sleep(200); 37 AdblockPlus::Sleep(200);
38 ASSERT_EQ("1,2", jsEngine.Evaluate("this.foo")->AsString()); 38 ASSERT_EQ("1,2", jsEngine.Evaluate("this.foo")->AsString());
39 } 39 }
OLDNEW
« src/JsEngine.cpp ('K') | « test/FilterEngineStubs.cpp ('k') | test/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld