Index: test/BaseJsTest.h |
=================================================================== |
--- a/test/BaseJsTest.h |
+++ b/test/BaseJsTest.h |
@@ -13,16 +13,17 @@ |
* |
* You should have received a copy of the GNU General Public License |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
#ifndef MOCKS_H |
#define MOCKS_H |
+#include <queue> |
#include <thread> |
#include <AdblockPlus.h> |
#include <AdblockPlus/Platform.h> |
#include <gtest/gtest.h> |
#include "../src/Thread.h" |
// Strictly speaking in each test there should be a special implementation of |
@@ -66,16 +67,37 @@ |
class NoopTimer : public AdblockPlus::ITimer |
{ |
void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& timerCallback) override |
{ |
} |
}; |
+class ManualTimer : public AdblockPlus::ITimer |
+{ |
+ std::queue<TimerCallback> timers; |
+ void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& timerCallback) override |
+ { |
+ timers.push(timerCallback); |
+ } |
+ |
+public: |
+ void runPending() |
+ { |
+ std::queue<TimerCallback> currentTimers; |
+ currentTimers.swap(timers); |
+ while (!currentTimers.empty()) { |
+ auto callback = currentTimers.front(); |
+ currentTimers.pop(); |
+ callback(); |
+ } |
+ } |
+}; |
+ |
struct DelayedTimerTask |
{ |
std::chrono::milliseconds timeout; |
AdblockPlus::ITimer::TimerCallback callback; |
}; |
class DelayedTimer : public DelayedMixin<DelayedTimer, DelayedTimerTask, AdblockPlus::ITimer> |
{ |