1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/TestCommon.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,50 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef TestCommon_h__ 1.9 +#define TestCommon_h__ 1.10 + 1.11 +#include <stdlib.h> 1.12 +#include "nsThreadUtils.h" 1.13 +#include "mozilla/Attributes.h" 1.14 + 1.15 +inline int test_common_init(int *argc, char ***argv) 1.16 +{ 1.17 + return 0; 1.18 +} 1.19 + 1.20 +//----------------------------------------------------------------------------- 1.21 + 1.22 +static bool gKeepPumpingEvents = false; 1.23 + 1.24 +class nsQuitPumpingEvent MOZ_FINAL : public nsIRunnable { 1.25 +public: 1.26 + NS_DECL_THREADSAFE_ISUPPORTS 1.27 + NS_IMETHOD Run() { 1.28 + gKeepPumpingEvents = false; 1.29 + return NS_OK; 1.30 + } 1.31 +}; 1.32 +NS_IMPL_ISUPPORTS(nsQuitPumpingEvent, nsIRunnable) 1.33 + 1.34 +static inline void PumpEvents() 1.35 +{ 1.36 + nsCOMPtr<nsIThread> thread = do_GetCurrentThread(); 1.37 + 1.38 + gKeepPumpingEvents = true; 1.39 + while (gKeepPumpingEvents) 1.40 + NS_ProcessNextEvent(thread); 1.41 + 1.42 + NS_ProcessPendingEvents(thread); 1.43 +} 1.44 + 1.45 +static inline void QuitPumpingEvents() 1.46 +{ 1.47 + // Dispatch a task that toggles gKeepPumpingEvents so that we flush all 1.48 + // of the pending tasks before exiting from PumpEvents. 1.49 + nsCOMPtr<nsIRunnable> event = new nsQuitPumpingEvent(); 1.50 + NS_DispatchToMainThread(event); 1.51 +} 1.52 + 1.53 +#endif