2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-10-22 01:22:23 +04:00
|
|
|
|
|
|
|
#ifndef TestCommon_h__
|
|
|
|
#define TestCommon_h__
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "nsThreadUtils.h"
|
2012-06-06 07:18:25 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2004-10-22 01:22:23 +04:00
|
|
|
inline int test_common_init(int *argc, char ***argv)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool gKeepPumpingEvents = false;
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2012-06-06 07:18:25 +04:00
|
|
|
class nsQuitPumpingEvent MOZ_FINAL : public nsIRunnable {
|
2014-06-24 20:36:44 +04:00
|
|
|
~nsQuitPumpingEvent() {}
|
2006-05-10 21:30:15 +04:00
|
|
|
public:
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_IMETHOD Run() {
|
2011-10-17 18:59:28 +04:00
|
|
|
gKeepPumpingEvents = false;
|
2006-05-10 21:30:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsQuitPumpingEvent, nsIRunnable)
|
2006-05-10 21:30:15 +04:00
|
|
|
|
2009-11-18 00:18:05 +03:00
|
|
|
static inline void PumpEvents()
|
2006-05-10 21:30:15 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
gKeepPumpingEvents = true;
|
2006-05-10 21:30:15 +04:00
|
|
|
while (gKeepPumpingEvents)
|
|
|
|
NS_ProcessNextEvent(thread);
|
|
|
|
|
|
|
|
NS_ProcessPendingEvents(thread);
|
|
|
|
}
|
|
|
|
|
2009-11-18 00:18:05 +03:00
|
|
|
static inline void QuitPumpingEvents()
|
2006-05-10 21:30:15 +04:00
|
|
|
{
|
|
|
|
// Dispatch a task that toggles gKeepPumpingEvents so that we flush all
|
|
|
|
// of the pending tasks before exiting from PumpEvents.
|
|
|
|
nsCOMPtr<nsIRunnable> event = new nsQuitPumpingEvent();
|
|
|
|
NS_DispatchToMainThread(event);
|
|
|
|
}
|
|
|
|
|
2004-10-22 01:22:23 +04:00
|
|
|
#endif
|