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

Side by Side Diff: test/ConsoleJsObject.cpp

Issue 29500602: Issue 5450 - introduce the Platform class (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created July 28, 2017, 12:40 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
OLDNEW
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "BaseJsTest.h" 18 #include "BaseJsTest.h"
19 19
20 using namespace AdblockPlus;
21
20 namespace 22 namespace
21 { 23 {
22 class MockLogSystem : public AdblockPlus::LogSystem 24 class MockLogSystem : public AdblockPlus::LogSystem
23 { 25 {
24 public: 26 public:
25 AdblockPlus::LogSystem::LogLevel lastLogLevel; 27 AdblockPlus::LogSystem::LogLevel lastLogLevel;
26 std::string lastMessage; 28 std::string lastMessage;
27 std::string lastSource; 29 std::string lastSource;
28 30
29 void operator()(AdblockPlus::LogSystem::LogLevel logLevel, 31 void operator()(AdblockPlus::LogSystem::LogLevel logLevel,
30 const std::string& message, const std::string& source) 32 const std::string& message, const std::string& source)
31 { 33 {
32 lastLogLevel = logLevel; 34 lastLogLevel = logLevel;
33 lastMessage = message; 35 lastMessage = message;
34 lastSource = source; 36 lastSource = source;
35 } 37 }
36 }; 38 };
37 39
38 class ConsoleJsObjectTest : public BaseJsTest 40 class ConsoleJsObjectTest : public ::testing::Test
39 { 41 {
40 protected: 42 protected:
43 std::unique_ptr<Platform> platform;
41 MockLogSystem* mockLogSystem; 44 MockLogSystem* mockLogSystem;
45 JsEnginePtr jsEngine;
42 46
43 void SetUp() 47 void SetUp() override
44 { 48 {
45 JsEngineCreationParameters jsEngineParams; 49 ThrowingPlatformCreationParameters platformParams;
46 jsEngineParams.logSystem.reset(mockLogSystem = new MockLogSystem()); 50 platformParams.logSystem.reset(mockLogSystem = new MockLogSystem());
47 jsEngine = CreateJsEngine(std::move(jsEngineParams)); 51 platform.reset(new Platform(std::move(platformParams)));
52 jsEngine = platform->GetJsEngine();
48 } 53 }
49 }; 54 };
50 } 55 }
51 56
52 TEST_F(ConsoleJsObjectTest, ConsoleLogCall) 57 TEST_F(ConsoleJsObjectTest, ConsoleLogCall)
53 { 58 {
54 jsEngine->Evaluate("\n\nconsole.log('foo', 'bar');\n\n", "eval"); 59 jsEngine->Evaluate("\n\nconsole.log('foo', 'bar');\n\n", "eval");
55 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_LOG, mockLogSystem->lastLogLevel); 60 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_LOG, mockLogSystem->lastLogLevel);
56 ASSERT_EQ("foo bar", mockLogSystem->lastMessage); 61 ASSERT_EQ("foo bar", mockLogSystem->lastMessage);
57 ASSERT_EQ("eval:3", mockLogSystem->lastSource); 62 ASSERT_EQ("eval:3", mockLogSystem->lastSource);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 })();\n\ 104 })();\n\
100 }\n\ 105 }\n\
101 foo();", "eval"); 106 foo();", "eval");
102 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, mockLogSystem->lastLogLevel ); 107 ASSERT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, mockLogSystem->lastLogLevel );
103 ASSERT_EQ("\ 108 ASSERT_EQ("\
104 1: /* anonymous */() at eval:5\n\ 109 1: /* anonymous */() at eval:5\n\
105 2: foo() at eval:6\n\ 110 2: foo() at eval:6\n\
106 3: /* anonymous */() at eval:8\n", mockLogSystem->lastMessage); 111 3: /* anonymous */() at eval:8\n", mockLogSystem->lastMessage);
107 ASSERT_EQ("", mockLogSystem->lastSource); 112 ASSERT_EQ("", mockLogSystem->lastSource);
108 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld