2012-05-21 11:12:37 +00: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-21 21:22:23 +00:00
|
|
|
|
|
|
|
#ifndef TestCommon_h__
|
|
|
|
#define TestCommon_h__
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "nsThreadUtils.h"
|
2012-06-06 03:18:25 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2004-10-21 21:22:23 +00:00
|
|
|
inline int test_common_init(int *argc, char ***argv)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool gKeepPumpingEvents = false;
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2012-06-06 03:18:25 +00:00
|
|
|
class nsQuitPumpingEvent MOZ_FINAL : public nsIRunnable {
|
2014-06-24 16:36:44 +00:00
|
|
|
~nsQuitPumpingEvent() {}
|
2006-05-10 17:30:15 +00:00
|
|
|
public:
|
2013-07-19 02:24:13 +00:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_IMETHOD Run() {
|
2011-10-17 14:59:28 +00:00
|
|
|
gKeepPumpingEvents = false;
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsQuitPumpingEvent, nsIRunnable)
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2009-11-17 21:18:05 +00:00
|
|
|
static inline void PumpEvents()
|
2006-05-10 17:30:15 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
gKeepPumpingEvents = true;
|
2006-05-10 17:30:15 +00:00
|
|
|
while (gKeepPumpingEvents)
|
|
|
|
NS_ProcessNextEvent(thread);
|
|
|
|
|
|
|
|
NS_ProcessPendingEvents(thread);
|
|
|
|
}
|
|
|
|
|
2009-11-17 21:18:05 +00:00
|
|
|
static inline void QuitPumpingEvents()
|
2006-05-10 17:30:15 +00: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-21 21:22:23 +00:00
|
|
|
#endif
|