michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef TestCommon_h__ michael@0: #define TestCommon_h__ michael@0: michael@0: #include michael@0: #include "nsThreadUtils.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: inline int test_common_init(int *argc, char ***argv) michael@0: { michael@0: return 0; michael@0: } michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: static bool gKeepPumpingEvents = false; michael@0: michael@0: class nsQuitPumpingEvent MOZ_FINAL : public nsIRunnable { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_IMETHOD Run() { michael@0: gKeepPumpingEvents = false; michael@0: return NS_OK; michael@0: } michael@0: }; michael@0: NS_IMPL_ISUPPORTS(nsQuitPumpingEvent, nsIRunnable) michael@0: michael@0: static inline void PumpEvents() michael@0: { michael@0: nsCOMPtr thread = do_GetCurrentThread(); michael@0: michael@0: gKeepPumpingEvents = true; michael@0: while (gKeepPumpingEvents) michael@0: NS_ProcessNextEvent(thread); michael@0: michael@0: NS_ProcessPendingEvents(thread); michael@0: } michael@0: michael@0: static inline void QuitPumpingEvents() michael@0: { michael@0: // Dispatch a task that toggles gKeepPumpingEvents so that we flush all michael@0: // of the pending tasks before exiting from PumpEvents. michael@0: nsCOMPtr event = new nsQuitPumpingEvent(); michael@0: NS_DispatchToMainThread(event); michael@0: } michael@0: michael@0: #endif