netwerk/test/TestCommon.h

changeset 1
ca08bd8f51b2
equal deleted inserted replaced
-1:000000000000 0:1beab4776b70
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/. */
4
5 #ifndef TestCommon_h__
6 #define TestCommon_h__
7
8 #include <stdlib.h>
9 #include "nsThreadUtils.h"
10 #include "mozilla/Attributes.h"
11
12 inline int test_common_init(int *argc, char ***argv)
13 {
14 return 0;
15 }
16
17 //-----------------------------------------------------------------------------
18
19 static bool gKeepPumpingEvents = false;
20
21 class nsQuitPumpingEvent MOZ_FINAL : public nsIRunnable {
22 public:
23 NS_DECL_THREADSAFE_ISUPPORTS
24 NS_IMETHOD Run() {
25 gKeepPumpingEvents = false;
26 return NS_OK;
27 }
28 };
29 NS_IMPL_ISUPPORTS(nsQuitPumpingEvent, nsIRunnable)
30
31 static inline void PumpEvents()
32 {
33 nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
34
35 gKeepPumpingEvents = true;
36 while (gKeepPumpingEvents)
37 NS_ProcessNextEvent(thread);
38
39 NS_ProcessPendingEvents(thread);
40 }
41
42 static inline void QuitPumpingEvents()
43 {
44 // Dispatch a task that toggles gKeepPumpingEvents so that we flush all
45 // of the pending tasks before exiting from PumpEvents.
46 nsCOMPtr<nsIRunnable> event = new nsQuitPumpingEvent();
47 NS_DispatchToMainThread(event);
48 }
49
50 #endif

mercurial