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 | #include <stdio.h> |
michael@0 | 2 | #include "TestCommon.h" |
michael@0 | 3 | #include "nsNetUtil.h" |
michael@0 | 4 | #include "nsThreadUtils.h" |
michael@0 | 5 | #include "prlog.h" |
michael@0 | 6 | #include "mozilla/Attributes.h" |
michael@0 | 7 | |
michael@0 | 8 | #if defined(PR_LOGGING) |
michael@0 | 9 | // |
michael@0 | 10 | // set NSPR_LOG_MODULES=Test:5 |
michael@0 | 11 | // |
michael@0 | 12 | static PRLogModuleInfo *gTestLog = nullptr; |
michael@0 | 13 | #endif |
michael@0 | 14 | #define LOG(args) PR_LOG(gTestLog, PR_LOG_DEBUG, args) |
michael@0 | 15 | |
michael@0 | 16 | class MyStreamLoaderObserver MOZ_FINAL : public nsIStreamLoaderObserver |
michael@0 | 17 | { |
michael@0 | 18 | public: |
michael@0 | 19 | NS_DECL_ISUPPORTS |
michael@0 | 20 | NS_DECL_NSISTREAMLOADEROBSERVER |
michael@0 | 21 | }; |
michael@0 | 22 | |
michael@0 | 23 | NS_IMPL_ISUPPORTS(MyStreamLoaderObserver, nsIStreamLoaderObserver) |
michael@0 | 24 | |
michael@0 | 25 | NS_IMETHODIMP |
michael@0 | 26 | MyStreamLoaderObserver::OnStreamComplete(nsIStreamLoader *loader, |
michael@0 | 27 | nsISupports *ctxt, |
michael@0 | 28 | nsresult status, |
michael@0 | 29 | uint32_t resultLen, |
michael@0 | 30 | const uint8_t *result) |
michael@0 | 31 | { |
michael@0 | 32 | LOG(("OnStreamComplete [status=%x resultLen=%u]\n", status, resultLen)); |
michael@0 | 33 | |
michael@0 | 34 | nsCOMPtr<nsIRequest> request; |
michael@0 | 35 | loader->GetRequest(getter_AddRefs(request)); |
michael@0 | 36 | LOG((" request=%p\n", request.get())); |
michael@0 | 37 | |
michael@0 | 38 | QuitPumpingEvents(); |
michael@0 | 39 | return NS_OK; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | int main(int argc, char **argv) |
michael@0 | 43 | { |
michael@0 | 44 | if (test_common_init(&argc, &argv) != 0) |
michael@0 | 45 | return -1; |
michael@0 | 46 | |
michael@0 | 47 | if (argc < 2) { |
michael@0 | 48 | printf("usage: %s <url>\n", argv[0]); |
michael@0 | 49 | return -1; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | #if defined(PR_LOGGING) |
michael@0 | 53 | gTestLog = PR_NewLogModule("Test"); |
michael@0 | 54 | #endif |
michael@0 | 55 | |
michael@0 | 56 | nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); |
michael@0 | 57 | if (NS_FAILED(rv)) |
michael@0 | 58 | return -1; |
michael@0 | 59 | |
michael@0 | 60 | { |
michael@0 | 61 | nsCOMPtr<nsIURI> uri; |
michael@0 | 62 | rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(argv[1])); |
michael@0 | 63 | if (NS_FAILED(rv)) |
michael@0 | 64 | return -1; |
michael@0 | 65 | |
michael@0 | 66 | nsCOMPtr<nsIChannel> chan; |
michael@0 | 67 | rv = NS_NewChannel(getter_AddRefs(chan), uri); |
michael@0 | 68 | if (NS_FAILED(rv)) |
michael@0 | 69 | return -1; |
michael@0 | 70 | |
michael@0 | 71 | nsCOMPtr<nsIStreamLoaderObserver> observer = new MyStreamLoaderObserver(); |
michael@0 | 72 | if (!observer) |
michael@0 | 73 | return -1; |
michael@0 | 74 | |
michael@0 | 75 | nsCOMPtr<nsIStreamLoader> loader; |
michael@0 | 76 | rv = NS_NewStreamLoader(getter_AddRefs(loader), observer); |
michael@0 | 77 | if (NS_FAILED(rv)) |
michael@0 | 78 | return -1; |
michael@0 | 79 | |
michael@0 | 80 | rv = chan->AsyncOpen(loader, nullptr); |
michael@0 | 81 | if (NS_FAILED(rv)) |
michael@0 | 82 | return -1; |
michael@0 | 83 | |
michael@0 | 84 | PumpEvents(); |
michael@0 | 85 | } // this scopes the nsCOMPtrs |
michael@0 | 86 | // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM |
michael@0 | 87 | NS_ShutdownXPCOM(nullptr); |
michael@0 | 88 | return 0; |
michael@0 | 89 | } |