Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/BaseJsTest.h

Issue 29539858: Issue 5506 - Make the notification test work. (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Address review comments. Created Sept. 12, 2017, 12:53 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/Notification.cpp » ('j') | test/Notification.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
{
« no previous file with comments | « no previous file | test/Notification.cpp » ('j') | test/Notification.cpp » ('J')

Powered by Google App Engine
This is Rietveld