Index: test/ConsoleJsObject.cpp |
=================================================================== |
--- a/test/ConsoleJsObject.cpp |
+++ b/test/ConsoleJsObject.cpp |
@@ -1,37 +1,48 @@ |
-#include <AdblockPlus.h> |
-#include <gtest/gtest.h> |
+#include "BaseJsTest.h" |
-class MockErrorCallback : public AdblockPlus::ErrorCallback |
+namespace |
{ |
-public: |
- std::string lastMessage; |
+ class MockErrorCallback : public AdblockPlus::ErrorCallback |
+ { |
+ public: |
+ std::string lastMessage; |
- void operator()(const std::string& message) |
+ void operator()(const std::string& message) |
+ { |
+ lastMessage = message; |
+ } |
+ }; |
+ |
+ typedef std::tr1::shared_ptr<MockErrorCallback> MockErrorCallbackPtr; |
+ |
+ class ConsoleJsObjectTest : public BaseJsTest |
{ |
- lastMessage = message; |
- } |
-}; |
+ protected: |
+ MockErrorCallbackPtr mockErrorCallback; |
-TEST(ConsoleJsObjectTest, ErrorInvokesErrorCallback) |
-{ |
- AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); |
- MockErrorCallback* errorCallback = new MockErrorCallback(); |
- jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(errorCallback)); |
- jsEngine->Evaluate("console.error('foo')"); |
- ASSERT_EQ("foo", errorCallback->lastMessage); |
+ void SetUp() |
+ { |
+ BaseJsTest::SetUp(); |
+ mockErrorCallback = MockErrorCallbackPtr(new MockErrorCallback); |
+ jsEngine->SetErrorCallback(mockErrorCallback); |
+ } |
+ }; |
} |
-TEST(ConsoleJsObjectTest, ErrorWithMultipleArguments) |
+TEST_F(ConsoleJsObjectTest, ErrorInvokesErrorCallback) |
{ |
- AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); |
- MockErrorCallback* errorCallback = new MockErrorCallback(); |
- jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(errorCallback)); |
- jsEngine->Evaluate("console.error('foo', 'bar')"); |
- ASSERT_EQ("foobar", errorCallback->lastMessage); |
+ jsEngine->Evaluate("console.error('foo')"); |
+ ASSERT_EQ("foo", mockErrorCallback->lastMessage); |
} |
-TEST(ConsoleJsObjectTest, TraceDoesNothing) |
+TEST_F(ConsoleJsObjectTest, ErrorWithMultipleArguments) |
{ |
- AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); |
+ jsEngine->Evaluate("console.error('foo', 'bar')"); |
+ ASSERT_EQ("foobar", mockErrorCallback->lastMessage); |
+} |
+ |
+TEST_F(ConsoleJsObjectTest, TraceDoesNothing) |
+{ |
+ jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCallback)); |
jsEngine->Evaluate("console.trace()"); |
} |