зеркало из https://github.com/mozilla/gecko-dev.git
Add progress event sink notification test.
This commit is contained in:
Родитель
06b8524af8
Коммит
0642d114a1
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include "nsIFileTransportService.h"
|
||||
#include "nsITransport.h"
|
||||
#include "nsIProgressEventSink.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
@ -44,6 +46,9 @@ static PRLogModuleInfo *gTestFileTransportLog = nsnull;
|
|||
#define PRINTF(args)
|
||||
#endif
|
||||
|
||||
#undef PRINTF
|
||||
#define PRINTF(args) printf args
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
||||
|
@ -55,6 +60,37 @@ nsIEventQueue* gEventQ = nsnull;
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class MyProgressEventSink : public nsIProgressEventSink
|
||||
, public nsIInterfaceRequestor {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
MyProgressEventSink() { NS_INIT_ISUPPORTS(); }
|
||||
|
||||
NS_IMETHOD OnProgress(nsIRequest *request, nsISupports *ctxt,
|
||||
PRUint32 progress, PRUint32 progressMax) {
|
||||
PRINTF(("progress: %u/%u\n", progress, progressMax));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD OnStatus(nsIRequest *request, nsISupports *ctxt,
|
||||
nsresult status, const PRUnichar *statusArg) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetInterface(const nsIID &iid, void **result) {
|
||||
if (iid.Equals(NS_GET_IID(nsIProgressEventSink)))
|
||||
return QueryInterface(iid, result);
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS2(MyProgressEventSink,
|
||||
nsIProgressEventSink,
|
||||
nsIInterfaceRequestor)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class MyListener : public nsIStreamListener {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -160,6 +196,13 @@ TestAsyncRead(const char* fileName, PRUint32 offset, PRInt32 length)
|
|||
rv = listener->Init(fileName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
MyProgressEventSink* progressSink = new MyProgressEventSink();
|
||||
if (progressSink == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(progressSink);
|
||||
rv = fileTrans->SetNotificationCallbacks(progressSink, PR_FALSE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
gDone = PR_FALSE;
|
||||
nsCOMPtr<nsIRequest> request;
|
||||
rv = fileTrans->AsyncRead(listener, nsnull, offset, length, 0, getter_AddRefs(request));
|
||||
|
@ -208,6 +251,13 @@ TestAsyncWrite(const char* fileName, PRUint32 offset, PRInt32 length)
|
|||
rv = listener->Init(outFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
MyProgressEventSink* progressSink = new MyProgressEventSink();
|
||||
if (progressSink == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(progressSink);
|
||||
rv = fileTrans->SetNotificationCallbacks(progressSink, PR_FALSE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsILocalFile> f;
|
||||
rv = NS_NewLocalFile(fileName, PR_FALSE, getter_AddRefs(f));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
|
Загрузка…
Ссылка в новой задаче