OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 void operator()(AdblockPlus::LogSystem::LogLevel logLevel, | 31 void operator()(AdblockPlus::LogSystem::LogLevel logLevel, |
32 const std::string& message, const std::string& source) | 32 const std::string& message, const std::string& source) |
33 { | 33 { |
34 lastLogLevel = logLevel; | 34 lastLogLevel = logLevel; |
35 lastMessage = message; | 35 lastMessage = message; |
36 lastSource = source; | 36 lastSource = source; |
37 } | 37 } |
38 }; | 38 }; |
39 | 39 |
40 class ConsoleJsObjectTest : public ::testing::Test | 40 class ConsoleJsObjectTest : public BaseJsTest |
41 { | 41 { |
42 protected: | 42 protected: |
43 std::unique_ptr<Platform> platform; | |
44 MockLogSystem* mockLogSystem; | 43 MockLogSystem* mockLogSystem; |
45 JsEnginePtr jsEngine; | |
46 | 44 |
47 void SetUp() override | 45 void SetUp() override |
48 { | 46 { |
49 ThrowingPlatformCreationParameters platformParams; | 47 ThrowingPlatformCreationParameters platformParams; |
50 platformParams.logSystem.reset(mockLogSystem = new MockLogSystem()); | 48 platformParams.logSystem.reset(mockLogSystem = new MockLogSystem()); |
51 platform.reset(new Platform(std::move(platformParams))); | 49 platform.reset(new Platform(std::move(platformParams))); |
52 jsEngine = platform->GetJsEngine(); | |
53 } | 50 } |
54 }; | 51 }; |
55 } | 52 } |
56 | 53 |
57 TEST_F(ConsoleJsObjectTest, ConsoleLogCall) | 54 TEST_F(ConsoleJsObjectTest, ConsoleLogCall) |
58 { | 55 { |
59 jsEngine->Evaluate("\n\nconsole.log('foo', 'bar');\n\n", "eval"); | 56 GetJsEngine().Evaluate("\n\nconsole.log('foo', 'bar');\n\n", "eval"); |
60 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_LOG, mockLogSystem->lastLogLevel); | 57 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_LOG, mockLogSystem->lastLogLevel); |
61 ASSERT_EQ("foo bar", mockLogSystem->lastMessage); | 58 ASSERT_EQ("foo bar", mockLogSystem->lastMessage); |
62 ASSERT_EQ("eval:3", mockLogSystem->lastSource); | 59 ASSERT_EQ("eval:3", mockLogSystem->lastSource); |
63 } | 60 } |
64 | 61 |
65 TEST_F(ConsoleJsObjectTest, ConsoleDebugCall) | 62 TEST_F(ConsoleJsObjectTest, ConsoleDebugCall) |
66 { | 63 { |
67 jsEngine->Evaluate("console.debug('foo', 'bar')"); | 64 GetJsEngine().Evaluate("console.debug('foo', 'bar')"); |
68 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_LOG, mockLogSystem->lastLogLevel); | 65 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_LOG, mockLogSystem->lastLogLevel); |
69 ASSERT_EQ("foo bar", mockLogSystem->lastMessage); | 66 ASSERT_EQ("foo bar", mockLogSystem->lastMessage); |
70 ASSERT_EQ(":1", mockLogSystem->lastSource); | 67 ASSERT_EQ(":1", mockLogSystem->lastSource); |
71 } | 68 } |
72 | 69 |
73 TEST_F(ConsoleJsObjectTest, ConsoleInfoCall) | 70 TEST_F(ConsoleJsObjectTest, ConsoleInfoCall) |
74 { | 71 { |
75 jsEngine->Evaluate("console.info('foo', 'bar')"); | 72 GetJsEngine().Evaluate("console.info('foo', 'bar')"); |
76 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_INFO, mockLogSystem->lastLogLevel)
; | 73 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_INFO, mockLogSystem->lastLogLevel)
; |
77 ASSERT_EQ("foo bar", mockLogSystem->lastMessage); | 74 ASSERT_EQ("foo bar", mockLogSystem->lastMessage); |
78 ASSERT_EQ(":1", mockLogSystem->lastSource); | 75 ASSERT_EQ(":1", mockLogSystem->lastSource); |
79 } | 76 } |
80 | 77 |
81 TEST_F(ConsoleJsObjectTest, ConsoleWarnCall) | 78 TEST_F(ConsoleJsObjectTest, ConsoleWarnCall) |
82 { | 79 { |
83 jsEngine->Evaluate("console.warn('foo', 'bar')"); | 80 GetJsEngine().Evaluate("console.warn('foo', 'bar')"); |
84 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_WARN, mockLogSystem->lastLogLevel)
; | 81 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_WARN, mockLogSystem->lastLogLevel)
; |
85 ASSERT_EQ("foo bar", mockLogSystem->lastMessage); | 82 ASSERT_EQ("foo bar", mockLogSystem->lastMessage); |
86 ASSERT_EQ(":1", mockLogSystem->lastSource); | 83 ASSERT_EQ(":1", mockLogSystem->lastSource); |
87 } | 84 } |
88 | 85 |
89 TEST_F(ConsoleJsObjectTest, ConsoleErrorCall) | 86 TEST_F(ConsoleJsObjectTest, ConsoleErrorCall) |
90 { | 87 { |
91 jsEngine->Evaluate("console.error('foo', 'bar')"); | 88 GetJsEngine().Evaluate("console.error('foo', 'bar')"); |
92 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_ERROR, mockLogSystem->lastLogLevel
); | 89 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_ERROR, mockLogSystem->lastLogLevel
); |
93 ASSERT_EQ("foo bar", mockLogSystem->lastMessage); | 90 ASSERT_EQ("foo bar", mockLogSystem->lastMessage); |
94 ASSERT_EQ(":1", mockLogSystem->lastSource); | 91 ASSERT_EQ(":1", mockLogSystem->lastSource); |
95 } | 92 } |
96 | 93 |
97 TEST_F(ConsoleJsObjectTest, ConsoleTraceCall) | 94 TEST_F(ConsoleJsObjectTest, ConsoleTraceCall) |
98 { | 95 { |
99 jsEngine->Evaluate("\n\ | 96 GetJsEngine().Evaluate("\n\ |
100 function foo()\n\ | 97 function foo()\n\ |
101 {\n\ | 98 {\n\ |
102 (function() {\n\ | 99 (function() {\n\ |
103 console.trace();\n\ | 100 console.trace();\n\ |
104 })();\n\ | 101 })();\n\ |
105 }\n\ | 102 }\n\ |
106 foo();", "eval"); | 103 foo();", "eval"); |
107 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, mockLogSystem->lastLogLevel
); | 104 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, mockLogSystem->lastLogLevel
); |
108 ASSERT_EQ("\ | 105 ASSERT_EQ("\ |
109 1: /* anonymous */() at eval:5\n\ | 106 1: /* anonymous */() at eval:5\n\ |
110 2: foo() at eval:6\n\ | 107 2: foo() at eval:6\n\ |
111 3: /* anonymous */() at eval:8\n", mockLogSystem->lastMessage); | 108 3: /* anonymous */() at eval:8\n", mockLogSystem->lastMessage); |
112 ASSERT_EQ("", mockLogSystem->lastSource); | 109 ASSERT_EQ("", mockLogSystem->lastSource); |
113 } | 110 } |
OLD | NEW |