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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 <queue> |
21 #include <thread> | 22 #include <thread> |
22 | 23 |
23 #include <AdblockPlus.h> | 24 #include <AdblockPlus.h> |
24 #include <AdblockPlus/Platform.h> | 25 #include <AdblockPlus/Platform.h> |
25 #include <gtest/gtest.h> | 26 #include <gtest/gtest.h> |
26 #include "../src/Thread.h" | 27 #include "../src/Thread.h" |
27 | 28 |
28 // Strictly speaking in each test there should be a special implementation of | 29 // Strictly speaking in each test there should be a special implementation of |
29 // an interface, which is merely referenced by a wrapper and the latter should | 30 // an interface, which is merely referenced by a wrapper and the latter should |
30 // be injected into JsEngine or what ever. However the everthing a test often | 31 // be injected into JsEngine or what ever. However the everthing a test often |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 65 } |
65 }; | 66 }; |
66 | 67 |
67 class NoopTimer : public AdblockPlus::ITimer | 68 class NoopTimer : public AdblockPlus::ITimer |
68 { | 69 { |
69 void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& t
imerCallback) override | 70 void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& t
imerCallback) override |
70 { | 71 { |
71 } | 72 } |
72 }; | 73 }; |
73 | 74 |
| 75 class ManualTimer : public AdblockPlus::ITimer |
| 76 { |
| 77 std::queue<TimerCallback> timers; |
| 78 void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& t
imerCallback) override |
| 79 { |
| 80 timers.push(timerCallback); |
| 81 } |
| 82 |
| 83 public: |
| 84 void runPending() |
| 85 { |
| 86 std::queue<TimerCallback> currentTimers; |
| 87 currentTimers.swap(timers); |
| 88 while (!currentTimers.empty()) { |
| 89 auto callback = currentTimers.front(); |
| 90 currentTimers.pop(); |
| 91 callback(); |
| 92 } |
| 93 } |
| 94 }; |
| 95 |
74 struct DelayedTimerTask | 96 struct DelayedTimerTask |
75 { | 97 { |
76 std::chrono::milliseconds timeout; | 98 std::chrono::milliseconds timeout; |
77 AdblockPlus::ITimer::TimerCallback callback; | 99 AdblockPlus::ITimer::TimerCallback callback; |
78 }; | 100 }; |
79 | 101 |
80 class DelayedTimer : public DelayedMixin<DelayedTimer, DelayedTimerTask, Adblock
Plus::ITimer> | 102 class DelayedTimer : public DelayedMixin<DelayedTimer, DelayedTimerTask, Adblock
Plus::ITimer> |
81 { | 103 { |
82 public: | 104 public: |
83 void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& t
imerCallback) override | 105 void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& t
imerCallback) override |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 363 } |
342 | 364 |
343 void TearDown() override | 365 void TearDown() override |
344 { | 366 { |
345 if (platform) | 367 if (platform) |
346 platform.reset(); | 368 platform.reset(); |
347 } | 369 } |
348 }; | 370 }; |
349 | 371 |
350 #endif | 372 #endif |
OLD | NEW |