Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
TestPageLoad.cpp File Reference
#include "TestCommon.h"
#include "nsNetUtil.h"
#include "nsIEventQueueService.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 "nsTimer.h"
#include "prlong.h"
#include "plstr.h"
#include "nsSupportsArray.h"
#include "nsReadableUtils.h"
#include "nsIComponentRegistrar.h"

Go to the source code of this file.

Classes

class  MyListener
class  MyNotifications

Defines

#define RETURN_IF_FAILED(rv, step)

Functions

int getStrLine (const char *src, char *str, int ind, int max)
nsresult auxLoad (char *uriBuf)
static NS_DEFINE_CID (kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID)
static NS_METHOD streamParse (nsIInputStream *in, void *closure, const char *fromRawSegment, PRUint32 toOffset, PRUint32 count, PRUint32 *writeCount)
 NS_IMPL_ISUPPORTS2 (MyListener, nsIRequestObserver, nsIStreamListener) NS_IMETHODIMP MyListener
 NS_IMPL_THREADSAFE_ISUPPORTS2 (MyNotifications, nsIInterfaceRequestor, nsIProgressEventSink) NS_IMETHODIMP MyNotifications
int main (int argc, char **argv)
 The Xalan testcases app.

Variables

static nsIEventQueuegEventQ = nsnull
static PRBool gKeepRunning = PR_FALSE
static nsCString globalStream
static nsCOMPtr< nsIURIbaseURI
static nsCOMPtr< nsISupportsArrayuriList
static int numStart = 0
static int numFound = 0

Define Documentation

#define RETURN_IF_FAILED (   rv,
  step 
)
Value:
PR_BEGIN_MACRO \
    if (NS_FAILED(rv)) { \
        printf(">>> %s failed: rv=%x\n", step, rv); \
        return rv;\
    } \
    PR_END_MACRO

Definition at line 60 of file TestPageLoad.cpp.


Function Documentation

nsresult auxLoad ( char *  uriBuf)

Definition at line 295 of file TestPageLoad.cpp.

{
    nsresult rv;

    nsCOMPtr<nsISupportsPRBool> myBool = do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID);

    nsCOMPtr<nsIURI> uri;
    nsCOMPtr<nsIChannel> chan;
    nsCOMPtr<nsIStreamListener> listener = new MyListener();
    nsCOMPtr<nsIInterfaceRequestor> 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
    PRUint32 num;
    uriList->Count(&num);
    PRBool equal;
    nsCOMPtr<nsIURI> uriTmp;
    for(PRUint32 i = 0; i < num; i++) {
      uriList->GetElementAt(i, getter_AddRefs(uriTmp));
      uri->Equals(uriTmp, &equal);
      if(equal) {
        printf("(duplicate, canceling) %s\n",uriBuf); 
        return NS_OK;
      }
    }
    printf("\n");
    uriList->AppendElement(uri);
    rv = NS_NewChannel(getter_AddRefs(chan), uri, nsnull, nsnull, callbacks);
    RETURN_IF_FAILED(rv, "NS_NewChannel");

    gKeepRunning++;
    rv = chan->AsyncOpen(listener, myBool);
    RETURN_IF_FAILED(rv, "AsyncOpen");

    return NS_OK;

}

Here is the call graph for this function:

Here is the caller graph for this function:

int getStrLine ( const char *  src,
char *  str,
int  ind,
int  max 
)

