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

Unified Diff: test/ConsoleJsObject.cpp

Issue 10260028: Refactor tests, use fixtures and avoid duplication (Closed)
Patch Set: Created April 19, 2013, 4:11 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/BaseJsTest.h ('k') | test/FileSystemJsObject.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()");
}
« no previous file with comments | « test/BaseJsTest.h ('k') | test/FileSystemJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld