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 runOne() |
| 85 { |
| 86 auto callback = timers.front(); |
| 87 timers.pop(); |
| 88 callback(); |
| 89 } |
| 90 }; |
| 91 |
74 struct DelayedTimerTask | 92 struct DelayedTimerTask |
75 { | 93 { |
76 std::chrono::milliseconds timeout; | 94 std::chrono::milliseconds timeout; |
77 AdblockPlus::ITimer::TimerCallback callback; | 95 AdblockPlus::ITimer::TimerCallback callback; |
78 }; | 96 }; |
79 | 97 |
80 class DelayedTimer : public DelayedMixin<DelayedTimer, DelayedTimerTask, Adblock
Plus::ITimer> | 98 class DelayedTimer : public DelayedMixin<DelayedTimer, DelayedTimerTask, Adblock
Plus::ITimer> |
81 { | 99 { |
82 public: | 100 public: |
83 void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& t
imerCallback) override | 101 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 } | 359 } |
342 | 360 |
343 void TearDown() override | 361 void TearDown() override |
344 { | 362 { |
345 if (platform) | 363 if (platform) |
346 platform.reset(); | 364 platform.reset(); |
347 } | 365 } |
348 }; | 366 }; |
349 | 367 |
350 #endif | 368 #endif |
OLD | NEW |