From 943d34a148e4308a19e27d3c701f257d8dcde274 Mon Sep 17 00:00:00 2001 From: Christoph Kerschbaumer Date: Wed, 14 Jan 2015 11:52:57 -0800 Subject: [PATCH] Bug 1119006 - Remove files where code is still calling removed NS_OpenURI API (r=mcmanus) --- editor/libeditor/nsHTMLURIRefObject.cpp | 26 -- netwerk/test/TestHttp.cpp | 2 +- netwerk/test/TestPageLoad.cpp | 398 ------------------------ netwerk/test/TestPerf.cpp | 273 ---------------- netwerk/test/TestProtocols.cpp | 2 +- netwerk/test/TestSyncHTTP.cpp | 111 ------- netwerk/test/TestThreadedIO.cpp | 290 ----------------- netwerk/test/moz.build | 2 - xpcom/tests/CvtURL.cpp | 95 ------ 9 files changed, 2 insertions(+), 1197 deletions(-) delete mode 100644 netwerk/test/TestPageLoad.cpp delete mode 100644 netwerk/test/TestPerf.cpp delete mode 100644 netwerk/test/TestSyncHTTP.cpp delete mode 100644 netwerk/test/TestThreadedIO.cpp delete mode 100644 xpcom/tests/CvtURL.cpp diff --git a/editor/libeditor/nsHTMLURIRefObject.cpp b/editor/libeditor/nsHTMLURIRefObject.cpp index 16e1f0c859b..643a53639f7 100644 --- a/editor/libeditor/nsHTMLURIRefObject.cpp +++ b/editor/libeditor/nsHTMLURIRefObject.cpp @@ -39,32 +39,6 @@ q: cite */ -/* Here is how to open a channel for testing - (from embed/qa/testembed/Tests.cpp): - - nsCOMPtr theChannel; - nsCString uri; - nsCOMPtr theURI; - rv = NS_NewURI(getter_AddRefs(theURI), theSpec); - if (!theURI) - error; - rv = NS_OpenURI(getter_AddRefs(theChannel), theURI, nullptr, theLoadGroup); - if (!theChannel) - error; - nsCOMPtr theLoadGroup(do_CreateInstance(NS_LOADGROUP_CONTRACTID)); - if (!theLoadGroup) - error; - nsCOMPtr listener(static_cast(qaBrowserImpl)); - //nsCOMPtr thisListener(do_GetWeakReference(listener)); - //qaWebBrowser->AddWebBrowserListener(thisListener, NS_GET_IID(nsIStreamListener)); - - // this calls nsIStreamListener::OnDataAvailable() - rv = theChannel->AsyncOpen(listener, nullptr); - - nsCOMPtr theRequest = do_QueryInterface(theChannel); - // Now we can do things on nsIRequest (like what?) - */ - #include "nsHTMLURIRefObject.h" #include "mozilla/mozalloc.h" diff --git a/netwerk/test/TestHttp.cpp b/netwerk/test/TestHttp.cpp index 21fb33c00aa..3bb87592ce9 100644 --- a/netwerk/test/TestHttp.cpp +++ b/netwerk/test/TestHttp.cpp @@ -171,7 +171,7 @@ int main(int argc, char **argv) nsILoadInfo::SEC_NORMAL, nsIContentPolicy::TYPE_OTHER); - RETURN_IF_FAILED(rv, "NS_OpenURI"); + RETURN_IF_FAILED(rv, "NS_NewChannel"); rv = chan->AsyncOpen(listener, nullptr); RETURN_IF_FAILED(rv, "AsyncOpen"); diff --git a/netwerk/test/TestPageLoad.cpp b/netwerk/test/TestPageLoad.cpp deleted file mode 100644 index fe5002a2019..00000000000 --- a/netwerk/test/TestPageLoad.cpp +++ /dev/null @@ -1,398 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "TestCommon.h" -#include "nsNetUtil.h" -#include "nsIServiceManager.h" -#include "nsIInterfaceRequestor.h" -#include "nsIInterfaceRequestorUtils.h" -#include "nsIProgressEventSink.h" -#include "nsIComponentManager.h" -#include "prprf.h" -#include "nsXPCOM.h" -#include "nsISupportsPrimitives.h" -#include "plstr.h" -#include "nsCOMArray.h" -#include "nsIComponentRegistrar.h" -#include -#include "nsIScriptSecurityManager.h" - -namespace TestPageLoad { - -int getStrLine(const char *src, char *str, int ind, int max); -nsresult auxLoad(char *uriBuf); -//---------------------------------------------------------------------- - - -#define RETURN_IF_FAILED(rv, ret, step) \ - PR_BEGIN_MACRO \ - if (NS_FAILED(rv)) { \ - printf(">>> %s failed: rv=%x\n", step, static_cast(rv)); \ - return ret;\ - } \ - PR_END_MACRO - -static nsCString globalStream; -//static char urlBuf[256]; -static nsCOMPtr baseURI; -static nsCOMArray uriList; - -//Temp, should remove: -static int numStart=0; -static int numFound=0; - -static int32_t gKeepRunning = 0; - - -//--------writer fun---------------------- - -static NS_METHOD streamParse (nsIInputStream* in, - void* closure, - const char* fromRawSegment, - uint32_t toOffset, - uint32_t count, - uint32_t *writeCount) { - - char parseBuf[2048], loc[2048], lineBuf[2048]; - char *loc_t, *loc_t2; - int i = 0; - const char *tmp; - - if(!globalStream.IsEmpty()) { - globalStream.Append(fromRawSegment); - tmp = globalStream.get(); - //printf("\n>>NOW:\n^^^^^\n%s\n^^^^^^^^^^^^^^", tmp); - } else { - tmp = fromRawSegment; - } - - while(i < (int)count) { - i = getStrLine(tmp, lineBuf, i, count); - if(i < 0) { - *writeCount = count; - return NS_OK; - } - parseBuf[0]='\0'; - if((loc_t=PL_strcasestr(lineBuf, "img"))!= nullptr - || (loc_t=PL_strcasestr(lineBuf, "script"))!=nullptr) { - loc_t2=PL_strcasestr(loc_t, "src"); - if(loc_t2!=nullptr) { - loc_t2+=3; - strcpy(loc, loc_t2); - sscanf(loc, "=\"%[^\"]", parseBuf); - if(parseBuf[0]=='\0') - sscanf(loc, "=%s", parseBuf); - if(parseBuf[0]!='\0'){ - numFound++; - auxLoad(parseBuf); - } - } - } - - /***NEED BETTER CHECK FOR STYLESHEETS - if((loc_t=PL_strcasestr(lineBuf, "link"))!= nullptr) { - loc_t2=PL_strcasestr(loc_t, "href"); - if(loc_t2!=nullptr) { - loc_t2+=4; - strcpy(loc, loc_t2); - //printf("%s\n", loc); - sscanf(loc, "=\"%[^\"]", parseBuf); - if(parseBuf[0]!='\0'){ - //printf("%s\n", parseBuf); - numFound++; - auxLoad(parseBuf); - } - } - } - */ - if((loc_t=PL_strcasestr(lineBuf, "background"))!=nullptr) { - loc_t+=10; - strcpy(loc, loc_t); - sscanf(loc, "=\"%[^\"]", parseBuf); - if(parseBuf[0]!='\0') { - numFound++; - auxLoad(parseBuf); - } - } - i++; - - } - *writeCount = count; - return NS_OK; -} - -//----------------------------------------------------------------------------- -// nsIStreamListener implementation -//----------------------------------------------------------------------------- - -class MyListener : public nsIStreamListener -{ - virtual ~MyListener() {} - -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIREQUESTOBSERVER - NS_DECL_NSISTREAMLISTENER - - MyListener() { } -}; - -NS_IMPL_ISUPPORTS(MyListener, - nsIRequestObserver, - nsIStreamListener) - -NS_IMETHODIMP -MyListener::OnStartRequest(nsIRequest *req, nsISupports *ctxt) -{ - //printf(">>> OnStartRequest\n"); - numStart++; - return NS_OK; -} - -NS_IMETHODIMP -MyListener::OnStopRequest(nsIRequest *req, nsISupports *ctxt, nsresult status) -{ - //printf(">>> OnStopRequest status=%x\n", status); - if (--gKeepRunning == 0) - QuitPumpingEvents(); - return NS_OK; -} - -NS_IMETHODIMP -MyListener::OnDataAvailable(nsIRequest *req, nsISupports *ctxt, - nsIInputStream *stream, - uint64_t offset, uint32_t count) -{ - //printf(">>> OnDataAvailable [count=%u]\n", count); - nsresult rv = NS_ERROR_FAILURE; - uint32_t bytesRead=0; - char buf[1024]; - - if(ctxt == nullptr) { - bytesRead=0; - rv = stream->ReadSegments(streamParse, nullptr, count, &bytesRead); - } else { - while (count) { - uint32_t amount = std::min(count, sizeof(buf)); - rv = stream->Read(buf, amount, &bytesRead); - count -= bytesRead; - } - } - - if (NS_FAILED(rv)) { - printf(">>> stream->Read failed with rv=%x\n", - static_cast(rv)); - return rv; - } - - return NS_OK; -} - -//----------------------------------------------------------------------------- -// NotificationCallbacks implementation -//----------------------------------------------------------------------------- - -class MyNotifications : public nsIInterfaceRequestor - , public nsIProgressEventSink -{ - virtual ~MyNotifications() {} - -public: - NS_DECL_THREADSAFE_ISUPPORTS - NS_DECL_NSIINTERFACEREQUESTOR - NS_DECL_NSIPROGRESSEVENTSINK - - MyNotifications() { } -}; - -NS_IMPL_ISUPPORTS(MyNotifications, - nsIInterfaceRequestor, - nsIProgressEventSink) - -NS_IMETHODIMP -MyNotifications::GetInterface(const nsIID &iid, void **result) -{ - return QueryInterface(iid, result); -} - -NS_IMETHODIMP -MyNotifications::OnStatus(nsIRequest *req, nsISupports *ctx, - nsresult status, const char16_t *statusText) -{ - //printf("status: %x\n", status); - return NS_OK; -} - -NS_IMETHODIMP -MyNotifications::OnProgress(nsIRequest *req, nsISupports *ctx, - uint64_t progress, uint64_t progressMax) -{ - // char buf[100]; - // PR_snprintf(buf, sizeof(buf), "%llu/%llu\n", progress, progressMax); - // printf("%s", buf); - return NS_OK; -} - -//----------------------------------------------------------------------------- -// main, etc.. -//----------------------------------------------------------------------------- - -//---------getStrLine Helper function--------------- -//Finds a newline in src starting at ind. Puts the -//line in str (must be big enough). Returns the index -//of the newline, or -1 if at end of string. If reaches -//end of string ('\0'), then will copy contents to -//globalStream. -int getStrLine(const char *src, char *str, int ind, int max) { - char c = src[ind]; - int i=0; - globalStream.Assign('\0'); - while(c!='\n' && c!='\0' && i myBool = do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID); - - nsCOMPtr uri; - nsCOMPtr chan; - nsCOMPtr listener = new MyListener(); - nsCOMPtr callbacks = new MyNotifications(); - - printf("Getting: %s", uriBuf); - - //If relative link - if(strncmp(uriBuf, "http:", 5)) { - //Relative link - rv = NS_NewURI(getter_AddRefs(uri), uriBuf, baseURI); - if (NS_FAILED(rv)) return(rv); - } else { - //Absolute link, no base needed - rv = NS_NewURI(getter_AddRefs(uri), uriBuf); - if (NS_FAILED(rv)) return(rv); - } - - //Compare to see if exists - bool equal; - for(int32_t i = 0; i < uriList.Count(); i++) { - uri->Equals(uriList[i], &equal); - if(equal) { - printf("(duplicate, canceling) %s\n",uriBuf); - return NS_OK; - } - } - printf("\n"); - uriList.AppendObject(uri); - - nsCOMPtr secman = - do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - RETURN_IF_FAILED(rv, rv, "Couldn't get script security manager!"); - nsCOMPtr systemPrincipal; - rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal)); - RETURN_IF_FAILED(rv, rv, "Couldn't get system principal!"); - - rv = NS_NewChannel(getter_AddRefs(chan), - uri, - systemPrincipal, - nsILoadInfo::SEC_NORMAL, - nsIContentPolicy::TYPE_OTHER, - nullptr, // loadGroup - callbacks); - - RETURN_IF_FAILED(rv, rv, "NS_NewChannel"); - - gKeepRunning++; - rv = chan->AsyncOpen(listener, myBool); - RETURN_IF_FAILED(rv, rv, "AsyncOpen"); - - return NS_OK; - -} - -//---------Buffer writer fun--------- - -} // namespace - -using namespace TestPageLoad; - -//---------MAIN----------- - -int main(int argc, char **argv) -{ - if (test_common_init(&argc, &argv) != 0) - return -1; - - nsresult rv; - - if (argc == 1) { - printf("usage: TestPageLoad \n"); - return -1; - } - { - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr); - - PRTime start, finish; - - printf("Loading necko ... \n"); - nsCOMPtr chan; - nsCOMPtr listener = new MyListener(); - nsCOMPtr callbacks = new MyNotifications(); - - rv = NS_NewURI(getter_AddRefs(baseURI), argv[1]); - RETURN_IF_FAILED(rv, -1, "NS_NewURI"); - - nsCOMPtr secman = - do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - RETURN_IF_FAILED(rv, -1, "Couldn't get script security manager!"); - nsCOMPtr systemPrincipal; - rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal)); - RETURN_IF_FAILED(rv, -1, "Couldn't get system principal!"); - - rv = NS_NewChannel(getter_AddRefs(chan), - baseURI, - systemPrincipal, - nsILoadInfo::SEC_NORMAL, - nsIContentPolicy::TYPE_OTHER, - nullptr, // loadGroup - callbacks); - - RETURN_IF_FAILED(rv, -1, "NS_OpenURI"); - gKeepRunning++; - - //TIMER STARTED----------------------- - printf("Starting clock ... \n"); - start = PR_Now(); - rv = chan->AsyncOpen(listener, nullptr); - RETURN_IF_FAILED(rv, -1, "AsyncOpen"); - - PumpEvents(); - - finish = PR_Now(); - uint32_t totalTime32 = uint32_t(finish - start); - - printf("\n\n--------------------\nAll done:\nnum found:%d\nnum start:%d\n", numFound, numStart); - - printf("\n\n>>PageLoadTime>>%u>>\n\n", totalTime32); - } // this scopes the nsCOMPtrs - // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM - rv = NS_ShutdownXPCOM(nullptr); - NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); - return 0; -} diff --git a/netwerk/test/TestPerf.cpp b/netwerk/test/TestPerf.cpp deleted file mode 100644 index e5ebfbfbf0f..00000000000 --- a/netwerk/test/TestPerf.cpp +++ /dev/null @@ -1,273 +0,0 @@ -#include "TestCommon.h" -#include -#include "nsCRT.h" /* should be "plstr.h"? */ -#include "nsNetUtil.h" -#include "nsIServiceManager.h" -#include "nsIComponentRegistrar.h" -#include "nsISupportsArray.h" -#include "nsContentUtils.h" -#include - -namespace TestPerf { - -static nsIIOService *gIOService = nullptr; - -//----------------------------------------------------------------------------- - -static bool -load_sync_1(nsISupports *element, void *data) -{ - nsCOMPtr stream; - nsCOMPtr uri( do_QueryInterface(element) ); - nsAutoCString spec; - nsresult rv; - - rv = NS_OpenURI(getter_AddRefs(stream), - uri, - nsContentUtils::GetSystemPrincipal(), - nsILoadInfo::SEC_NORMAL, - nsIContentPolicy::TYPE_OTHER, - nullptr, // aLoadGroup - nullptr, // aCallbacks - LOAD_NORMAL, - gIOService); - - if (NS_FAILED(rv)) { - uri->GetAsciiSpec(spec); - fprintf(stderr, "*** failed opening %s [rv=%x]\n", spec.get(), rv); - return true; - } - - char buf[4096]; - uint32_t bytesRead; - - while (1) { - rv = stream->Read(buf, sizeof(buf), &bytesRead); - if (NS_FAILED(rv) || bytesRead == 0) { - if (NS_FAILED(rv)) { - uri->GetAsciiSpec(spec); - fprintf(stderr, "*** failed reading %s [rv=%x]\n", spec.get(), rv); - } - break; - } - } - - return true; -} - -static nsresult -load_sync(nsISupportsArray *urls) -{ - urls->EnumerateForwards(load_sync_1, nullptr); - return NS_OK; -} - -//----------------------------------------------------------------------------- - -static int gRequestCount = 0; - -class MyListener : public nsIStreamListener -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIREQUESTOBSERVER - NS_DECL_NSISTREAMLISTENER - - MyListener() { } - virtual ~MyListener() {} -}; - -NS_IMPL_ISUPPORTS(MyListener, nsIStreamListener, nsIRequestObserver) - -NS_IMETHODIMP -MyListener::OnStartRequest(nsIRequest *req, nsISupports *ctx) -{ - return NS_OK; -} - -NS_IMETHODIMP -MyListener::OnDataAvailable(nsIRequest *req, nsISupports *ctx, - nsIInputStream *stream, - uint64_t offset, uint32_t count) -{ - nsresult rv; - char buf[4096]; - uint32_t n, bytesRead; - while (count) { - n = std::min(count, sizeof(buf)); - rv = stream->Read(buf, n, &bytesRead); - if (NS_FAILED(rv)) - break; - count -= bytesRead; - if (bytesRead == 0) - break; - } - return NS_OK; -} - -NS_IMETHODIMP -MyListener::OnStopRequest(nsIRequest *req, nsISupports *ctx, nsresult status) -{ - if (NS_FAILED(status)) { - nsAutoCString spec; - req->GetName(spec); - fprintf(stderr, "*** failed loading %s [reason=%x]\n", spec.get(), status); - } - if (--gRequestCount == 0) { - // post shutdown event - QuitPumpingEvents(); - } - return NS_OK; -} - -static bool -load_async_1(nsISupports *element, void *data) -{ - nsCOMPtr uri( do_QueryInterface(element) ); - if (!uri) - return true; - - MyListener *listener = new MyListener(); - if (!listener) - return true; - NS_ADDREF(listener); - - nsresult rv = NS_OpenURI(listener, - nullptr, // aContext - uri, - nsContentUtils::GetSystemPrincipal(), - nsILoadInfo::SEC_NORMAL, - nsIContentPolicy::TYPE_OTHER, - nullptr, // aLoadGroup - nullptr, // aCallbacks - gIOService); - - NS_RELEASE(listener); - if (NS_SUCCEEDED(rv)) - gRequestCount++; - else - printf(">> NS_OpenURI failed [rv=%x]\n", rv); - return true; -} - -static nsresult -load_async(nsISupportsArray *urls) -{ - urls->EnumerateForwards(load_async_1, nullptr); - - PumpEvents(); - return NS_OK; -} - -//----------------------------------------------------------------------------- - -static nsresult -read_file(const char *fname, nsISupportsArray *urls) -{ - FILE *fp = fopen(fname, "r"); - if (!fp) { - printf("failed opening file: %s\n", fname); - return NS_ERROR_FAILURE; - } - - nsCOMPtr uri; - nsresult rv; - char buf[512]; - while (fgets(buf, sizeof(buf), fp)) { - // remove trailing newline - buf[strlen(buf) - 1] = 0; - rv = NS_NewURI(getter_AddRefs(uri), buf, nullptr, gIOService); - if (NS_FAILED(rv)) - printf("*** ignoring malformed uri: %s\n", buf); - else { - //nsXPIDLCString spec; - //uri->GetSpec(getter_Copies(spec)); - //printf("read url: %s\n", spec.get()); - urls->AppendElement(uri); - } - } - - fclose(fp); - return NS_OK; -} - -//----------------------------------------------------------------------------- - -static void -print_usage() -{ - printf("usage: TestPerf [-sync|-async] \n"); -} - -} // namespace - -using namespace TestPerf; - -int -main(int argc, char **argv) -{ - if (test_common_init(&argc, &argv) != 0) - return -1; - - nsresult rv; - bool sync; - - if (argc < 3) { - print_usage(); - return -1; - } - - if (PL_strcasecmp(argv[1], "-sync") == 0) - sync = true; - else if (PL_strcasecmp(argv[1], "-async") == 0) - sync = false; - else { - print_usage(); - return -1; - } - - nsCOMPtr servMan; - NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr); - nsCOMPtr registrar = do_QueryInterface(servMan); - NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); - registrar->AutoRegister(nullptr); - - // cache the io service - { - nsCOMPtr ioserv( do_GetIOService() ); - NS_ADDREF(gIOService = ioserv); - } - - nsCOMPtr urls; - rv = NS_NewISupportsArray(getter_AddRefs(urls)); - if (NS_FAILED(rv)) return -1; - - rv = read_file(argv[2], urls); - if (NS_FAILED(rv)) { - printf("failed reading file-of-urls\n"); - return -1; - } - - uint32_t urlCount; - urls->Count(&urlCount); - - PRIntervalTime start = PR_IntervalNow(); - - if (sync) - rv = load_sync(urls); - else - rv = load_async(urls); - - if (NS_FAILED(rv)) { - printf("load failed\n"); - return -1; - } - - PRIntervalTime end = PR_IntervalNow(); - fprintf(stderr, "read: %u urls; total time: %u milliseconds\n", - urlCount, - PR_IntervalToMilliseconds(end - start)); - - NS_RELEASE(gIOService); - return 0; -} diff --git a/netwerk/test/TestProtocols.cpp b/netwerk/test/TestProtocols.cpp index 17e07040a1f..e355c007cd4 100644 --- a/netwerk/test/TestProtocols.cpp +++ b/netwerk/test/TestProtocols.cpp @@ -649,7 +649,7 @@ nsresult StartLoadingURL(const char* aUrlString) NS_RELEASE(callbacks); if (NS_FAILED(rv)) { - LOG(("ERROR: NS_OpenURI failed for %s [rv=%x]\n", aUrlString, rv)); + LOG(("ERROR: NS_NewChannel failed for %s [rv=%x]\n", aUrlString, rv)); return rv; } diff --git a/netwerk/test/TestSyncHTTP.cpp b/netwerk/test/TestSyncHTTP.cpp deleted file mode 100644 index 8a6f8dfffa2..00000000000 --- a/netwerk/test/TestSyncHTTP.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include -#include -#include -#include -#include -#include -#include "nsContentUtils.h" -#include - -/* - * Test synchronous HTTP. - */ - -#define RETURN_IF_FAILED(rv, what) \ - PR_BEGIN_MACRO \ - if (NS_FAILED(rv)) { \ - printf(what ": failed - %08x\n", rv); \ - return -1; \ - } \ - PR_END_MACRO - -struct TestContext { - nsCOMPtr uri; - nsCOMPtr channel; - nsCOMPtr inputStream; - PRTime t1, t2; - uint32_t bytesRead, totalRead; - - TestContext() - : t1(0), t2(0), bytesRead(0), totalRead(0) - { printf("TestContext [this=%p]\n", (void*)this); } - ~TestContext() - { printf("~TestContext [this=%p]\n", (void*)this); } -}; - -int -main(int argc, char **argv) -{ - nsresult rv; - TestContext *c; - int i, nc=0, npending=0; - char buf[256]; - - if (argc < 2) { - printf("Usage: TestSyncHTTP \n"); - return -1; - } - - c = new TestContext[argc-1]; - - for (i=0; i<(argc-1); ++i, ++nc) { - rv = NS_NewURI(getter_AddRefs(c[i].uri), argv[i+1]); - RETURN_IF_FAILED(rv, "NS_NewURI"); - - rv = NS_OpenURI(getter_AddRefs(c[i].channel, - c[i].uri, - nsContentUtils::GetSystemPrincipal(), - nsILoadInfo::SEC_NORMAL, - nsIContentPolicy::TYPE_OTHER); - - RETURN_IF_FAILED(rv, "NS_OpenURI"); - - nsCOMPtr httpChannel = do_QueryInterface(c[i].channel); - if (httpChannel) - httpChannel->SetOpenHasEventQueue(false); - - // initialize these fields for reading - c[i].bytesRead = 1; - c[i].totalRead = 0; - } - - for (i=0; iOpen(getter_AddRefs(c[i].inputStream)); - RETURN_IF_FAILED(rv, "nsIChannel::OpenInputStream"); - } - - npending = nc; - while (npending) { - for (i=0; i 0) { - rv = c[i].inputStream->Read(buf, sizeof buf, &c[i].bytesRead); - RETURN_IF_FAILED(rv, "nsIInputStream::Read"); - c[i].totalRead += c[i].bytesRead; - - if (c[i].bytesRead == 0) { - c[i].t2 = PR_Now(); - printf("finished GET of: %s\n", argv[i+1]); - printf("total read: %u bytes\n", c[i].totalRead); - printf("total read time: %0.3f\n", - ((double) (c[i].t2 - c[i].t1))/1000000.0); - npending--; - } - } - } - } - - delete[] c; - - NS_ShutdownXPCOM(nullptr); - return 0; -} diff --git a/netwerk/test/TestThreadedIO.cpp b/netwerk/test/TestThreadedIO.cpp deleted file mode 100644 index c20e90cc5df..00000000000 --- a/netwerk/test/TestThreadedIO.cpp +++ /dev/null @@ -1,290 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include -#include "nsCOMPtr.h" -#include "nsIEventQueueService.h" -#include "nsIServiceManager.h" -#include "nsIStreamListener.h" -#include "nsIURI.h" -#include "nsNetUtil.h" -#include "nsContentUtils.h" -#include -//#include "prthread.h" - -// This test attempts to load a URL on a separate thread. It is currently -// designed simply to expose the problems inherent in such an ambitous task -// (i.e., it don't work). - -// Utility functions... - -// Create event queue for current thread. -static nsCOMPtr -createEventQueue() { - nsCOMPtr result; - // Get event queue service. - nsresult rv = NS_OK; - nsCOMPtr eqs = - do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv); - if ( NS_SUCCEEDED( rv ) ) { - eqs->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(result)); - } else { - printf( "%s %d: NS_WITH_SERVICE(nsIEventQueueService) failed, rv=0x%08X\n", - (char*)__FILE__, (int)__LINE__, (int)rv ); - } - return result; -} - -// Create channel for requested URL. -static nsCOMPtr -createChannel( const char *url ) { - nsCOMPtr result; - - nsCOMPtr uri; - printf( "Calling NS_NewURI for %s...\n", url ); - nsresult rv = NS_NewURI( getter_AddRefs( uri ), url ); - - if ( NS_SUCCEEDED( rv ) ) { - printf( "...NS_NewURI completed OK\n" ); - - // Allocate a new input channel on this thread. - printf( "Calling NS_OpenURI...\n" ); - - nsresult rv = NS_OpenURI(getter_AddRefs(result), - uri, - nsContentUtils::GetSystemPrincipal(), - nsILoadInfo::SEC_NORMAL, - nsIContentPolicy::TYPE_OTHER); - - if ( NS_SUCCEEDED( rv ) ) { - printf( "...NS_OpenURI completed OK\n" ); - } else { - printf( "%s %d: NS_OpenURI failed, rv=0x%08X\n", - (char*)__FILE__, (int)__LINE__, (int)rv ); - } - } else { - printf( "%s %d: NS_NewURI failed, rv=0x%08X\n", - (char*)__FILE__, (int)__LINE__, (int)rv ); - } - return result; -} - -// Test listener. It basically dumps incoming data to console. -class TestListener : public nsIStreamListener { -public: - NS_DECL_ISUPPORTS - NS_DECL_NSISTREAMLISTENER - NS_DECL_NSISTREAMOBSERVER - - TestListener(); - ~TestListener(); - static void IOThread( void *p ); - -private: - bool mDone; - int mThreadNo; - FILE *mFile; - static int threadCount; -}; // class TestListener - -int TestListener::threadCount = 0; - -TestListener::TestListener() - : mDone( false ), mThreadNo( ++threadCount ) { - printf( "TestListener ctor called on thread %d\n", mThreadNo ); -} - -TestListener::~TestListener() { - printf( "TestListener dtor called on thread %d\n", mThreadNo ); -} - -NS_IMPL_ISUPPORTS( TestListener, nsIStreamListener, nsIRequestObserver ) - -NS_IMETHODIMP -TestListener::OnStartRequest( nsIChannel *aChannel, nsISupports *aContext ) { - nsresult rv = NS_OK; - - printf( "TestListener::OnStartRequest called on thread %d\n", mThreadNo ); - - // Open output file. - char fileName[32]; - sprintf( fileName, "%s%d", "thread", mThreadNo ); - mFile = fopen( fileName, "wb" ); - setbuf( mFile, 0 ); - - return rv; -} - -NS_IMETHODIMP -TestListener::OnStopRequest( nsIChannel *aChannel, - nsISupports *aContext, - nsresult aStatus, - const char16_t *aMsg ) { - nsresult rv = NS_OK; - - printf( "TestListener::OnStopRequest called on thread %d\n", mThreadNo ); - - fclose( mFile ); - mDone = true; - - return rv; -} - -NS_IMETHODIMP -TestListener::OnDataAvailable( nsIChannel *aChannel, - nsISupports *aContext, - nsIInputStream *aStream, - uint64_t offset, - uint32_t aLength ) { - nsresult rv = NS_OK; - - printf( "TestListener::OnDataAvailable called on thread %d\n", mThreadNo ); - - // Write the data to the console. - // Read a buffer full till aLength bytes have been processed. - char buffer[ 8192 ]; - unsigned long bytesRemaining = aLength; - while ( bytesRemaining ) { - unsigned int bytesRead; - // Read a buffer full or the number remaining (whichever is smaller). - rv = aStream->Read( buffer, - std::min( sizeof( buffer ), bytesRemaining ), - &bytesRead ); - if ( NS_SUCCEEDED( rv ) ) { - // Write the bytes just read to the output file. - fwrite( buffer, 1, bytesRead, mFile ); - bytesRemaining -= bytesRead; - } else { - printf( "%s %d: Read error, rv=0x%08X\n", - (char*)__FILE__, (int)__LINE__, (int)rv ); - break; - } - } - printf( "\n" ); - - return rv; -} - -// IOThread: this function creates a new TestListener object (on the new -// thread), opens a channel, and does AsyncRead to it. -void -TestListener::IOThread( void *p ) { - printf( "I/O thread (0x%08X) started...\n", (int)(void*)PR_GetCurrentThread() ); - - // Argument is pointer to the nsIEventQueue for the main thread. - nsIEventQueue *mainThreadQ = static_cast(p); - - // Create channel for random web page. - nsCOMPtr channel = createChannel( (const char*)p ); - - if ( channel ) { - // Create event queue. - nsCOMPtr ioEventQ = createEventQueue(); - - if ( ioEventQ ) { - // Create test listener. - TestListener *testListener = new TestListener(); - testListener->AddRef(); - - // Read the channel. - printf( "Doing AsyncRead...\n" ); - nsresult rv = channel->AsyncRead( testListener, 0 ); - - if ( NS_SUCCEEDED( rv ) ) { - printf( "...AsyncRead completed OK\n" ); - - // Process events till testListener says stop. - printf( "Start event loop on io thread %d...\n", testListener->mThreadNo ); - while ( !testListener->mDone ) { - PLEvent *event; - ioEventQ->GetEvent( &event ); - ioEventQ->HandleEvent( event ); - } - printf( "...io thread %d event loop exiting\n", testListener->mThreadNo ); - } else { - printf( "%s %d: AsyncRead failed on thread %d, rv=0x%08X\n", - (char*)__FILE__, (int)__LINE__, testListener->mThreadNo, (int)rv ); - } - - // Release the test listener. - testListener->Release(); - } - } - - printf( "...I/O thread terminating\n" ); -} - -static const int maxThreads = 5; - -int -main( int argc, char* argv[] ) { - setbuf( stdout, 0 ); - if ( argc < 2 || argc > maxThreads + 1 ) { - printf( "usage: testThreadedIO url1 ...\n" - "where is a location to be loaded on a separate thread\n" - "limit is %d urls/threads", maxThreads ); - return -1; - } - - nsresult rv= (nsresult)-1; - - printf( "Test starting...\n" ); - - // Initialize XPCOM. - printf( "Initializing XPCOM...\n" ); - rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); - if ( NS_FAILED( rv ) ) { - printf( "%s %d: NS_InitXPCOM failed, rv=0x%08X\n", - (char*)__FILE__, (int)__LINE__, (int)rv ); - return rv; - } - printf( "...XPCOM initialized OK\n" ); - // Create the Event Queue for this thread... - printf( "Creating event queue for main thread (0x%08X)...\n", - (int)(void*)PR_GetCurrentThread() ); - { - nsCOMPtr mainThreadQ = createEventQueue(); - - if ( mainThreadQ ) { - printf( "...main thread's event queue created OK\n" ); - - // Spawn threads to do I/O. - int goodThreads = 0; - PRThread *thread[ maxThreads ]; - for ( int threadNo = 1; threadNo < argc; threadNo++ ) { - printf( "Creating I/O thread %d to load %s...\n", threadNo, argv[threadNo] ); - PRThread *ioThread = PR_CreateThread( PR_USER_THREAD, - TestListener::IOThread, - argv[threadNo], - PR_PRIORITY_NORMAL, - PR_GLOBAL_THREAD, - PR_JOINABLE_THREAD, - 0 ); - if ( ioThread ) { - thread[ goodThreads++ ] = ioThread; - printf( "...I/O thread %d (0x%08X) created OK\n", - threadNo, (int)(void*)ioThread ); - } else { - printf( "%s %d: PR_CreateThread for thread %d failed\n", - (char*)__FILE__, (int)__LINE__, threadNo ); - } - } - - // Wait for all the threads to terminate. - for ( int joinThread = 0; joinThread < goodThreads; joinThread++ ) { - printf( "Waiting for thread %d to terminate...\n", joinThread+1 ); - PR_JoinThread( thread[ joinThread ] ); - } - } - } // this scopes the nsCOMPtrs - // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM - // Shut down XPCOM. - printf( "Shutting down XPCOM...\n" ); - NS_ShutdownXPCOM( 0 ); - printf( "...XPCOM shutdown complete\n" ); - - // Exit. - printf( "...test complete, rv=0x%08X\n", (int)rv ); - return rv; -} diff --git a/netwerk/test/moz.build b/netwerk/test/moz.build index d0b9a673d27..c180b31c1f7 100644 --- a/netwerk/test/moz.build +++ b/netwerk/test/moz.build @@ -24,7 +24,6 @@ GeckoSimplePrograms([ 'TestDNS', 'TestIncrementalDownload', 'TestOpen', - 'TestPageLoad', 'TestProtocols', 'TestServ', 'TestStandardURL', @@ -38,7 +37,6 @@ GeckoSimplePrograms([ #SIMPLE_PROGRAMS += [ # TestIDN', # TestIOThreads', -# TestPerf', # TestSocketTransport', # TestStreamChannel', # TestStreamPump', diff --git a/xpcom/tests/CvtURL.cpp b/xpcom/tests/CvtURL.cpp deleted file mode 100644 index df2cd03f707..00000000000 --- a/xpcom/tests/CvtURL.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include -#include "nscore.h" -#include "nsIConverterInputStream.h" -#include "nsIURL.h" -#include "nsNetUtil.h" -#include "nsCRT.h" -#include "nsString.h" -#include "prprf.h" -#include "prtime.h" - -static nsString* ConvertCharacterSetName(const char* aName) -{ - return new nsString(NS_ConvertASCIItoUTF16(aName)); -} - -int main(int argc, char** argv) -{ - if (3 != argc) { - printf("usage: CvtURL url utf8\n"); - return -1; - } - - char* characterSetName = argv[2]; - nsString* cset = ConvertCharacterSetName(characterSetName); - if (NS_PTR_TO_INT32(cset) < 0) { - printf("illegal character set name: '%s'\n", characterSetName); - return -1; - } - - // Create url object - char* urlName = argv[1]; - nsIURI* url; - nsresult rv; - rv = NS_NewURI(&url, urlName); - if (NS_OK != rv) { - printf("invalid URL: '%s'\n", urlName); - return -1; - } - - // Get an input stream from the url - nsIInputStream* in; - nsresult ec = NS_OpenURI(&in, - url, - nsContentUtils::GetSystemPrincipal(), - nsILoadInfo::SEC_NORMAL, - nsIContentPolicy::TYPE_OTHER); - - if (nullptr == in) { - printf("open of url('%s') failed: error=%x\n", urlName, ec); - return -1; - } - - // Translate the input using the argument character set id into - // unicode - nsCOMPtr uin = - do_CreateInstance("@mozilla.org/intl/converter-input-stream;1", &rv); - if (NS_SUCCEEDED(rv)) - rv = uin->Init(in, cset->get(), 4096); - if (NS_FAILED(rv)) { - printf("can't create converter input stream: %d\n", rv); - return -1; - } - - // Read the input and write some output - PRTime start = PR_Now(); - int32_t count = 0; - for (;;) { - char16_t buf[1000]; - uint32_t nb; - ec = uin->Read(buf, 0, 1000, &nb); - if (NS_FAILED(ec)) { - printf("i/o error: %d\n", ec); - break; - } - if (nb == 0) break; // EOF - count += nb; - } - PRTime end = PR_Now(); - PRTime conversion = (end - start) / 1000; - char buf[500]; - PR_snprintf(buf, sizeof(buf), - "converting and discarding %d bytes took %lldms", - count, conversion); - puts(buf); - - // Release the objects - in->Release(); - url->Release(); - - return 0; -}