Definition at line 276 of file TestPageLoad.cpp.

                                                             {
  char c = src[ind];
  int i=0;
  globalStream.AssignLiteral("\0");
  while(c!='\n' && c!='\0' && i<max) {
    str[i] = src[ind];
    i++; ind++;
    c = src[ind];
  }
  str[i]='\0';
  if(i==max || c=='\0') {
    globalStream.Assign(str);
    //printf("\nCarryover (%d|%d):\n------------\n%s\n-------\n",i,max,str);
    return -1;
  }
  return ind;
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 350 of file TestPageLoad.cpp.

{ 
    if (test_common_init(&argc, &argv) != 0)
        return -1;

    nsresult rv;

    if (argc == 1) {
        printf("usage: TestPageLoad <url>\n");
        return -1;
    }
    {
        nsCOMPtr<nsIServiceManager> servMan;
        NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
        nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
        NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
        if (registrar)
            registrar->AutoRegister(nsnull);

        PRTime start, finish;

        rv = NS_NewISupportsArray(getter_AddRefs(uriList));
        RETURN_IF_FAILED(rv, "NS_NewISupportsArray");

        // Create the Event Queue for this thread...
        nsCOMPtr<nsIEventQueueService> eqs =
                 do_GetService(kEventQueueServiceCID, &rv);
        RETURN_IF_FAILED(rv, "do_GetService(EventQueueService)");

        rv = eqs->CreateMonitoredThreadEventQueue();
        RETURN_IF_FAILED(rv, "CreateMonitoredThreadEventQueue");

        rv = eqs->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
        RETURN_IF_FAILED(rv, "GetThreadEventQueue");

        printf("Loading necko ... \n");
        nsCOMPtr<nsIChannel> chan;
        nsCOMPtr<nsIStreamListener> listener = new MyListener();
        nsCOMPtr<nsIInterfaceRequestor> callbacks = new MyNotifications();

        rv = NS_NewURI(getter_AddRefs(baseURI), argv[1]);
        RETURN_IF_FAILED(rv, "NS_NewURI");

        rv = NS_NewChannel(getter_AddRefs(chan), baseURI, nsnull, nsnull, callbacks);
        RETURN_IF_FAILED(rv, "NS_OpenURI");
        gKeepRunning++;

        //TIMER STARTED-----------------------
        printf("Starting clock ... \n");
        start = PR_Now();
        rv = chan->AsyncOpen(listener, nsnull);
        RETURN_IF_FAILED(rv, "AsyncOpen");

        while (gKeepRunning) {
            gEventQ->ProcessPendingEvents();
        }

        finish = PR_Now();
        PRUint32 totalTime32;
        PRUint64 totalTime64;
        LL_SUB(totalTime64, finish, start);
        LL_L2UI(totalTime32, totalTime64);

        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(nsnull);
    NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
    return 0;
}

Here is the call graph for this function:

Definition at line 173 of file TestPageLoad.cpp.

{
  //printf(">>> OnStartRequest\n");
    numStart++;
    return NS_OK;
}

Definition at line 238 of file TestPageLoad.cpp.

{
    return QueryInterface(iid, result);
}
static NS_METHOD streamParse ( nsIInputStream in,
void closure,
const char *  fromRawSegment,
PRUint32  toOffset,
PRUint32  count,
PRUint32 writeCount 
) [static]

Definition at line 83 of file TestPageLoad.cpp.

                                                    {

  char parseBuf[2048], loc[2048], lineBuf[2048];
  char *loc_t, *loc_t2;
  int i = 0;
  char *tmp;

  if(!globalStream.IsEmpty()) {
    globalStream.Append(fromRawSegment);
    tmp = ToNewCString(globalStream);
    //printf("\n>>NOW:\n^^^^^\n%s\n^^^^^^^^^^^^^^", tmp);
  } else {
    tmp = (char *)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"))!= NULL 
       || (loc_t=PL_strcasestr(lineBuf, "script"))!=NULL) {
      loc_t2=PL_strcasestr(loc_t, "src");
      if(loc_t2!=NULL) {
        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"))!= NULL) { 
       loc_t2=PL_strcasestr(loc_t, "href");
      if(loc_t2!=NULL) {
        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"))!=NULL) {
      loc_t+=10;
      strcpy(loc, loc_t);
      sscanf(loc, "=\"%[^\"]", parseBuf);
      if(parseBuf[0]!='\0') {
        numFound++;
        auxLoad(parseBuf);
      }
    }
    i++;

  }
  *writeCount = count;
  return NS_OK;
}

Here is the call graph for this function:


Variable Documentation

nsCOMPtr<nsIURI> baseURI [static]

Definition at line 73 of file TestPageLoad.cpp.

Definition at line 69 of file TestPageLoad.cpp.

Definition at line 70 of file TestPageLoad.cpp.

Definition at line 71 of file TestPageLoad.cpp.

int numFound = 0 [static]

Definition at line 78 of file TestPageLoad.cpp.

int numStart = 0 [static]

Definition at line 77 of file TestPageLoad.cpp.

Definition at line 74 of file TestPageLoad.cpp.