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); |
} |