Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | #include "TestCommon.h" |
michael@0 | 6 | #include "nsXPCOM.h" |
michael@0 | 7 | #include "nsIServiceManager.h" |
michael@0 | 8 | #include "nsServiceManagerUtils.h" |
michael@0 | 9 | #include "nsIEventTarget.h" |
michael@0 | 10 | #include "nsCOMPtr.h" |
michael@0 | 11 | #include "nsNetCID.h" |
michael@0 | 12 | #include "prlog.h" |
michael@0 | 13 | |
michael@0 | 14 | #if defined(PR_LOGGING) |
michael@0 | 15 | // |
michael@0 | 16 | // set NSPR_LOG_MODULES=Test:5 |
michael@0 | 17 | // |
michael@0 | 18 | static PRLogModuleInfo *gTestLog = nullptr; |
michael@0 | 19 | #endif |
michael@0 | 20 | #define LOG(args) PR_LOG(gTestLog, PR_LOG_DEBUG, args) |
michael@0 | 21 | |
michael@0 | 22 | class nsIOEvent : public nsIRunnable { |
michael@0 | 23 | public: |
michael@0 | 24 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 25 | |
michael@0 | 26 | nsIOEvent(int i) : mIndex(i) {} |
michael@0 | 27 | |
michael@0 | 28 | NS_IMETHOD Run() { |
michael@0 | 29 | LOG(("Run [%d]\n", mIndex)); |
michael@0 | 30 | return NS_OK; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | private: |
michael@0 | 34 | int mIndex; |
michael@0 | 35 | }; |
michael@0 | 36 | NS_IMPL_ISUPPORTS(nsIOEvent, nsIRunnable) |
michael@0 | 37 | |
michael@0 | 38 | static nsresult RunTest() |
michael@0 | 39 | { |
michael@0 | 40 | nsresult rv; |
michael@0 | 41 | nsCOMPtr<nsIEventTarget> target = |
michael@0 | 42 | do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv); |
michael@0 | 43 | if (NS_FAILED(rv)) |
michael@0 | 44 | return rv; |
michael@0 | 45 | |
michael@0 | 46 | for (int i=0; i<10; ++i) { |
michael@0 | 47 | nsCOMPtr<nsIRunnable> event = new nsIOEvent(i); |
michael@0 | 48 | LOG(("Dispatch %d\n", i)); |
michael@0 | 49 | target->Dispatch(event, NS_DISPATCH_NORMAL); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | return NS_OK; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | int main(int argc, char **argv) |
michael@0 | 56 | { |
michael@0 | 57 | if (test_common_init(&argc, &argv) != 0) |
michael@0 | 58 | return -1; |
michael@0 | 59 | |
michael@0 | 60 | nsresult rv; |
michael@0 | 61 | |
michael@0 | 62 | #if defined(PR_LOGGING) |
michael@0 | 63 | gTestLog = PR_NewLogModule("Test"); |
michael@0 | 64 | #endif |
michael@0 | 65 | |
michael@0 | 66 | rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); |
michael@0 | 67 | if (NS_FAILED(rv)) |
michael@0 | 68 | return rv; |
michael@0 | 69 | |
michael@0 | 70 | rv = RunTest(); |
michael@0 | 71 | if (NS_FAILED(rv)) |
michael@0 | 72 | LOG(("RunTest failed [rv=%x]\n", rv)); |
michael@0 | 73 | |
michael@0 | 74 | LOG(("sleeping main thread for 2 seconds...\n")); |
michael@0 | 75 | PR_Sleep(PR_SecondsToInterval(2)); |
michael@0 | 76 | |
michael@0 | 77 | NS_ShutdownXPCOM(nullptr); |
michael@0 | 78 | return 0; |
michael@0 | 79 | } |