From cf7c66e034421f59ae857b954060ae7af791e3b4 Mon Sep 17 00:00:00 2001 From: "dcone%netscape.com" Date: Thu, 23 May 2002 21:06:49 +0000 Subject: [PATCH] Update of the debug plugin. Not part of the build --- .../layout-debug/idl/nsIDebugObject.idl | 8 +++ .../layout-debug/plugin/nsIDebugPlugin.h | 12 ++++ .../layout-debug/plugin/nsIDebugPlugin.idl | 1 + .../layout-debug/plugin/nsScriptablePeer.cpp | 18 +++++- extensions/layout-debug/plugin/plugin.cpp | 17 +++++ extensions/layout-debug/plugin/plugin.h | 1 + extensions/layout-debug/plugin/test.html | 64 +++++++++++++++---- extensions/layout-debug/src/nsDebugObject.cpp | 47 ++++++++++++-- .../layout-debug/src/nsRegressionTester.cpp | 47 ++++++++++++-- 9 files changed, 188 insertions(+), 27 deletions(-) diff --git a/extensions/layout-debug/idl/nsIDebugObject.idl b/extensions/layout-debug/idl/nsIDebugObject.idl index e3c9f83b5201..91afa6721251 100644 --- a/extensions/layout-debug/idl/nsIDebugObject.idl +++ b/extensions/layout-debug/idl/nsIDebugObject.idl @@ -43,6 +43,14 @@ interface nsIDebugObject : nsISupports { + /** + * creates a directory.. only locally + * @param + * @param + */ + void CreateDirectory(in wstring aDirectoryPath, in unsigned long aFlags); + + /** * Dumps the content of a window * @param diff --git a/extensions/layout-debug/plugin/nsIDebugPlugin.h b/extensions/layout-debug/plugin/nsIDebugPlugin.h index 0505bbac764c..891faaee9428 100644 --- a/extensions/layout-debug/plugin/nsIDebugPlugin.h +++ b/extensions/layout-debug/plugin/nsIDebugPlugin.h @@ -30,6 +30,9 @@ class NS_NO_VTABLE nsIDebugPlugin : public nsISupports { /* readonly attribute string version; */ NS_IMETHOD GetVersion(char * *aVersion) = 0; + /* void CreateDirectory (in wstring aDirPath, in unsigned long aFlags, [retval] out long aResult); */ + NS_IMETHOD CreateDirectory(const PRUnichar *aDirPath, PRUint32 aFlags, PRInt32 *aResult) = 0; + /* void DumpLayout (in nsISupports aWindow, in wstring aFilePath, in wstring aFileName, in unsigned long aFlags, [retval] out long aResult); */ NS_IMETHOD DumpLayout(nsISupports *aWindow, const PRUnichar *aFilePath, const PRUnichar *aFileName, PRUint32 aFlags, PRInt32 *aResult) = 0; @@ -47,6 +50,7 @@ class NS_NO_VTABLE nsIDebugPlugin : public nsISupports { /* Use this macro when declaring classes that implement this interface. */ #define NS_DECL_NSIDEBUGPLUGIN \ NS_IMETHOD GetVersion(char * *aVersion); \ + NS_IMETHOD CreateDirectory(const PRUnichar *aDirPath, PRUint32 aFlags, PRInt32 *aResult); \ NS_IMETHOD DumpLayout(nsISupports *aWindow, const PRUnichar *aFilePath, const PRUnichar *aFileName, PRUint32 aFlags, PRInt32 *aResult); \ NS_IMETHOD StartDirectorySearch(const char *aFilePath); \ NS_IMETHOD GetNextFileInDirectory(char **aFileName); \ @@ -55,6 +59,7 @@ class NS_NO_VTABLE nsIDebugPlugin : public nsISupports { /* Use this macro to declare functions that forward the behavior of this interface to another object. */ #define NS_FORWARD_NSIDEBUGPLUGIN(_to) \ NS_IMETHOD GetVersion(char * *aVersion) { return _to GetVersion(aVersion); } \ + NS_IMETHOD CreateDirectory(const PRUnichar *aDirPath, PRUint32 aFlags, PRInt32 *aResult) { return _to CreateDirectory(aDirPath, aFlags, aResult); } \ NS_IMETHOD DumpLayout(nsISupports *aWindow, const PRUnichar *aFilePath, const PRUnichar *aFileName, PRUint32 aFlags, PRInt32 *aResult) { return _to DumpLayout(aWindow, aFilePath, aFileName, aFlags, aResult); } \ NS_IMETHOD StartDirectorySearch(const char *aFilePath) { return _to StartDirectorySearch(aFilePath); } \ NS_IMETHOD GetNextFileInDirectory(char **aFileName) { return _to GetNextFileInDirectory(aFileName); } \ @@ -63,6 +68,7 @@ class NS_NO_VTABLE nsIDebugPlugin : public nsISupports { /* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */ #define NS_FORWARD_SAFE_NSIDEBUGPLUGIN(_to) \ NS_IMETHOD GetVersion(char * *aVersion) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetVersion(aVersion); } \ + NS_IMETHOD CreateDirectory(const PRUnichar *aDirPath, PRUint32 aFlags, PRInt32 *aResult) { return !_to ? NS_ERROR_NULL_POINTER : _to->CreateDirectory(aDirPath, aFlags, aResult); } \ NS_IMETHOD DumpLayout(nsISupports *aWindow, const PRUnichar *aFilePath, const PRUnichar *aFileName, PRUint32 aFlags, PRInt32 *aResult) { return !_to ? NS_ERROR_NULL_POINTER : _to->DumpLayout(aWindow, aFilePath, aFileName, aFlags, aResult); } \ NS_IMETHOD StartDirectorySearch(const char *aFilePath) { return !_to ? NS_ERROR_NULL_POINTER : _to->StartDirectorySearch(aFilePath); } \ NS_IMETHOD GetNextFileInDirectory(char **aFileName) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetNextFileInDirectory(aFileName); } \ @@ -103,6 +109,12 @@ NS_IMETHODIMP nsDebugPlugin::GetVersion(char * *aVersion) return NS_ERROR_NOT_IMPLEMENTED; } +/* void CreateDirectory (in wstring aDirPath, in unsigned long aFlags, [retval] out long aResult); */ +NS_IMETHODIMP nsDebugPlugin::CreateDirectory(const PRUnichar *aDirPath, PRUint32 aFlags, PRInt32 *aResult) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + /* void DumpLayout (in nsISupports aWindow, in wstring aFilePath, in wstring aFileName, in unsigned long aFlags, [retval] out long aResult); */ NS_IMETHODIMP nsDebugPlugin::DumpLayout(nsISupports *aWindow, const PRUnichar *aFilePath, const PRUnichar *aFileName, PRUint32 aFlags, PRInt32 *aResult) { diff --git a/extensions/layout-debug/plugin/nsIDebugPlugin.idl b/extensions/layout-debug/plugin/nsIDebugPlugin.idl index 6ecc07295f1a..92adda3b9a28 100644 --- a/extensions/layout-debug/plugin/nsIDebugPlugin.idl +++ b/extensions/layout-debug/plugin/nsIDebugPlugin.idl @@ -25,6 +25,7 @@ [scriptable, uuid(482e1890-1fe5-11d5-9cf8-0060b0fbd8ac)] interface nsIDebugPlugin : nsISupports { readonly attribute string version; + void CreateDirectory(in wstring aDirPath,in unsigned long aFlags,[retval] out long aResult); void DumpLayout(in nsISupports aWindow,in wstring aFilePath,in wstring aFileName,in unsigned long aFlags,[retval] out long aResult ); void StartDirectorySearch(in string aFilePath); void GetNextFileInDirectory([retval] out string aFileName); diff --git a/extensions/layout-debug/plugin/nsScriptablePeer.cpp b/extensions/layout-debug/plugin/nsScriptablePeer.cpp index 1d2829028ea6..10364148d0c1 100644 --- a/extensions/layout-debug/plugin/nsScriptablePeer.cpp +++ b/extensions/layout-debug/plugin/nsScriptablePeer.cpp @@ -117,6 +117,20 @@ NS_IMETHODIMP nsScriptablePeer::GetVersion(char * *aVersion) return NS_OK; } + +NS_IMETHODIMP nsScriptablePeer::CreateDirectory(const PRUnichar *aFilePath,PRUint32 aFlags, PRInt32 *aResult) +{ +nsresult rv = NS_OK; +PRBool retVal; + + if ( mPlugin ) { + mPlugin->CreateDirectory(aFilePath,aFlags,&retVal); + } + return NS_OK; +} + + + NS_IMETHODIMP nsScriptablePeer::DumpLayout(nsISupports *aWindow, const PRUnichar *aFilePath, const PRUnichar *aFileName, PRUint32 aFlags, PRInt32 *aResult) { @@ -127,8 +141,10 @@ PRBool retVal; mPlugin->OutPutLayoutFrames(aWindow,aFilePath,aFileName,aFlags,&retVal); if (retVal == NS_OK) { *aResult= 0; + } else if ( retVal == NS_ERROR_FILE_INVALID_PATH ) { + *aResult = 2; // fatal error.. stop exection } else { - *aResult = 1; + *aResult = 1; // did not load.. keep going } } return rv; diff --git a/extensions/layout-debug/plugin/plugin.cpp b/extensions/layout-debug/plugin/plugin.cpp index 42f227704c13..389b1dfe5fbd 100644 --- a/extensions/layout-debug/plugin/plugin.cpp +++ b/extensions/layout-debug/plugin/plugin.cpp @@ -192,6 +192,23 @@ void nsPluginInstance::OutPutLayoutFrames(nsISupports *aWindow, const PRUnichar //----------------------------------------------------- +void nsPluginInstance::CreateDirectory(const PRUnichar *aBasePath, PRUint32 aFlags, PRInt32 *aRetVal) +{ + nsIDebugObject *theDebugObject=NULL; + + *aRetVal = NS_ERROR_FAILURE; + + if (gServiceManager) { + // get service using its contract id and use it to allocate the memory + gServiceManager->GetServiceByContractID("@mozilla.org/debug/debugobject;1", NS_GET_IID(nsIDebugObject), (void **)&theDebugObject); + if(theDebugObject){ + *aRetVal = theDebugObject->CreateDirectory(aBasePath, aFlags); + } + } +} + +//----------------------------------------------------- + void nsPluginInstance::CompareLayoutFrames(const PRUnichar *aBasePath, const PRUnichar *aVerPath, const PRUnichar *aBaseFile, const PRUnichar *aVerFile, PRUint32 aFlags, PRInt32 *aRetVal) { diff --git a/extensions/layout-debug/plugin/plugin.h b/extensions/layout-debug/plugin/plugin.h index 525621181573..28a020a2845a 100644 --- a/extensions/layout-debug/plugin/plugin.h +++ b/extensions/layout-debug/plugin/plugin.h @@ -61,6 +61,7 @@ public: // locals void getVersion(char* *aVersion); + void CreateDirectory(const PRUnichar *aFilePath, PRUint32 aFlags, PRInt32 *aRetVal); void OutPutLayoutFrames(nsISupports *aWindow,const PRUnichar *aFilePath, const PRUnichar *aFileName, PRUint32 aFlags, PRInt32 *aRetVal); void CompareLayoutFrames(const PRUnichar *aBasePath, const PRUnichar *aVerPath, const PRUnichar *aBaseFile, const PRUnichar *aVerFile, PRUint32 aFlags, PRInt32 *aRetVal); diff --git a/extensions/layout-debug/plugin/test.html b/extensions/layout-debug/plugin/test.html index 528a35c209a9..83d1ed4bd913 100644 --- a/extensions/layout-debug/plugin/test.html +++ b/extensions/layout-debug/plugin/test.html @@ -31,6 +31,7 @@ var origWidth; var origHeight; var dirType; var curIndex; +var dumpStyle; var myArray = new Array(9); @@ -211,11 +212,9 @@ RestoreWindow(); function ShowDirectories() { - for(i=0;i<(myArray.length);i+=3){ WriteOutput( myArray[i], false, "normal" ,false,true ); } - } //============================================================================= @@ -245,6 +244,7 @@ function runTests() testType = 4; } + if ( dirType == 1 ) { ClearOutput(); WriteOutput( "Starting Single Directory Tests",true,"normal",true,false ); @@ -256,12 +256,23 @@ function runTests() baseDir = document.TestForm.baseDir.value; verDir = document.TestForm.verDir.value; + // create the output directories + if ( testType == 1 ) { + dirURL = "file:///"+ baseDir; + err = embed.CreateDirectory(dirURL,0); + } + + if ( (testType == 1) || (testType == 2) ) { + dirURL = "file:///"+ verDir; + err = embed.CreateDirectory(dirURL,0); + } + DumpFrames(true,0,testType); } else if (dirType == 2) { ClearOutput(); WriteOutput( "Starting Directory Tests",true,"normal",true,false ); curIndex = 0; - DumpDirectoryies(testType,0); + DumpDirectoryies(testType); } } @@ -280,6 +291,19 @@ function DumpDirectoryies(aTestType) verDir = myArray[curIndex+2]; baseExt = document.TestForm.baseExt.value; verExt = document.TestForm.verExt.value; + + // create the output directories + if ( testType == 1 ) { + dirURL = "file:///"+ baseDir; + err = embed.CreateDirectory(dirURL,0); + } + + if ( (testType == 1) || (testType == 2) ) { + dirURL = "file:///"+ verDir; + err = embed.CreateDirectory(dirURL,0); + } + + WriteOutput( "New Directory" , false, "normal" ,true, true ); DumpFrames(true,0,aTestType); } else { @@ -305,6 +329,11 @@ var loadingFlag; outputWindow = window; theWindow = window.open(filename,0); placeWindows(outputWindow,theWindow); + } + if ( document.getElementById('ds').checked ) { + dumpStyle = 1; + } else { + dumpStyle = 0; } started = true; } else { @@ -319,22 +348,24 @@ var loadingFlag; if (aTestType==1) { // baseline outputfilename = outputfilename.replace (".html",baseExt); - loading = embed.DumpLayout(theWindow,baseDir,outputfilename,0); + loading = embed.DumpLayout(theWindow,baseDir,outputfilename,dumpStyle); } else if ((aTestType==2)|| (aTestType==3) ) { // verify outputfilename = outputfilename.replace (".html",verExt); - loading = embed.DumpLayout(theWindow,verDir,outputfilename,0); + loading = embed.DumpLayout(theWindow,verDir,outputfilename,dumpStyle); } else if (aTestType==4) { // just compare outputfilename = outputfilename.replace (".html",verExt); loading = 0; } - if (loading != 0) { + if (loading == 1) { + // page was not loaded testtype = aTestType; - setTimeout("DumpFrames(false,filename,testtype)",1000); + setTimeout("DumpFrames(false,filename,testtype,dumpStyle)",250); break; - } else { + } else if (loading == 0) { + // successful in loading the page if ( aTestType<4 ){ WriteOutput("Writing File " + "\""+outputfilename+"\"",false,"success",true,true ); } @@ -357,6 +388,10 @@ var loadingFlag; DumpDirectoryies(aTestType); } } + } else { + // fatal error.. break + WriteOutput("FATAL ERROR" + "\""+outputfilename+"\"",false,"failure",true,true ); + break; } } } @@ -453,10 +488,17 @@ var loadingFlag; Run Compare - + + + + Dump Style + + + + @@ -471,11 +513,9 @@ var loadingFlag; - - -

OUTPUT IDLE

+

OUTPUT IDLE

diff --git a/extensions/layout-debug/src/nsDebugObject.cpp b/extensions/layout-debug/src/nsDebugObject.cpp index d89ea7f89463..a8db7a5670fc 100644 --- a/extensions/layout-debug/src/nsDebugObject.cpp +++ b/extensions/layout-debug/src/nsDebugObject.cpp @@ -60,7 +60,8 @@ #include "nsStyleStruct.h" #include "nsIFrameUtil.h" #include "nsLayoutCID.h" - +#include "nsNetUtil.h" + NS_IMPL_ISUPPORTS1(nsDebugObject, nsIDebugObject) static NS_DEFINE_IID(kFrameUtilCID, NS_FRAME_UTIL_CID); static NS_DEFINE_IID(kIFrameUtilIID, NS_IFRAME_UTIL_IID); @@ -83,6 +84,34 @@ nsDebugObject::~nsDebugObject() } +/** --------------------------------------------------- + * See documentation in nsDebugObject.h + * @update 5/16/02 dwc + */ +NS_IMETHODIMP +nsDebugObject::CreateDirectory( const PRUnichar *aFilePath, PRUint32 aFlags) +{ + nsresult rv,result = NS_ERROR_FAILURE; + nsCAutoString dirPathAS; + PRBool exists = PR_TRUE; + + // see if the directory exists, if not create it + dirPathAS.AssignWithConversion(aFilePath); + char* dirPath = ToNewCString(dirPathAS); + + nsCOMPtr localFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); + rv = NS_InitFileFromURLSpec( localFile,nsDependentCString(dirPath)); + if ( rv == NS_OK) { + rv = localFile->Exists(&exists); + if (!exists){ + rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0600); + } + } + + return result; +} + + /** --------------------------------------------------- * See documentation in nsDebugObject.h * @update 5/16/02 dwc @@ -114,7 +143,6 @@ PRBool stillLoading; docShell->GetPresShell(getter_AddRefs(presShell)); presShell->GetRootFrame(&root); if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) { - // create the string for the output nsCAutoString outputPath; outputPath.AssignWithConversion(aFilePath); @@ -128,12 +156,17 @@ PRBool stillLoading; FILE* fp = fopen(filePath, "wt"); - presShell->GetPresContext(&thePC); + if ( fp ) { + presShell->GetPresContext(&thePC); - fdbg->DumpRegressionData(thePC, fp, 0, dumpStyle); - fclose(fp); - delete filePath; - result = NS_OK; // the document is now loaded, and the frames are dumped. + fdbg->DumpRegressionData(thePC, fp, 0, dumpStyle); + fclose(fp); + delete filePath; + result = NS_OK; // the document is now loaded, and the frames are dumped. + } else { + + result = NS_ERROR_FILE_INVALID_PATH; + } } } } diff --git a/extensions/layout-debug/src/nsRegressionTester.cpp b/extensions/layout-debug/src/nsRegressionTester.cpp index d89ea7f89463..a8db7a5670fc 100644 --- a/extensions/layout-debug/src/nsRegressionTester.cpp +++ b/extensions/layout-debug/src/nsRegressionTester.cpp @@ -60,7 +60,8 @@ #include "nsStyleStruct.h" #include "nsIFrameUtil.h" #include "nsLayoutCID.h" - +#include "nsNetUtil.h" + NS_IMPL_ISUPPORTS1(nsDebugObject, nsIDebugObject) static NS_DEFINE_IID(kFrameUtilCID, NS_FRAME_UTIL_CID); static NS_DEFINE_IID(kIFrameUtilIID, NS_IFRAME_UTIL_IID); @@ -83,6 +84,34 @@ nsDebugObject::~nsDebugObject() } +/** --------------------------------------------------- + * See documentation in nsDebugObject.h + * @update 5/16/02 dwc + */ +NS_IMETHODIMP +nsDebugObject::CreateDirectory( const PRUnichar *aFilePath, PRUint32 aFlags) +{ + nsresult rv,result = NS_ERROR_FAILURE; + nsCAutoString dirPathAS; + PRBool exists = PR_TRUE; + + // see if the directory exists, if not create it + dirPathAS.AssignWithConversion(aFilePath); + char* dirPath = ToNewCString(dirPathAS); + + nsCOMPtr localFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); + rv = NS_InitFileFromURLSpec( localFile,nsDependentCString(dirPath)); + if ( rv == NS_OK) { + rv = localFile->Exists(&exists); + if (!exists){ + rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0600); + } + } + + return result; +} + + /** --------------------------------------------------- * See documentation in nsDebugObject.h * @update 5/16/02 dwc @@ -114,7 +143,6 @@ PRBool stillLoading; docShell->GetPresShell(getter_AddRefs(presShell)); presShell->GetRootFrame(&root); if (NS_SUCCEEDED(CallQueryInterface(root, &fdbg))) { - // create the string for the output nsCAutoString outputPath; outputPath.AssignWithConversion(aFilePath); @@ -128,12 +156,17 @@ PRBool stillLoading; FILE* fp = fopen(filePath, "wt"); - presShell->GetPresContext(&thePC); + if ( fp ) { + presShell->GetPresContext(&thePC); - fdbg->DumpRegressionData(thePC, fp, 0, dumpStyle); - fclose(fp); - delete filePath; - result = NS_OK; // the document is now loaded, and the frames are dumped. + fdbg->DumpRegressionData(thePC, fp, 0, dumpStyle); + fclose(fp); + delete filePath; + result = NS_OK; // the document is now loaded, and the frames are dumped. + } else { + + result = NS_ERROR_FILE_INVALID_PATH; + } } } }