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

Unified Diff: test/ConsoleJsObject.cpp

Issue 10524054: Rename ErrorCallback into LogSystem, provide a proper console API (Closed)
Patch Set: Created May 10, 2013, 2:01 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
Index: test/ConsoleJsObject.cpp
===================================================================
--- a/test/ConsoleJsObject.cpp
+++ b/test/ConsoleJsObject.cpp
@@ -14,52 +14,97 @@
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
#include "BaseJsTest.h"
namespace
{
- class MockErrorCallback : public AdblockPlus::ErrorCallback
+ class MockLogSystem : public AdblockPlus::LogSystem
{
public:
+ AdblockPlus::LogSystem::LogLevel lastLogLevel;
std::string lastMessage;
+ std::string lastSource;
- void operator()(const std::string& message)
+ void operator()(AdblockPlus::LogSystem::LogLevel logLevel,
+ const std::string& message, const std::string& source)
{
+ lastLogLevel = logLevel;
lastMessage = message;
+ lastSource = source;
}
};
- typedef std::tr1::shared_ptr<MockErrorCallback> MockErrorCallbackPtr;
+ typedef std::tr1::shared_ptr<MockLogSystem> MockLogSystemPtr;
class ConsoleJsObjectTest : public BaseJsTest
{
protected:
- MockErrorCallbackPtr mockErrorCallback;
+ MockLogSystemPtr mockLogSystem;
void SetUp()
{
BaseJsTest::SetUp();
- mockErrorCallback = MockErrorCallbackPtr(new MockErrorCallback);
- jsEngine->SetErrorCallback(mockErrorCallback);
+ mockLogSystem = MockLogSystemPtr(new MockLogSystem);
+ jsEngine->SetLogSystem(mockLogSystem);
}
};
}
-TEST_F(ConsoleJsObjectTest, ErrorInvokesErrorCallback)
+TEST_F(ConsoleJsObjectTest, ConsoleLogCall)
{
- jsEngine->Evaluate("console.error('foo')");
- ASSERT_EQ("foo", mockErrorCallback->lastMessage);
+ jsEngine->Evaluate("\n\nconsole.log('foo', 'bar');\n\n", "eval");
+ ASSERT_EQ(AdblockPlus::LogSystem::LOG, mockLogSystem->lastLogLevel);
+ ASSERT_EQ("foo bar", mockLogSystem->lastMessage);
+ ASSERT_EQ("eval:3", mockLogSystem->lastSource);
}
-TEST_F(ConsoleJsObjectTest, ErrorWithMultipleArguments)
+TEST_F(ConsoleJsObjectTest, ConsoleDebugCall)
+{
+ jsEngine->Evaluate("console.debug('foo', 'bar')");
+ ASSERT_EQ(AdblockPlus::LogSystem::LOG, mockLogSystem->lastLogLevel);
+ ASSERT_EQ("foo bar", mockLogSystem->lastMessage);
+ ASSERT_EQ(":1", mockLogSystem->lastSource);
+}
+
+TEST_F(ConsoleJsObjectTest, ConsoleInfoCall)
+{
+ jsEngine->Evaluate("console.info('foo', 'bar')");
+ ASSERT_EQ(AdblockPlus::LogSystem::INFO, mockLogSystem->lastLogLevel);
+ ASSERT_EQ("foo bar", mockLogSystem->lastMessage);
+ ASSERT_EQ(":1", mockLogSystem->lastSource);
+}
+
+TEST_F(ConsoleJsObjectTest, ConsoleWarnCall)
+{
+ jsEngine->Evaluate("console.warn('foo', 'bar')");
+ ASSERT_EQ(AdblockPlus::LogSystem::WARN, mockLogSystem->lastLogLevel);
+ ASSERT_EQ("foo bar", mockLogSystem->lastMessage);
+ ASSERT_EQ(":1", mockLogSystem->lastSource);
+}
+
+TEST_F(ConsoleJsObjectTest, ConsoleErrorCall)
{
jsEngine->Evaluate("console.error('foo', 'bar')");
- ASSERT_EQ("foobar", mockErrorCallback->lastMessage);
+ ASSERT_EQ(AdblockPlus::LogSystem::ERROR, mockLogSystem->lastLogLevel);
+ ASSERT_EQ("foo bar", mockLogSystem->lastMessage);
+ ASSERT_EQ(":1", mockLogSystem->lastSource);
}
-TEST_F(ConsoleJsObjectTest, TraceDoesNothing)
+TEST_F(ConsoleJsObjectTest, ConsoleTraceCall)
{
- jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCallback));
- jsEngine->Evaluate("console.trace()");
+ jsEngine->Evaluate("\n\
+ function foo()\n\
+ {\n\
+ (function() {\n\
+ console.trace();\n\
+ })();\n\
+ }\n\
+ foo();", "eval");
+ ASSERT_EQ(AdblockPlus::LogSystem::TRACE, mockLogSystem->lastLogLevel);
+ ASSERT_EQ("\
+1: /* anonymous */() at eval:5\n\
+2: foo() at eval:6\n\
+3: /* anonymous */() at eval:8\n", mockLogSystem->lastMessage);
+ ASSERT_EQ("", mockLogSystem->lastSource);
}
« include/AdblockPlus/LogSystem.h ('K') | « test/BaseJsTest.h ('k') | test/FilterEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld