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

Side by Side Diff: test/ConsoleJsObject.cpp

Issue 10260028: Refactor tests, use fixtures and avoid duplication (Closed)
Patch Set: Created April 19, 2013, 4:11 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
« no previous file with comments | « test/BaseJsTest.h ('k') | test/FileSystemJsObject.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <AdblockPlus.h> 1 #include "BaseJsTest.h"
2 #include <gtest/gtest.h>
3 2
4 class MockErrorCallback : public AdblockPlus::ErrorCallback 3 namespace
5 { 4 {
6 public: 5 class MockErrorCallback : public AdblockPlus::ErrorCallback
7 std::string lastMessage; 6 {
7 public:
8 std::string lastMessage;
8 9
9 void operator()(const std::string& message) 10 void operator()(const std::string& message)
11 {
12 lastMessage = message;
13 }
14 };
15
16 typedef std::tr1::shared_ptr<MockErrorCallback> MockErrorCallbackPtr;
17
18 class ConsoleJsObjectTest : public BaseJsTest
10 { 19 {
11 lastMessage = message; 20 protected:
12 } 21 MockErrorCallbackPtr mockErrorCallback;
13 };
14 22
15 TEST(ConsoleJsObjectTest, ErrorInvokesErrorCallback) 23 void SetUp()
16 { 24 {
17 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); 25 BaseJsTest::SetUp();
18 MockErrorCallback* errorCallback = new MockErrorCallback(); 26 mockErrorCallback = MockErrorCallbackPtr(new MockErrorCallback);
19 jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(errorCallback)); 27 jsEngine->SetErrorCallback(mockErrorCallback);
20 jsEngine->Evaluate("console.error('foo')"); 28 }
21 ASSERT_EQ("foo", errorCallback->lastMessage); 29 };
22 } 30 }
23 31
24 TEST(ConsoleJsObjectTest, ErrorWithMultipleArguments) 32 TEST_F(ConsoleJsObjectTest, ErrorInvokesErrorCallback)
25 { 33 {
26 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); 34 jsEngine->Evaluate("console.error('foo')");
27 MockErrorCallback* errorCallback = new MockErrorCallback(); 35 ASSERT_EQ("foo", mockErrorCallback->lastMessage);
28 jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(errorCallback));
29 jsEngine->Evaluate("console.error('foo', 'bar')");
30 ASSERT_EQ("foobar", errorCallback->lastMessage);
31 } 36 }
32 37
33 TEST(ConsoleJsObjectTest, TraceDoesNothing) 38 TEST_F(ConsoleJsObjectTest, ErrorWithMultipleArguments)
34 { 39 {
35 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); 40 jsEngine->Evaluate("console.error('foo', 'bar')");
41 ASSERT_EQ("foobar", mockErrorCallback->lastMessage);
42 }
43
44 TEST_F(ConsoleJsObjectTest, TraceDoesNothing)
45 {
46 jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCall back));
36 jsEngine->Evaluate("console.trace()"); 47 jsEngine->Evaluate("console.trace()");
37 } 48 }
OLDNEW
« 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