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

Side by Side Diff: test/BaseJsTest.h

Issue 29433591: Issue 5180 - start to inject implementation of WebRequest into JsEngine::ctr (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created May 8, 2017, 11:59 a.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 | « no previous file | test/BaseJsTest.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 /* 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 #ifndef MOCKS_H 18 #ifndef MOCKS_H
19 #define MOCKS_H 19 #define MOCKS_H
20 20
21 #include <AdblockPlus.h> 21 #include <AdblockPlus.h>
22 #include <gtest/gtest.h> 22 #include <gtest/gtest.h>
23 #include "../src/Thread.h" 23 #include "../src/Thread.h"
24 24
25 class ThrowingTimer : public AdblockPlus::ITimer
26 {
27 void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& t imerCallback) override
28 {
29 throw std::runtime_error("Unexpected timer: " + std::to_string(timeout.count ()));
30 }
31 };
32
33 class NoopTimer : public AdblockPlus::ITimer
34 {
35 void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& t imerCallback) override
36 {
37 }
38 };
39
25 class ThrowingLogSystem : public AdblockPlus::LogSystem 40 class ThrowingLogSystem : public AdblockPlus::LogSystem
26 { 41 {
27 public: 42 public:
28 void operator()(LogLevel logLevel, const std::string& message, 43 void operator()(LogLevel logLevel, const std::string& message,
29 const std::string& source) 44 const std::string& source)
30 { 45 {
31 throw std::runtime_error("Unexpected error: " + message); 46 throw std::runtime_error("Unexpected error: " + message);
32 } 47 }
33 }; 48 };
34 49
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 { 141 {
127 public: 142 public:
128 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea derList& requestHeaders) const 143 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea derList& requestHeaders) const
129 { 144 {
130 while (true) 145 while (true)
131 AdblockPlus::Sleep(100000); 146 AdblockPlus::Sleep(100000);
132 return AdblockPlus::ServerResponse(); 147 return AdblockPlus::ServerResponse();
133 } 148 }
134 }; 149 };
135 150
151 class NoopWebRequest : public AdblockPlus::IWebRequest
152 {
153 public:
154 void GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders , const GetCallback& callback) override
155 {
156 }
157 };
158
136 class LazyLogSystem : public AdblockPlus::LogSystem 159 class LazyLogSystem : public AdblockPlus::LogSystem
137 { 160 {
138 public: 161 public:
139 void operator()(LogLevel logLevel, const std::string& message, 162 void operator()(LogLevel logLevel, const std::string& message,
140 const std::string& source) 163 const std::string& source)
141 { 164 {
142 } 165 }
143 }; 166 };
144 167
145 AdblockPlus::JsEnginePtr CreateJsEngine(const AdblockPlus::AppInfo& appInfo = Ad blockPlus::AppInfo(), 168 struct JsEngineCreationParameters
146 AdblockPlus::WebRequestPtr webRequest = AdblockPlus::WebRequestPtr(new Throwin gWebRequest())); 169 {
170 JsEngineCreationParameters();
171
172 AdblockPlus::AppInfo appInfo;
173 AdblockPlus::LogSystemPtr logSystem;
174 AdblockPlus::TimerPtr timer;
175 AdblockPlus::WebRequestPtr webRequest;
176 AdblockPlus::FileSystemPtr fileSystem;
177 };
178
179 AdblockPlus::JsEnginePtr CreateJsEngine(JsEngineCreationParameters&& jsEngineCre ationParameters = JsEngineCreationParameters());
147 180
148 class BaseJsTest : public ::testing::Test 181 class BaseJsTest : public ::testing::Test
149 { 182 {
150 protected: 183 protected:
151 AdblockPlus::JsEnginePtr jsEngine; 184 AdblockPlus::JsEnginePtr jsEngine;
152 185
153 virtual void SetUp() 186 virtual void SetUp()
154 { 187 {
155 jsEngine = CreateJsEngine(); 188 jsEngine = CreateJsEngine();
156 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new ThrowingLogSystem));
157 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new ThrowingFileSystem));
158 jsEngine->SetWebRequest(std::make_shared<ThrowingWebRequest>());
159 } 189 }
160 }; 190 };
161 191
162 #endif 192 #endif
OLDNEW
« no previous file with comments | « no previous file | test/BaseJsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld