michael@0: #include michael@0: #include "TestCommon.h" michael@0: #include "nsNetUtil.h" michael@0: #include "nsThreadUtils.h" michael@0: #include "prlog.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #if defined(PR_LOGGING) michael@0: // michael@0: // set NSPR_LOG_MODULES=Test:5 michael@0: // michael@0: static PRLogModuleInfo *gTestLog = nullptr; michael@0: #endif michael@0: #define LOG(args) PR_LOG(gTestLog, PR_LOG_DEBUG, args) michael@0: michael@0: class MyStreamLoaderObserver MOZ_FINAL : public nsIStreamLoaderObserver michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSISTREAMLOADEROBSERVER michael@0: }; michael@0: michael@0: NS_IMPL_ISUPPORTS(MyStreamLoaderObserver, nsIStreamLoaderObserver) michael@0: michael@0: NS_IMETHODIMP michael@0: MyStreamLoaderObserver::OnStreamComplete(nsIStreamLoader *loader, michael@0: nsISupports *ctxt, michael@0: nsresult status, michael@0: uint32_t resultLen, michael@0: const uint8_t *result) michael@0: { michael@0: LOG(("OnStreamComplete [status=%x resultLen=%u]\n", status, resultLen)); michael@0: michael@0: nsCOMPtr request; michael@0: loader->GetRequest(getter_AddRefs(request)); michael@0: LOG((" request=%p\n", request.get())); michael@0: michael@0: QuitPumpingEvents(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: if (test_common_init(&argc, &argv) != 0) michael@0: return -1; michael@0: michael@0: if (argc < 2) { michael@0: printf("usage: %s \n", argv[0]); michael@0: return -1; michael@0: } michael@0: michael@0: #if defined(PR_LOGGING) michael@0: gTestLog = PR_NewLogModule("Test"); michael@0: #endif michael@0: michael@0: nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); michael@0: if (NS_FAILED(rv)) michael@0: return -1; michael@0: michael@0: { michael@0: nsCOMPtr uri; michael@0: rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(argv[1])); michael@0: if (NS_FAILED(rv)) michael@0: return -1; michael@0: michael@0: nsCOMPtr chan; michael@0: rv = NS_NewChannel(getter_AddRefs(chan), uri); michael@0: if (NS_FAILED(rv)) michael@0: return -1; michael@0: michael@0: nsCOMPtr observer = new MyStreamLoaderObserver(); michael@0: if (!observer) michael@0: return -1; michael@0: michael@0: nsCOMPtr loader; michael@0: rv = NS_NewStreamLoader(getter_AddRefs(loader), observer); michael@0: if (NS_FAILED(rv)) michael@0: return -1; michael@0: michael@0: rv = chan->AsyncOpen(loader, nullptr); michael@0: if (NS_FAILED(rv)) michael@0: return -1; michael@0: michael@0: PumpEvents(); michael@0: } // this scopes the nsCOMPtrs michael@0: // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM michael@0: NS_ShutdownXPCOM(nullptr); michael@0: return 0; michael@0: }