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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 <thread> |
| 22 |
21 #include <AdblockPlus.h> | 23 #include <AdblockPlus.h> |
22 #include <gtest/gtest.h> | 24 #include <gtest/gtest.h> |
23 #include "../src/Thread.h" | |
24 | 25 |
25 class ThrowingLogSystem : public AdblockPlus::LogSystem | 26 class ThrowingLogSystem : public AdblockPlus::LogSystem |
26 { | 27 { |
27 public: | 28 public: |
28 void operator()(LogLevel logLevel, const std::string& message, | 29 void operator()(LogLevel logLevel, const std::string& message, |
29 const std::string& source) | 30 const std::string& source) |
30 { | 31 { |
31 throw std::runtime_error("Unexpected error: " + message); | 32 throw std::runtime_error("Unexpected error: " + message); |
32 } | 33 } |
33 }; | 34 }; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 return path; | 118 return path; |
118 } | 119 } |
119 }; | 120 }; |
120 | 121 |
121 class LazyWebRequest : public AdblockPlus::WebRequest | 122 class LazyWebRequest : public AdblockPlus::WebRequest |
122 { | 123 { |
123 public: | 124 public: |
124 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea
derList& requestHeaders) const | 125 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea
derList& requestHeaders) const |
125 { | 126 { |
126 while (true) | 127 while (true) |
127 AdblockPlus::Sleep(100000); | 128 std::this_thread::sleep_for(std::chrono::seconds(100)); |
128 return AdblockPlus::ServerResponse(); | 129 return AdblockPlus::ServerResponse(); |
129 } | 130 } |
130 }; | 131 }; |
131 | 132 |
132 class LazyLogSystem : public AdblockPlus::LogSystem | 133 class LazyLogSystem : public AdblockPlus::LogSystem |
133 { | 134 { |
134 public: | 135 public: |
135 void operator()(LogLevel logLevel, const std::string& message, | 136 void operator()(LogLevel logLevel, const std::string& message, |
136 const std::string& source) | 137 const std::string& source) |
137 { | 138 { |
(...skipping 10 matching lines...) Expand all Loading... |
148 virtual void SetUp() | 149 virtual void SetUp() |
149 { | 150 { |
150 jsEngine = CreateJsEngine(); | 151 jsEngine = CreateJsEngine(); |
151 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new ThrowingLogSystem)); | 152 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new ThrowingLogSystem)); |
152 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new ThrowingFileSystem)); | 153 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new ThrowingFileSystem)); |
153 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new ThrowingWebRequest)); | 154 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new ThrowingWebRequest)); |
154 } | 155 } |
155 }; | 156 }; |
156 | 157 |
157 #endif | 158 #endif |
OLD | NEW |