Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef TestCommon_h__ |
michael@0 | 6 | #define TestCommon_h__ |
michael@0 | 7 | |
michael@0 | 8 | #include <stdlib.h> |
michael@0 | 9 | #include "nsThreadUtils.h" |
michael@0 | 10 | #include "mozilla/Attributes.h" |
michael@0 | 11 | |
michael@0 | 12 | inline int test_common_init(int *argc, char ***argv) |
michael@0 | 13 | { |
michael@0 | 14 | return 0; |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | //----------------------------------------------------------------------------- |
michael@0 | 18 | |
michael@0 | 19 | static bool gKeepPumpingEvents = false; |
michael@0 | 20 | |
michael@0 | 21 | class nsQuitPumpingEvent MOZ_FINAL : public nsIRunnable { |
michael@0 | 22 | public: |
michael@0 | 23 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 24 | NS_IMETHOD Run() { |
michael@0 | 25 | gKeepPumpingEvents = false; |
michael@0 | 26 | return NS_OK; |
michael@0 | 27 | } |
michael@0 | 28 | }; |
michael@0 | 29 | NS_IMPL_ISUPPORTS(nsQuitPumpingEvent, nsIRunnable) |
michael@0 | 30 | |
michael@0 | 31 | static inline void PumpEvents() |
michael@0 | 32 | { |
michael@0 | 33 | nsCOMPtr<nsIThread> thread = do_GetCurrentThread(); |
michael@0 | 34 | |
michael@0 | 35 | gKeepPumpingEvents = true; |
michael@0 | 36 | while (gKeepPumpingEvents) |
michael@0 | 37 | NS_ProcessNextEvent(thread); |
michael@0 | 38 | |
michael@0 | 39 | NS_ProcessPendingEvents(thread); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | static inline void QuitPumpingEvents() |
michael@0 | 43 | { |
michael@0 | 44 | // Dispatch a task that toggles gKeepPumpingEvents so that we flush all |
michael@0 | 45 | // of the pending tasks before exiting from PumpEvents. |
michael@0 | 46 | nsCOMPtr<nsIRunnable> event = new nsQuitPumpingEvent(); |
michael@0 | 47 | NS_DispatchToMainThread(event); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | #endif |