authorisation/userpromptservice/test/tups_install/tuiscriptadaptors.h
changeset 98 7355aab40bca
parent 91 a675745f8b2e
equal deleted inserted replaced
91:a675745f8b2e 98:7355aab40bca
     1 /*
       
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __TUISCRIPTADAPATORS_H__
       
    20 #define __TUISCRIPTADAPATORS_H__
       
    21 
       
    22 #include <xml/parser.h>
       
    23 #include <xml/contenthandler.h>
       
    24 #include <swi/msisuihandlers.h>
       
    25 #include <e32property.h>
       
    26 #include <e32uid.h>
       
    27 
       
    28 
       
    29 class TTableOfInstallSizes
       
    30 	{
       
    31 public:	
       
    32 	TBuf<64>  iPkgFileName;
       
    33 	TInt      iInstallSize; 
       
    34 	};
       
    35 
       
    36 namespace Swi
       
    37 {
       
    38 namespace Test
       
    39 {
       
    40 const TInt KBufSize = 5;
       
    41 
       
    42 enum TFunctions{
       
    43 	EScript = 0,
       
    44 	EDisplayInstall,
       
    45     EDisplayGrantCapabilities,
       
    46 	EDisplayLanguage,
       
    47 	EDisplayDrive,
       
    48 	EDisplayUpgrade,
       
    49 	EDisplayOptions,
       
    50 	EHandleInstallEvent,
       
    51 	EHandleCancellableInstallEvent,
       
    52 	EDisplaySecurityWarning,
       
    53 	EDisplayOcspResult,
       
    54 	EDisplayCannotOverwriteFile,
       
    55 	EDisplayUninstall,
       
    56 	EDisplayText,
       
    57 	EDisplayError,
       
    58 	EDisplayDependencyBreak,
       
    59 	EDisplayApplicationsInUse,
       
    60 	EDisplayQuestion,
       
    61 	EDisplayMissingDependency,
       
    62 	EDisplaySIDMismatch,
       
    63 };
       
    64 
       
    65 enum TLeveltags{
       
    66 	EItemIndex =1,
       
    67 	EReturn,
       
    68 	EUpdateProgress,
       
    69 	EUpdateProgressFinal
       
    70 };
       
    71 
       
    72 enum TSwiCancelType{
       
    73 	ENoCancel,
       
    74 	ECancelTimerFromStart,
       
    75 	ECancelFromDialog,
       
    76 	ECancelAfterDialog
       
    77 };
       
    78 
       
    79 
       
    80 /**
       
    81  * Structure to hold the parsed value of the XML file.
       
    82  */
       
    83 struct TXmlFileData {
       
    84 	TBool			  InstallResult;
       
    85 	TBool			  CapabilitiesResult; 
       
    86 	TInt			  LanguagesResult;
       
    87 	TInt			  DriveResult;
       
    88 	TBool			  UpgradeResult;
       
    89 	TBool			  OptionsResult;
       
    90 	RArray< TBool >	  OptionSelection;
       
    91 	TBool			  WarningResult;
       
    92 	TBool			  OcspResult;
       
    93 	TBool			  UninstallResult;
       
    94 	TBool			  TextResult;
       
    95 	TBool			  DependencyResult;
       
    96 	TBool			  ApplicationsInUseResult;
       
    97 	TBool			  QuestionResult;
       
    98 	TBool             MissingDependencyResult;
       
    99 	TBool			  DevCertsResult;
       
   100 	TBool			  UpdateProgressBarResult;
       
   101 	TBool			  ProgressBarFinalValueResult;
       
   102 		
       
   103 	TXmlFileData();
       
   104 };
       
   105 
       
   106 /**
       
   107  * This class defines the interface required by a client of the xml framework.
       
   108  * It allows a client to be placed in a chain with other clients, i.e. a Parser,
       
   109  * a Validator, or a User, and therefore allows the flow of information between 
       
   110  * these links.
       
   111  */
       
   112 class CRebuildingContentHandler : public CBase, public Xml::MContentHandler
       
   113 	{
       
   114 public:
       
   115 	static CRebuildingContentHandler* NewL(CTestExecuteLogger& aLogger);
       
   116 	static CRebuildingContentHandler* NewLC(CTestExecuteLogger& aLogger);
       
   117 	~CRebuildingContentHandler();
       
   118 	void OnStartDocumentL(const Xml::RDocumentParameters& aDocParam, TInt aErrorCode);
       
   119 	void OnEndDocumentL(TInt aErrorCode);
       
   120 	void OnStartElementL(const Xml::RTagInfo& aElement, const Xml::RAttributeArray& aAttributes, TInt aErrorCode);
       
   121 	void OnEndElementL(const Xml::RTagInfo& aElement, TInt aErrorCode);
       
   122 	void OnContentL(const TDesC8& aBytes, TInt aErrorCode);
       
   123 	void OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, TInt aErrorCode);
       
   124 	void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode);
       
   125 	void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode);
       
   126 	void OnSkippedEntityL(const RString& aName, TInt aErrorCode) ;
       
   127 	void OnProcessingInstructionL(const TDesC8& aTarget, const TDesC8& aData, TInt aErrorCode);
       
   128 	void OnExtensionL(const RString& aData, TInt aToken, TInt aErrorCode);
       
   129 	void OnOutOfData();
       
   130 	void OnError(TInt aErrorCode);
       
   131 	TAny* GetExtendedInterface(const TInt32 aUid);
       
   132 	TXmlFileData& GetOptions();
       
   133 	
       
   134 public:
       
   135 	TInt iError;
       
   136 	
       
   137 private:
       
   138 	CRebuildingContentHandler(CTestExecuteLogger& aLogger);
       
   139 		
       
   140 	CTestExecuteLogger& Logger();
       
   141 	TXmlFileData iResult;
       
   142 	CTestExecuteLogger& iLogger;
       
   143 	TInt		 iLevel1;
       
   144 	TInt		 iLevel2;
       
   145 	TInt		 iLevel3;
       
   146 	TBool        iLangLogged;    ///< Has language dialog result been logged?
       
   147 	TBool        iDriveLogged;   ///< Has drive dialog result been logged?
       
   148 	TBool        iSecWarnLogged; ///< Has security warning result been logged?
       
   149 	};
       
   150 
       
   151 inline CTestExecuteLogger& CRebuildingContentHandler::Logger()
       
   152 	{
       
   153 	return iLogger;
       
   154 	}
       
   155 
       
   156 /**
       
   157 	When the FT option is used to display a dialog, up to this
       
   158 	many characters are recorded from the displayed string.  They
       
   159 	can be compared with the text specified in ExpectedDisplayText
       
   160 	if it is in the ini file.
       
   161  */
       
   162 const TInt KMaxDisplayText = 32;
       
   163 
       
   164 class CUIScriptAdaptor : public CBase, public MUiHandler
       
   165 	{
       
   166 public:	
       
   167 	~CUIScriptAdaptor();
       
   168 	static CUIScriptAdaptor* NewL(const TFileName& aXmlFileName,
       
   169 		CTestExecuteLogger& aLogger, RArray<TTableOfInstallSizes>* aExpectedValue = NULL);
       
   170 	static CUIScriptAdaptor* NewLC(const TFileName& aXmlFileName,
       
   171 		CTestExecuteLogger& aLogger, RArray<TTableOfInstallSizes>* aExpectedValue = NULL);
       
   172 	static CUIScriptAdaptor* NewL(const TFileName& aXmlFileName,
       
   173 		CTestExecuteLogger& aLogger, TPtrC aExpectedText,TPtrC aTextIsHash, TInt aExpectedDialog, TInt aKerrCode);
       
   174 	static CUIScriptAdaptor* NewLC(const TFileName& aXmlFileName,
       
   175 		CTestExecuteLogger& aLogger, TPtrC aExpectedText,TPtrC aTextIsHash, TInt aExpectedDialog, TInt aKerrCode);
       
   176 	
       
   177 	/// Displays install dialog, logging all incoming information.
       
   178 	TBool DisplayInstallL(const CAppInfo& aAppInfo,
       
   179 			const CApaMaskedBitmap* aLogo,
       
   180 				const RPointerArray<CCertificateInfo>& aCertificates);
       
   181 
       
   182 	TBool DisplayGrantCapabilitiesL(const CAppInfo& aAppInfo,
       
   183 			const TCapabilitySet& aCapabilitySet);
       
   184 
       
   185 	TInt DisplayLanguageL(const CAppInfo& aAppInfo, 
       
   186 			const RArray<TLanguage>& aLanguages);
       
   187 
       
   188 	TInt DisplayDriveL(const CAppInfo& aAppInfo,TInt64 aSize,
       
   189 			const RArray<TChar>& aDriveLetters,
       
   190 				const RArray<TInt64>& aDriveSpaces);
       
   191 
       
   192 	TBool DisplayUpgradeL(const CAppInfo& aAppInfo,
       
   193 			const CAppInfo& aExistingAppInfo);
       
   194 
       
   195 	TBool DisplayOptionsL(const CAppInfo& aAppInfo, 
       
   196 			const RPointerArray<TDesC>& aOptions,
       
   197 				RArray<TBool>& aSelections); 
       
   198 
       
   199 	TBool HandleInstallEventL(const CAppInfo& aAppInfo,
       
   200 			TInstallEvent aEvent, TInt aValue=0, 
       
   201 				const TDesC& aDes=KNullDesC);
       
   202 
       
   203 	void HandleCancellableInstallEventL(const CAppInfo& aAppInfo,
       
   204 			TInstallCancellableEvent aEvent, 
       
   205 				MCancelHandler& aCancelHandler,TInt aValue=0, 
       
   206 					const TDesC& aDes=KNullDesC);
       
   207 
       
   208 	TBool DisplaySecurityWarningL(const CAppInfo& aAppInfo,
       
   209 			TSignatureValidationResult aSigValidationResult,
       
   210 			RPointerArray<CPKIXValidationResultBase>& aPkixResults,
       
   211 			RPointerArray<CCertificateInfo>& aCertificates,
       
   212 			TBool aInstallAnyway);
       
   213 
       
   214 	TBool DisplayOcspResultL(const CAppInfo& aAppInfo,
       
   215 			TRevocationDialogMessage aMessage, 
       
   216 			RPointerArray<TOCSPOutcome>& aOutcomes,
       
   217 			RPointerArray<CCertificateInfo>& aCertificates,
       
   218 			TBool aWarningOnly);
       
   219 
       
   220 	void DisplayCannotOverwriteFileL(const CAppInfo& aAppInfo,
       
   221 			const CAppInfo& aInstalledAppInfo,
       
   222 				const TDesC& aFileName);
       
   223 
       
   224 	TBool DisplayUninstallL(const CAppInfo& aAppInfo);
       
   225 
       
   226 	TBool DisplayTextL(const CAppInfo& aAppInfo, 
       
   227 			TFileTextOption aOption,
       
   228 				const TDesC& aText);
       
   229 
       
   230 	void DisplayErrorL(const CAppInfo& aAppInfo,
       
   231 			TErrorDialog aType, 
       
   232 				const TDesC& aParam);
       
   233 
       
   234 	TBool DisplayDependencyBreakL(const CAppInfo& aAppInfo,
       
   235 	        const RPointerArray<TDesC>& aComponents);
       
   236 
       
   237 	TBool DisplayApplicationsInUseL(const CAppInfo& aAppInfo, 
       
   238 		    const RPointerArray<TDesC>& aAppNames);
       
   239 
       
   240 	TBool DisplayQuestionL(const CAppInfo& aAppInfo, 
       
   241 		    TQuestionDialog aQuestion, const TDesC& aDes=KNullDesC);
       
   242 		    
       
   243 	TBool DisplayMissingDependencyL(const CAppInfo& aAppInfo,
       
   244 		const TDesC& aDependencyName,TVersion aWantedVersionFrom,
       
   245 		TVersion aWantedVersionTo,TVersion aInstalledVersion);
       
   246 
       
   247 	// functions to handle displaying info to file
       
   248 	void DisplayAppInfo(const TDesC& aPreText, const CAppInfo& aAppInfo);
       
   249 	void DisplayBoolReturn(TBool aReturn);
       
   250 	void DisplayIntReturn(TInt aReturn);
       
   251 
       
   252 	// function to check progress bar
       
   253 	void CheckFinalProgressBarL();
       
   254 
       
   255 	// Function that aborts a test case when the expected
       
   256 	// installation size does not match the calculated size.
       
   257 	void CheckExpectedAndCalculatedInstallSizesL(const TDesC& aAppInfoName, TInt64 aSize);
       
   258 
       
   259 	// function to check if the "Display Drive" dialog have been called
       
   260  	TBool DisplayDriveDialogCalled() const;
       
   261 
       
   262 	// function to check the "Grant Capabilities" dialog has been called
       
   263 	TBool GrantUserCapsDialogCalled() const;
       
   264 	
       
   265 	// function to check the "CannotOverwrite" dialog has been called
       
   266 	TBool CannotOverwriteFileDialogCalled() const;
       
   267 
       
   268 	// function to check the "file owner" name in the CannotOverwrite dialog.
       
   269 	const TDesC& FileOwner() const;
       
   270 
       
   271 	// function to check whether a fatal OCSP response was encountered
       
   272 	TBool FatalOcspResponseEncountered() const;
       
   273 		
       
   274 	//Function to check the expected Ocsp Outcomes
       
   275     const RPointerArray<TOCSPOutcome>& ObservedOcspOutcomes() const;
       
   276 	
       
   277 	/// Use to enable and disable cancel testing inside dialogs
       
   278 	void SetCancelDialogTesting(TSwiCancelType aCancelType);
       
   279 	
       
   280 	// Set the dialog number to cancel on
       
   281 	void SetCancelDialogNumber(TInt aDialogNumber);
       
   282 
       
   283 	/// Use to enable and disable dialog delays
       
   284 	void SetDialogDelay(TTimeIntervalMicroSeconds32 aUsec);
       
   285 
       
   286 	// Set specific dialog number to delay at (default is all dialogs if dialog delay > 0)
       
   287 	void SetDelayDialogNumber(TInt aDialog);
       
   288 
       
   289 	// Reset the current dialog number, and set iInstallationCancelled to False
       
   290 	void ResetCurrentDialogNumber(TInt aDialogNumber = 0);
       
   291 	TBool InstallationCancelled() const;
       
   292 
       
   293 	inline const TDesC& DisplayedText() const;
       
   294 	inline const TDesC& DisplayedTextActual() const;
       
   295 
       
   296 	//Leave with error code
       
   297 	void LeaveError(TInt aReason);
       
   298 	
       
   299 	inline TInt NumberOfSecurityDialogsInvoked() const;
       
   300 		
       
   301 private:
       
   302 	/** 
       
   303 	 * Constructor
       
   304 	 * @param aXmlFileName    Name of the XML file containing dialog parameters
       
   305 	 * @param aLogger         TestExecute logger
       
   306 	 * @param aExpectedValue  Array of install sizes, if present.
       
   307 	 */
       
   308 	CUIScriptAdaptor(const TFileName& aXmlFileName, CTestExecuteLogger& aLogger,
       
   309 					 RArray<TTableOfInstallSizes>* aExpectedValue = NULL);
       
   310 	CUIScriptAdaptor(const TFileName& aXmlFileName, CTestExecuteLogger& aLogger,
       
   311 					 TPtrC aExpectedText,
       
   312 					 TPtrC aTextIsHash,
       
   313 					 TInt aExpectedDailog,
       
   314 					 TInt aKerrcode
       
   315 					 );				 					 
       
   316 					 					 
       
   317 	void ConstructL();
       
   318 	void ScriptParseL();
       
   319 	CTestExecuteLogger& Logger();
       
   320 	
       
   321 	// Called whenever a dialog is reached
       
   322 	void DialogReached();
       
   323 
       
   324 	TXmlFileData         iResult;
       
   325 	TFileName            iXmlFileName;
       
   326 	RFs			         iFs;
       
   327 	CTestExecuteLogger& iLogger;
       
   328 	
       
   329 	TInt iProgressBarFinal;	///< Progress bar final value.
       
   330 	TInt iProgressBarCurrent;	///< Progress bar current value.
       
   331 	TPtrC iExpectedDisplayText;
       
   332 	TPtrC iExpectedHash;
       
   333 	TInt iExpectedDialog;
       
   334 	TInt  iKerrCode;
       
   335 	RArray<TTableOfInstallSizes>* iExpectedValue;
       
   336 
       
   337 	TBool iDialogCancelType;			///< Controls whether we do cancel testing
       
   338 	TInt iCancelDialogNumber;		///< The dialog to cancel at 
       
   339 	TInt iCurrentDialogNumber;		///< The currentDialogNumber.
       
   340 	TBool iInstallationCancelled;	///< Whether we've cancelled the install yet
       
   341 	MCancelHandler *iCancelHandler; ///< Current CancellableInstallEvent cancel callback
       
   342 
       
   343 	// TBools for whether certain dialogs have been called
       
   344 	TBool iDisplayDriveDialogCalled;
       
   345 	TBool iGrantUserCapsDialogCalled;
       
   346 	TBool iCannotOverwriteFileDialogCalled;
       
   347 	HBufC* iFileOwner;
       
   348 	TTimeIntervalMicroSeconds32 iDialogDelay; // For async cancel testing
       
   349 	TInt iDelayDialogNumber;
       
   350 	TBool iFatalOcspResponseEncountered;
       
   351 	/** Possibly truncated text which was displayed with FT. */
       
   352 	TBuf<KMaxDisplayText> iDisplayedText;
       
   353 	HBufC *iDisplayedTextActual;
       
   354 	TInt iSecurityWarningDialogsInvoked;
       
   355 	// Array of observed ocsp outcomes for comparison to expected values.
       
   356     RPointerArray<TOCSPOutcome> iObservedOcspOutcomes;
       
   357     };
       
   358 
       
   359 inline TBool CUIScriptAdaptor::DisplayDriveDialogCalled() const
       
   360  	{
       
   361  	return iDisplayDriveDialogCalled;
       
   362  	}
       
   363  
       
   364 inline TBool CUIScriptAdaptor::GrantUserCapsDialogCalled() const
       
   365 	{
       
   366 	return iGrantUserCapsDialogCalled;
       
   367 	}
       
   368 
       
   369 inline TBool CUIScriptAdaptor::FatalOcspResponseEncountered() const 
       
   370 	{
       
   371 	return iFatalOcspResponseEncountered;
       
   372 	}
       
   373 
       
   374 inline const RPointerArray<TOCSPOutcome>& CUIScriptAdaptor::ObservedOcspOutcomes() const
       
   375     {
       
   376     return iObservedOcspOutcomes;  	
       
   377     }
       
   378  
       
   379 inline 	CTestExecuteLogger& CUIScriptAdaptor::Logger()
       
   380 	{
       
   381 	return iLogger;
       
   382 	}
       
   383 
       
   384 inline void CUIScriptAdaptor::SetCancelDialogTesting(TSwiCancelType aCancelType)
       
   385 	{
       
   386 	iDialogCancelType = aCancelType;
       
   387 	}
       
   388 
       
   389 inline void CUIScriptAdaptor::SetCancelDialogNumber(TInt aDialogNumber)
       
   390 	{
       
   391 	iCancelDialogNumber = aDialogNumber;
       
   392 	}
       
   393 
       
   394 inline void CUIScriptAdaptor::ResetCurrentDialogNumber(TInt aDialogNumber)
       
   395 	{
       
   396 	iCurrentDialogNumber = aDialogNumber;
       
   397 	iInstallationCancelled = EFalse;
       
   398 	if(aDialogNumber == 0) iCancelHandler = 0;
       
   399 	}
       
   400 
       
   401 inline TBool CUIScriptAdaptor::InstallationCancelled() const
       
   402 	{
       
   403 	return iInstallationCancelled;
       
   404 	}
       
   405 
       
   406 inline void CUIScriptAdaptor::SetDialogDelay(TTimeIntervalMicroSeconds32 aDialogDelay)
       
   407 	{
       
   408 	iDialogDelay = aDialogDelay;
       
   409 	}
       
   410 
       
   411 inline void CUIScriptAdaptor::SetDelayDialogNumber(TInt aDialog)
       
   412 	{
       
   413 	iDelayDialogNumber = aDialog;
       
   414 	}
       
   415 
       
   416 inline const TDesC& CUIScriptAdaptor::DisplayedText() const
       
   417 /**
       
   418 	Returns text displayed with FT.
       
   419 
       
   420 	@return					Text displayed with FT.
       
   421  */
       
   422 	{
       
   423 	return iDisplayedText;
       
   424 	}
       
   425 
       
   426 inline const TDesC& CUIScriptAdaptor::DisplayedTextActual() const
       
   427 	{
       
   428 	return *iDisplayedTextActual;		// Unchanged text
       
   429 	}
       
   430 
       
   431 inline TBool CUIScriptAdaptor::CannotOverwriteFileDialogCalled() const
       
   432  	{
       
   433  	return iCannotOverwriteFileDialogCalled;
       
   434  	}
       
   435 
       
   436 inline const TDesC& CUIScriptAdaptor::FileOwner() const
       
   437 	{
       
   438 	return *iFileOwner;
       
   439 	}
       
   440 
       
   441 inline TInt CUIScriptAdaptor::NumberOfSecurityDialogsInvoked() const
       
   442 	{
       
   443 	return iSecurityWarningDialogsInvoked;
       
   444 	}
       
   445 
       
   446 }//swi
       
   447 }//test
       
   448 #endif // TUISCRIPTADAPATORS_H