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

Side by Side Diff: test/ConsoleJsObject.cpp

Issue 10173031: Don`t use references to JsEngine to avoid use-after-free errors,switch to shared_ptr instead (Closed)
Patch Set: Created April 18, 2013, 4:15 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 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <gtest/gtest.h> 2 #include <gtest/gtest.h>
3 3
4 class MockErrorCallback : public AdblockPlus::ErrorCallback 4 class MockErrorCallback : public AdblockPlus::ErrorCallback
5 { 5 {
6 public: 6 public:
7 std::string lastMessage; 7 std::string lastMessage;
8 8
9 void operator()(const std::string& message) 9 void operator()(const std::string& message)
10 { 10 {
11 lastMessage = message; 11 lastMessage = message;
12 } 12 }
13 }; 13 };
14 14
15 TEST(ConsoleJsObjectTest, ErrorInvokesErrorCallback) 15 TEST(ConsoleJsObjectTest, ErrorInvokesErrorCallback)
16 { 16 {
17 AdblockPlus::JsEngine jsEngine; 17 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
18 MockErrorCallback* errorCallback = new MockErrorCallback(); 18 MockErrorCallback* errorCallback = new MockErrorCallback();
19 jsEngine.SetErrorCallback(AdblockPlus::ErrorCallbackPtr(errorCallback)); 19 jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(errorCallback));
20 jsEngine.Evaluate("console.error('foo')"); 20 jsEngine->Evaluate("console.error('foo')");
21 ASSERT_EQ("foo", errorCallback->lastMessage); 21 ASSERT_EQ("foo", errorCallback->lastMessage);
22 } 22 }
23 23
24 TEST(ConsoleJsObjectTest, ErrorWithMultipleArguments) 24 TEST(ConsoleJsObjectTest, ErrorWithMultipleArguments)
25 { 25 {
26 AdblockPlus::JsEngine jsEngine; 26 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
27 MockErrorCallback* errorCallback = new MockErrorCallback(); 27 MockErrorCallback* errorCallback = new MockErrorCallback();
28 jsEngine.SetErrorCallback(AdblockPlus::ErrorCallbackPtr(errorCallback)); 28 jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(errorCallback));
29 jsEngine.Evaluate("console.error('foo', 'bar')"); 29 jsEngine->Evaluate("console.error('foo', 'bar')");
30 ASSERT_EQ("foobar", errorCallback->lastMessage); 30 ASSERT_EQ("foobar", errorCallback->lastMessage);
31 } 31 }
32 32
33 TEST(ConsoleJsObjectTest, TraceDoesNothing) 33 TEST(ConsoleJsObjectTest, TraceDoesNothing)
34 { 34 {
35 AdblockPlus::JsEngine jsEngine; 35 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
36 jsEngine.Evaluate("console.trace()"); 36 jsEngine->Evaluate("console.trace()");
37 } 37 }
OLDNEW
« src/JsEngine.cpp ('K') | « test/AppInfoJsObject.cpp ('k') | test/FileSystemJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld