| 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 <condition_variable> |
| 22 #include <mutex> |
| 21 #include <thread> | 23 #include <thread> |
| 22 | 24 |
| 23 #include <AdblockPlus.h> | 25 #include <AdblockPlus.h> |
| 24 #include <gtest/gtest.h> | 26 #include <gtest/gtest.h> |
| 25 | 27 |
| 26 class ThrowingLogSystem : public AdblockPlus::LogSystem | 28 class ThrowingLogSystem : public AdblockPlus::LogSystem |
| 27 { | 29 { |
| 28 public: | 30 public: |
| 29 void operator()(LogLevel logLevel, const std::string& message, | 31 void operator()(LogLevel logLevel, const std::string& message, |
| 30 const std::string& source) | 32 const std::string& source) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 114 } |
| 113 return result; | 115 return result; |
| 114 } | 116 } |
| 115 | 117 |
| 116 std::string Resolve(const std::string& path) const | 118 std::string Resolve(const std::string& path) const |
| 117 { | 119 { |
| 118 return path; | 120 return path; |
| 119 } | 121 } |
| 120 }; | 122 }; |
| 121 | 123 |
| 124 class LazyWaiter |
| 125 { |
| 126 std::mutex m; |
| 127 typedef std::unique_lock<std::mutex> UniqueLockType; |
| 128 std::condition_variable cv; |
| 129 bool running; |
| 130 |
| 131 public: |
| 132 LazyWaiter() |
| 133 : running(true) |
| 134 {} |
| 135 |
| 136 void WaitUntilCancelled() |
| 137 { |
| 138 UniqueLockType ul(m); |
| 139 cv.wait(ul, [this]() -> bool { return !running; }); |
| 140 } |
| 141 |
| 142 void Cancel() |
| 143 { |
| 144 UniqueLockType ul(m); |
| 145 running = false; |
| 146 cv.notify_all(); |
| 147 } |
| 148 }; |
| 149 |
| 122 class LazyWebRequest : public AdblockPlus::WebRequest | 150 class LazyWebRequest : public AdblockPlus::WebRequest |
| 123 { | 151 { |
| 152 mutable LazyWaiter w; |
| 153 |
| 124 public: | 154 public: |
| 155 LazyWebRequest() {} // = default; |
| 156 |
| 125 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea
derList& requestHeaders) const | 157 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea
derList& requestHeaders) const |
| 126 { | 158 { |
| 127 while (true) | 159 w.WaitUntilCancelled(); |
| 128 std::this_thread::sleep_for(std::chrono::seconds(100)); | |
| 129 return AdblockPlus::ServerResponse(); | 160 return AdblockPlus::ServerResponse(); |
| 130 } | 161 } |
| 162 |
| 163 void Cancel() |
| 164 { |
| 165 w.Cancel(); |
| 166 } |
| 131 }; | 167 }; |
| 132 | 168 |
| 133 class LazyLogSystem : public AdblockPlus::LogSystem | 169 class LazyLogSystem : public AdblockPlus::LogSystem |
| 134 { | 170 { |
| 135 public: | 171 public: |
| 136 void operator()(LogLevel logLevel, const std::string& message, | 172 void operator()(LogLevel logLevel, const std::string& message, |
| 137 const std::string& source) | 173 const std::string& source) |
| 138 { | 174 { |
| 139 } | 175 } |
| 140 }; | 176 }; |
| 141 | 177 |
| 142 AdblockPlus::JsEnginePtr CreateJsEngine(const AdblockPlus::AppInfo& appInfo = Ad
blockPlus::AppInfo()); | 178 AdblockPlus::JsEnginePtr CreateJsEngine(const AdblockPlus::AppInfo& appInfo = Ad
blockPlus::AppInfo()); |
| 143 | 179 |
| 144 class BaseJsTest : public ::testing::Test | 180 class BaseJsTest : public ::testing::Test |
| 145 { | 181 { |
| 146 protected: | 182 protected: |
| 147 AdblockPlus::JsEnginePtr jsEngine; | 183 AdblockPlus::JsEnginePtr jsEngine; |
| 148 virtual void SetUp(); | 184 virtual void SetUp(); |
| 149 virtual void TearDown(); | 185 virtual void TearDown(); |
| 150 }; | 186 }; |
| 151 | 187 |
| 152 #endif | 188 #endif |
| OLD | NEW |