Bumping manifests a=b2g-bump
[gecko.git] / netwerk / test / TestCommon.h
blobd79748df0d52b0668ee574a675ec82b3160570e3
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef TestCommon_h__
6 #define TestCommon_h__
8 #include <stdlib.h>
9 #include "nsThreadUtils.h"
10 #include "mozilla/Attributes.h"
12 inline int test_common_init(int *argc, char ***argv)
14 return 0;
17 //-----------------------------------------------------------------------------
19 static bool gKeepPumpingEvents = false;
21 class nsQuitPumpingEvent MOZ_FINAL : public nsIRunnable {
22 ~nsQuitPumpingEvent() {}
23 public:
24 NS_DECL_THREADSAFE_ISUPPORTS
25 NS_IMETHOD Run() {
26 gKeepPumpingEvents = false;
27 return NS_OK;
30 NS_IMPL_ISUPPORTS(nsQuitPumpingEvent, nsIRunnable)
32 static inline void PumpEvents()
34 nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
36 gKeepPumpingEvents = true;
37 while (gKeepPumpingEvents)
38 NS_ProcessNextEvent(thread);
40 NS_ProcessPendingEvents(thread);
43 static inline void QuitPumpingEvents()
45 // Dispatch a task that toggles gKeepPumpingEvents so that we flush all
46 // of the pending tasks before exiting from PumpEvents.
47 nsCOMPtr<nsIRunnable> event = new nsQuitPumpingEvent();
48 NS_DispatchToMainThread(event);
51 #endif