browser/src/BrCtlApiTestContainer.cpp
branchSymbian3
changeset 3 235c00e46fb7
equal deleted inserted replaced
2:e904b452aa85 3:235c00e46fb7
       
     1 /*
       
     2 * Copyright (c) 2006 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:  CBrCtlApiTestContainer from BrCtlBCTestContainer.h
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "BrCtlApiTestContainer.h"
       
    20 
       
    21 #include <eiklabel.h>  // for example label control
       
    22 #include <aknview.h>
       
    23 #include <AknGlobalConfirmationQuery.h>
       
    24 #include <BrCtlInterface.h>
       
    25 #include <CHARCONV.H>
       
    26 #include "BrCtlApiTestObserver.h"
       
    27 #include <e32std.h>
       
    28 
       
    29 _LIT8( KContentDataType, "text/html" );
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CBrCtlApiTestContainer::ConstructL(const TRect& aRect)
       
    35 // EPOC two phased constructor
       
    36 // ---------------------------------------------------------
       
    37 //
       
    38 void CBrCtlApiTestContainer::ConstructL(const TRect& aRect)
       
    39     {
       
    40     iBrCtlApiTestObserver = CBrCtlApiTestObserver::NewL();
       
    41     iBrCtlApiTestStateChangeObserver = CBrCtlApiTestStateChangeObserver::NewL( this );
       
    42     iBrCtlDialogs = CBrowserDialogsProviderProxy::NewL();
       
    43     iCommandBase = TBrCtlDefs::ECommandIdBase;
       
    44     CreateWindowL();
       
    45     SetRect(aRect);
       
    46     ActivateL();
       
    47     }
       
    48 
       
    49 // Destructor
       
    50 CBrCtlApiTestContainer::~CBrCtlApiTestContainer()
       
    51     {
       
    52 
       
    53     if (iBrCtlInterface)
       
    54         {
       
    55         iBrCtlInterface->RemoveLoadEventObserver(iBrCtlApiTestObserver);
       
    56         iBrCtlInterface->RemoveStateChangeObserver(iBrCtlApiTestStateChangeObserver);
       
    57         delete iBrCtlInterface;
       
    58         }
       
    59 
       
    60     delete iBrCtlApiTestStateChangeObserver;
       
    61     delete iBrCtlApiTestObserver;
       
    62     delete iBrCtlDialogs;
       
    63     }
       
    64 
       
    65 void CBrCtlApiTestContainer::CancelLoad()
       
    66     {
       
    67     iCancelInitDataLoad = ETrue;
       
    68     }
       
    69     
       
    70 TInt CBrCtlApiTestContainer::LoadPageL()
       
    71     {
       
    72     if(iBrCtlInterface)
       
    73         {
       
    74         iBrCtlInterface->LoadUrlL(KUrlLoadTestHtml2);
       
    75         }
       
    76 
       
    77      return KErrNone;
       
    78      }
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // CBrCtlApiTestContainer::SizeChanged()
       
    82 // Called by framework when the view size is changed
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 void CBrCtlApiTestContainer::SizeChanged()
       
    86     {
       
    87     if (iBrCtlInterface)
       
    88         {
       
    89         iBrCtlInterface->SetRect(Rect());
       
    90         }
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------
       
    94 // CBrCtlApiTestContainer::CountComponentControls() const
       
    95 // ---------------------------------------------------------
       
    96 //
       
    97 TInt CBrCtlApiTestContainer::CountComponentControls() const
       
    98     {
       
    99     if (iBrCtlInterface)
       
   100         return 1;
       
   101     return 0;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------
       
   105 // CBrCtlApiTestContainer::ComponentControl(TInt aIndex) const
       
   106 // ---------------------------------------------------------
       
   107 //
       
   108 CCoeControl* CBrCtlApiTestContainer::ComponentControl(TInt aIndex) const
       
   109     {
       
   110     switch ( aIndex )
       
   111         {
       
   112         case 0:
       
   113             return iBrCtlInterface; // Could be NULL
       
   114         default:
       
   115             return NULL;
       
   116         }
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CBrCtlApiTestContainer::Draw(const TRect& aRect) const
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 void CBrCtlApiTestContainer::Draw(const TRect& aRect) const
       
   124     {
       
   125     CWindowGc& gc = SystemGc();
       
   126     // TODO: Add your drawing code here
       
   127     // example code...
       
   128     gc.SetPenStyle(CGraphicsContext::ENullPen);
       
   129     gc.SetBrushColor(KRgbGray);
       
   130     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   131     gc.DrawRect(aRect);
       
   132     
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------
       
   136 // CBrCtlApiTestContainer::HandleControlEventL(
       
   137 //     CCoeControl* aControl,TCoeEvent aEventType)
       
   138 // ---------------------------------------------------------
       
   139 //
       
   140 void CBrCtlApiTestContainer::HandleControlEventL(
       
   141     CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
       
   142     {
       
   143     // TODO: Add your control event handler code here
       
   144     }
       
   145 
       
   146 
       
   147 
       
   148 // ----------------------------------------------------
       
   149 // CBrCtlApiTestContainer::HandleKeyEventL(
       
   150 //     const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
       
   151 // ?implementation_description
       
   152 // ----------------------------------------------------
       
   153 //
       
   154 TKeyResponse CBrCtlApiTestContainer::HandleKeyEventL(
       
   155     const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
       
   156     {
       
   157     return EKeyWasNotConsumed;
       
   158     }
       
   159 
       
   160 // ----------------------------------------------------
       
   161 // CBrCtlApiTestContainer::HandleCommandL(TInt aCommand)
       
   162 // ?implementation_description
       
   163 // ----------------------------------------------------
       
   164 //
       
   165 TInt CBrCtlApiTestContainer::HandleCommandL( TInt aCommand )
       
   166     {
       
   167     const TInt KCommandIdBase( 15000 );
       
   168     iBrCtlInterface->HandleCommandL( aCommand + KCommandIdBase );
       
   169     return KErrNone;
       
   170     }
       
   171 
       
   172 TKeyResponse CBrCtlApiTestContainer::OfferKeyEventL(const TKeyEvent& /* aKeyEvent */,
       
   173                         TEventCode /* aType */ )
       
   174     {
       
   175     return EKeyWasConsumed;
       
   176     }
       
   177 
       
   178 void CBrCtlApiTestContainer::HandleCommandL( 
       
   179     TBrCtlDefs::TBrCtlClientCommands /* aCommand */, 
       
   180     const CArrayFix<TPtrC>& /* aAttributesNames */,
       
   181     const CArrayFix<TPtrC>& /* aAttributeValues */ )
       
   182     {
       
   183     }
       
   184 
       
   185 
       
   186 void CBrCtlApiTestContainer::CreateBrowserControlInterfaceL(TInt aBrCtlConfig)
       
   187     {
       
   188     TPoint base( 0, 0 );
       
   189     TPoint extent( 352, 295 );
       
   190     TRect rect( base, extent );
       
   191     
       
   192     iBrCtlInterface = CreateBrowserControlL( this, rect, 
       
   193         aBrCtlConfig,
       
   194         iCommandBase, iBrCtlApiTestObserver, iBrCtlApiTestObserver,
       
   195         iBrCtlApiTestObserver, iBrCtlApiTestObserver, iBrCtlDialogs, NULL, iBrCtlApiTestObserver );
       
   196 
       
   197     iBrCtlInterface->MakeVisible( ETrue );
       
   198     
       
   199     }
       
   200 
       
   201 HBufC8* CBrCtlApiTestContainer::ReadFileLC( const TDesC& aFileName )
       
   202     {
       
   203     RFs rfs;
       
   204     RFile file;
       
   205     User::LeaveIfError( rfs.Connect() );
       
   206     CleanupClosePushL( rfs );
       
   207     User::LeaveIfError( file.Open( rfs, aFileName, EFileRead ) );
       
   208     CleanupClosePushL( file );
       
   209     TInt size;
       
   210     User::LeaveIfError( file.Size( size ) );
       
   211     HBufC8* buf = HBufC8::NewLC( size );
       
   212     TPtr8 bufPtr( buf->Des() );
       
   213     User::LeaveIfError( file.Read( bufPtr ) );
       
   214     CleanupStack::Pop(); // buf
       
   215     CleanupStack::PopAndDestroy( 2 ); // file, rfs
       
   216     CleanupStack::PushL( buf );
       
   217     return buf;
       
   218     }
       
   219 
       
   220 TInt CBrCtlApiTestContainer::LoadDataL()
       
   221     {
       
   222     HBufC8* data = ReadFileLC( KUrlLoadTestHtml );
       
   223     TDataType dataType( KContentDataType() );
       
   224     TUid uid;
       
   225     uid.iUid = KCharacterSetIdentifierIso88591;
       
   226     TRAPD( err, iBrCtlInterface->LoadDataL( KUrlLoadTestHtml, *data, dataType, uid ) );
       
   227 	
       
   228     CleanupStack::PopAndDestroy( data );
       
   229 
       
   230     return err;
       
   231     }
       
   232 
       
   233 TInt CBrCtlApiTestContainer::ClearCacheTest()
       
   234     {
       
   235     const TUint result = iBrCtlInterface->ClearCache();
       
   236     
       
   237     return KErrNone;
       
   238     }
       
   239 
       
   240 TBool CBrCtlApiTestContainer::IsUrlInCacheTest( TDesC16& aUrl )
       
   241     {
       
   242     const TBool result = iBrCtlInterface->IsUrlInCache( aUrl ); // ( TDesC16 & )KUrlLoadTestHtml() );
       
   243 
       
   244     return result;
       
   245     }
       
   246 
       
   247 TInt CBrCtlApiTestContainer::ClearItemInCacheTest()
       
   248     {
       
   249     TInt result = iBrCtlInterface->ClearItemInCache( (TDesC16 &) KUrlLoadTestHtml() );
       
   250 
       
   251     if ( ( result == KErrNotFound ) || ( result == KErrNone ) )
       
   252         {
       
   253         return KErrNone;
       
   254         }
       
   255     else
       
   256         {
       
   257         return KErrGeneral;
       
   258         }
       
   259     }
       
   260 
       
   261 TInt CBrCtlApiTestContainer::PageInfoLC( TBrCtlDefs::TBrCtlPageInfo aType )
       
   262     {
       
   263     iBrCtlInterface->LoadFileL( KUrlLoadTestHtml );
       
   264 
       
   265     TRAPD( err, 
       
   266         HBufC* url = iBrCtlInterface->PageInfoLC( aType ); 
       
   267         CleanupStack::PopAndDestroy( url ); 
       
   268         )
       
   269 
       
   270     return err;
       
   271     }
       
   272 
       
   273 TInt CBrCtlApiTestContainer::CertInfo()
       
   274     {
       
   275     const TCertInfo* certInfo = iBrCtlInterface->CertInfo();
       
   276 
       
   277     if ( !certInfo )
       
   278         {
       
   279         return KErrNone;
       
   280         }
       
   281     else
       
   282         {
       
   283         return KErrGeneral;
       
   284         }
       
   285     }
       
   286 
       
   287 TInt CBrCtlApiTestContainer::NavigationAvailableTest()
       
   288     {
       
   289     const TBool nav = iBrCtlInterface->NavigationAvailable( 
       
   290         TBrCtlDefs::ENavigationBack );
       
   291 
       
   292     if ( nav == 0 || nav == 1 )
       
   293         {
       
   294         return KErrNone;
       
   295         }
       
   296     else
       
   297         {
       
   298         return KErrGeneral;
       
   299         }
       
   300     }
       
   301 
       
   302 TInt CBrCtlApiTestContainer::GetBitmapData()
       
   303     {
       
   304     
       
   305     TRAPD( err, iBrCtlInterface->LoadUrlL(KUrlLoadTestHtml2) );
       
   306     
       
   307     //waits for browser control to load the page
       
   308     User::After(4000000);
       
   309 
       
   310     CGulIcon* icon = iBrCtlInterface->GetBitmapData( KUrlLoadTestHtml, TBrCtlDefs::EBitmapFavicon );
       
   311     icon = iBrCtlInterface->GetBitmapData( KUrlLoadTestHtml, TBrCtlDefs::EBitmapThumbnail );	
       
   312     return err;
       
   313     }
       
   314 
       
   315 TInt CBrCtlApiTestContainer::SaveToFileL()
       
   316     {
       
   317     HBufC8* data = ReadFileLC( KUrlLoadTestHtml );
       
   318     TDataType dataType( KContentDataType() );
       
   319     TUid uid;
       
   320     uid.iUid = KCharacterSetIdentifierIso88591;
       
   321     TRAPD( err, iBrCtlInterface->LoadDataL( KUrlLoadTestHtml, *data, dataType, uid ) );
       
   322 
       
   323     TUint16 NoOfBytesSaved =  iBrCtlInterface->SaveToFileL( KUrlLoadTestHtml );
       
   324 
       
   325     CleanupStack::PopAndDestroy( data ); 
       
   326     return err;
       
   327     }
       
   328 
       
   329 TInt CBrCtlApiTestContainer::OkToExit()
       
   330     {
       
   331     const TBool res = iBrCtlInterface->OkToExit();
       
   332 
       
   333     if ( res )
       
   334         {
       
   335         return KErrNone;
       
   336         }
       
   337     else
       
   338         {
       
   339         return KErrGeneral;
       
   340         }
       
   341     }
       
   342     
       
   343 TInt CBrCtlApiTestContainer::FindKeyword( TPtrC aHtml, TPtrC aKeyword, TInt aMatch)
       
   344     {
       
   345     TRAP_IGNORE( iBrCtlInterface->LoadFileL( KUrlLoadTestHtml2 ) );
       
   346 
       
   347     TInt result = iBrCtlInterface->FindKeyword( aKeyword );
       
   348 
       
   349     if ( result == TBrCtlDefs::EFindNoMatches && aMatch == EFindNoMatchesExpected )
       
   350         {
       
   351         return KErrNone;
       
   352         }
       
   353     else if ( result == TBrCtlDefs::EFindMatch && ( aMatch == EFindMatchExpected || aMatch == EFindMoreMatchesExpected ) )
       
   354         {
       
   355         return KErrNone;
       
   356         }
       
   357     else
       
   358         {
       
   359         return KErrNotFound;
       
   360         }
       
   361     }
       
   362 
       
   363 TInt CBrCtlApiTestContainer::FindKeywordAgain( TInt aMatch )
       
   364     {
       
   365     TBrCtlDefs::TBrCtlFindResponse result = iBrCtlInterface->FindKeywordAgain( ETrue );
       
   366 
       
   367     if ( result == TBrCtlDefs::EFindNoMatches && ( aMatch == EFindNoMatchesExpected || aMatch == EFindMatchExpected ) )
       
   368         {
       
   369         return KErrNone;
       
   370         }
       
   371     else if ( result == TBrCtlDefs::EFindMatch && aMatch == EFindMoreMatchesExpected )
       
   372         {
       
   373         return KErrNone;
       
   374         }
       
   375     else
       
   376         {
       
   377         return KErrNotFound;
       
   378         }
       
   379     }
       
   380 
       
   381 TInt CBrCtlApiTestContainer::SetFocus()
       
   382     {
       
   383     iBrCtlInterface->SetFocus( ETrue, EDrawNow );
       
   384     
       
   385     return KErrNone;
       
   386     }
       
   387 
       
   388 TInt CBrCtlApiTestContainer::OfferKeyEvent()
       
   389     {
       
   390     TKeyEvent key;
       
   391     key.iCode = 0;
       
   392     key.iScanCode = 0;
       
   393     key.iModifiers = 0;
       
   394     key.iRepeats = 0;
       
   395     
       
   396     TRAPD( err, iBrCtlInterface->OfferKeyEventL( key, EEventNull ) );
       
   397     
       
   398     return err;
       
   399     }
       
   400 
       
   401 TInt CBrCtlApiTestContainer::BrCtlMinimumSize()
       
   402     {
       
   403     const TSize testSize = iBrCtlInterface->MinimumSize();
       
   404     
       
   405     if ( testSize.iWidth > 0 && testSize.iHeight > 0 )
       
   406         {
       
   407         return KErrNone;
       
   408         }
       
   409     else
       
   410         {
       
   411         return KErrGeneral;
       
   412         }
       
   413     }
       
   414 
       
   415 TInt CBrCtlApiTestContainer::BrCtlSubscribeToMenuItemsL()
       
   416     {
       
   417     TRAPD( err, iBrCtlInterface->LoadUrlL( KUrlLoadTestHtml2 ) );
       
   418 
       
   419 	const RPointerArray<TBrCtlSubscribeTo> &ptr = iBrCtlInterface->SubscribeToMenuItemsL();
       
   420 
       
   421     return err;
       
   422     }    
       
   423     
       
   424 TInt CBrCtlApiTestContainer::BrCtlContentSize()
       
   425     {
       
   426     TBool testPassed = EFalse;
       
   427     TSize testSize;
       
   428     
       
   429     if ( iBrCtlInterface )
       
   430         {
       
   431         testSize = iBrCtlInterface->ContentSize();
       
   432 
       
   433         if ( testSize.iWidth == 0 && testSize.iHeight == 0 )
       
   434             {
       
   435             testPassed = ETrue;
       
   436             }
       
   437         }
       
   438     
       
   439     return testPassed;
       
   440     }
       
   441     
       
   442 TInt CBrCtlApiTestContainer::SetBrowserSettingL()
       
   443     {
       
   444     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsAutoLoadImages, 0 );
       
   445         
       
   446     return KErrNone;
       
   447     }
       
   448 
       
   449 TInt CBrCtlApiTestContainer::BrowserSettingL( TUint& aSetting )
       
   450     {
       
   451     // value returned
       
   452     aSetting = iBrCtlInterface->BrowserSettingL( TBrCtlDefs::ESettingsAutoLoadImages );
       
   453     
       
   454     return KErrNone;
       
   455     }
       
   456 
       
   457 TInt CBrCtlApiTestContainer::FocusedImageL()
       
   458     {
       
   459     iBrCtlInterface->LoadFileL( KUrlLoadTestHtml );
       
   460 
       
   461     iBrCtlInterface->SetFocus( ETrue, EDrawNow );
       
   462 
       
   463     TBrCtlImageCarrier* res = iBrCtlInterface->FocusedImageLC();
       
   464     CleanupStack::PopAndDestroy( res );
       
   465 
       
   466     if ( res )
       
   467         {
       
   468         return KErrNone; 
       
   469         }
       
   470     else 
       
   471         {
       
   472         return KErrGeneral;
       
   473         }        
       
   474     }
       
   475 
       
   476 TInt CBrCtlApiTestContainer::AddCommandObserverL()
       
   477     {
       
   478     iBrCtlInterface->AddCommandObserverL( this );
       
   479     return KErrNone;
       
   480     }
       
   481 
       
   482 TInt CBrCtlApiTestContainer::RemoveCommandObserver()
       
   483     {
       
   484     iBrCtlInterface->RemoveCommandObserver( this );
       
   485     return KErrNone;
       
   486     }
       
   487 
       
   488 TInt CBrCtlApiTestContainer::ImageCountL()
       
   489     {
       
   490     return iBrCtlInterface->ImageCountL();
       
   491     }
       
   492 
       
   493 TInt CBrCtlApiTestContainer::BrCtlFocusedElementTypeL()
       
   494     {
       
   495     
       
   496     iBrCtlInterface->LoadUrlL( KUrlLoadTestHtml2 );
       
   497     
       
   498     iBrCtlInterface->SetFocus( ETrue, EDrawNow );
       
   499 
       
   500     iBrCtlInterface->FocusedElementType();
       
   501 
       
   502     return KErrNone;
       
   503     }
       
   504     
       
   505 TInt CBrCtlApiTestContainer::BrCtlSetParam()
       
   506     {
       
   507     _LIT( KContentType, "text/html");
       
   508     TRAPD( err, iBrCtlInterface->SetParamL( TBrCtlDefs::EParamsSelfDownoadableTypes, KContentType ) )
       
   509 
       
   510     return err;
       
   511     }
       
   512 
       
   513 TInt CBrCtlApiTestContainer::LoadSavedPageL()
       
   514     {
       
   515     _LIT( KUid, "savedpage://4" );
       
   516     _LIT( KSavedUrl, "c:\\BrCtlTest\\loadtest.saved" );
       
   517 
       
   518     HBufC8* databuf = ReadFileLC( KSavedUrl );
       
   519     HBufC16* bigbuf = HBufC::NewL( databuf->Des().Length() );
       
   520 
       
   521     bigbuf->Des().Copy( databuf->Des() );
       
   522     
       
   523     iBrCtlInterface->LoadSavedPageL( KUid, *bigbuf );
       
   524 
       
   525     delete bigbuf;
       
   526     CleanupStack::PopAndDestroy( databuf ); 
       
   527 
       
   528     return KErrNone;    
       
   529     }
       
   530 
       
   531 TInt CBrCtlApiTestContainer::SetSelfDownloadContentTypes()
       
   532     {
       
   533     TRAPD( err, iBrCtlInterface->SetSelfDownloadContentTypesL( (TDesC16&)KContentDataType() ) );
       
   534 
       
   535     return err;
       
   536     }
       
   537 
       
   538 TInt CBrCtlApiTestContainer::ZoomLevels()
       
   539     {
       
   540     RArray<TUint>* zoom = iBrCtlInterface->ZoomLevels();
       
   541 
       
   542     if ( zoom->Count() > 0 )
       
   543         {
       
   544         return KErrNone;
       
   545         }
       
   546     else
       
   547         {
       
   548         return KErrGeneral;
       
   549         }
       
   550     }
       
   551 
       
   552 TInt CBrCtlApiTestContainer::AddOptionMenuItems()
       
   553     {
       
   554     TRAPD( err, iBrCtlInterface->AddOptionMenuItemsL( *iMenuPane, 0, 0 ) );
       
   555 
       
   556     return err;
       
   557     }
       
   558 
       
   559 TInt CBrCtlApiTestContainer::BrCtlInitLoadDataL()
       
   560     {
       
   561     HBufC8* data = ReadFileLC( KUrlLoadTestHtml );
       
   562     TDataType dataType( KContentDataType() );
       
   563     MBrCtlDataLoadConsumer* brCtlDataLoadConsumer = NULL;
       
   564     TUid uid;
       
   565     uid.iUid = KCharacterSetIdentifierIso88591;
       
   566     TRAPD( err, iBrCtlInterface->InitLoadDataL( KUrlLoadTestHtml, dataType, uid, data->Length(),
       
   567         this, &brCtlDataLoadConsumer ) );
       
   568 
       
   569     if ( brCtlDataLoadConsumer )
       
   570         {
       
   571         brCtlDataLoadConsumer->HandleNextDataChunk( *data );
       
   572         if ( !iCancelInitDataLoad )
       
   573             {
       
   574             brCtlDataLoadConsumer->HandleLoadComplete();
       
   575             }
       
   576         }
       
   577         
       
   578     iCancelInitDataLoad = EFalse;
       
   579 
       
   580     CleanupStack::PopAndDestroy( data );
       
   581     
       
   582     return err;
       
   583     }
       
   584 
       
   585 TInt CBrCtlApiTestContainer::HandleDownloadCommand()
       
   586     {
       
   587     TBool testPassed = EFalse;
       
   588 
       
   589     if ( iBrCtlInterface )
       
   590         {
       
   591         TRAPD( err, iBrCtlInterface->HandleDownloadCommandL( 0, TBrCtlDefs::EDownloadCmdMarkAsProgressive ) );
       
   592 
       
   593             if ( err == KErrNone )
       
   594             {
       
   595             testPassed = ETrue;
       
   596             }
       
   597         }
       
   598 
       
   599     if ( testPassed )
       
   600         {
       
   601         return KErrNone;
       
   602         }
       
   603     else
       
   604         {
       
   605         return KErrGeneral;
       
   606         }
       
   607     }   
       
   608 
       
   609 TInt CBrCtlApiTestContainer::VersionInfoL()
       
   610   {
       
   611 
       
   612   _LIT(KName, "S60 browser");
       
   613   _LIT(KVersion, "5.0");
       
   614   _LIT(KBuild, "0516");
       
   615 
       
   616   HBufC* verinfo = iBrCtlInterface->VersionInfoLC( TBrCtlDefs::EVersionInfoName );
       
   617 
       
   618   if(!verinfo)
       
   619     {
       
   620     return KErrGeneral;
       
   621     }
       
   622   if (verinfo->Compare(KName()) != 0)
       
   623     {
       
   624     CleanupStack::PopAndDestroy( verinfo ); 
       
   625     return KErrGeneral;
       
   626     }
       
   627   CleanupStack::PopAndDestroy( verinfo ); 
       
   628   verinfo = 0;
       
   629   verinfo = iBrCtlInterface->VersionInfoLC( TBrCtlDefs::EVersionInfoVersion );	
       
   630   if(!verinfo)
       
   631     {
       
   632   	return KErrGeneral;
       
   633     }
       
   634   if(verinfo->Compare(KVersion()) != 0)
       
   635     {
       
   636     CleanupStack::PopAndDestroy( verinfo ); 
       
   637     return KErrGeneral;
       
   638     }
       
   639   CleanupStack::PopAndDestroy( verinfo ); 
       
   640   verinfo = 0;
       
   641   verinfo = iBrCtlInterface->VersionInfoLC( TBrCtlDefs::EVersionInfoBuild );
       
   642   if(!verinfo)
       
   643     {
       
   644    	return KErrGeneral;
       
   645     }
       
   646   if(verinfo->Compare(KBuild()) != 0)
       
   647     {
       
   648     CleanupStack::PopAndDestroy( verinfo ); 
       
   649     return KErrGeneral;
       
   650     }
       
   651   CleanupStack::PopAndDestroy( verinfo ); 
       
   652   return KErrNone;
       
   653   }
       
   654 TInt CBrCtlApiTestContainer::WmlOptionMenuItemsL()
       
   655     {
       
   656 
       
   657     iBrCtlInterface->WMLOptionMenuItemsL();
       
   658     return KErrNone;
       
   659 
       
   660     }
       
   661 
       
   662 TInt CBrCtlApiTestContainer::BrCtlPostL()
       
   663     {
       
   664     
       
   665     RFs rfs;
       
   666     RFile file;
       
   667     User::LeaveIfError( rfs.Connect() );
       
   668     CleanupClosePushL( rfs );
       
   669     User::LeaveIfError( file.Open( rfs, KUrlLoadTestHtml(), EFileShareReadersOnly ) );
       
   670     CleanupClosePushL( file );    
       
   671     
       
   672     int size;
       
   673     User::LeaveIfError( file.Size( size ) );
       
   674     HBufC8* data = NULL;
       
   675     data = HBufC8::NewLC( size );
       
   676     TPtr8 dataPtr( data->Des() );
       
   677     User::LeaveIfError( file.Read( dataPtr ) );
       
   678 
       
   679     //parse url
       
   680     HBufC* url16 = NULL;
       
   681     int pos = dataPtr.Find( _L8("\r\n") );                   
       
   682     if ( pos != KErrNotFound )
       
   683         {
       
   684         url16 = HBufC::NewLC( pos );                
       
   685         url16->Des().Copy( dataPtr.Mid( 0, pos ) ); 
       
   686         }
       
   687     else 
       
   688         {
       
   689         CleanupStack::PushL( url16 );        
       
   690         }
       
   691     
       
   692     //parse content type
       
   693     HBufC8* contenttype = NULL;
       
   694     int pos2 = dataPtr.Mid( pos+2 ).Find( _L8("\r\n") );                   
       
   695     if ( pos2 != KErrNotFound )
       
   696         {
       
   697         contenttype = HBufC8::NewLC( pos2 );                
       
   698         contenttype->Des().Copy( dataPtr.Mid( pos+2, pos2 ) );             
       
   699         }
       
   700     else 
       
   701         {
       
   702         CleanupStack::PushL( contenttype );        
       
   703         }
       
   704 
       
   705     //parse post data
       
   706     HBufC8* postdata = NULL;
       
   707     int pos3 = dataPtr.Mid( pos+2+pos2+2 ).Find( _L8("\r\n") );                   
       
   708     if ( pos3 != KErrNotFound )
       
   709         {
       
   710         postdata = HBufC8::NewLC( pos3 );                
       
   711         postdata->Des().Copy( dataPtr.Mid( pos+2+pos2+2, pos3 ) );             
       
   712         }
       
   713     else 
       
   714         {
       
   715         CleanupStack::PushL( postdata );        
       
   716         }
       
   717 
       
   718     //parse boundry
       
   719     HBufC8* boundry = NULL;
       
   720     int pos4 = dataPtr.Mid( pos+2+pos2+2+pos3+2 ).Find( _L8("\r\n") );                   
       
   721     if ( pos4 != KErrNotFound )
       
   722         {
       
   723         boundry = HBufC8::NewLC( pos4 );                
       
   724         boundry->Des().Copy( dataPtr.Mid(pos+2+pos2+2+pos3+2 , pos4) );             
       
   725         }
       
   726     else 
       
   727         {
       
   728         CleanupStack::PushL( boundry );        
       
   729         }
       
   730     
       
   731     TAny* any = NULL;
       
   732     
       
   733     TRAPD( error, iBrCtlInterface->PostUrlL ( *url16, 
       
   734                                 *contenttype, 
       
   735                                 *postdata, 
       
   736                                 boundry, 
       
   737                                 any ) );
       
   738 	
       
   739 /*	HBufC* urlTest = NULL;
       
   740 
       
   741     TRAP( error, iBrCtlInterface->PostUrlL ( *urlTest, 
       
   742                                 *contenttype, 
       
   743                                 *postdata, 
       
   744                                 boundry, 
       
   745                                 any ) );
       
   746                                 
       
   747      HBufC8* contenttypeTest = NULL;                          
       
   748                                 
       
   749      TRAP( error, iBrCtlInterface->PostUrlL ( *url16, 
       
   750                                 *contenttypeTest, 
       
   751                                 *postdata, 
       
   752                                 boundry, 
       
   753                                 any ) );                           
       
   754 */
       
   755 
       
   756     CleanupStack::PopAndDestroy( boundry );
       
   757     CleanupStack::PopAndDestroy( postdata );
       
   758     CleanupStack::PopAndDestroy( contenttype );
       
   759     CleanupStack::PopAndDestroy( url16 );    
       
   760     CleanupStack::PopAndDestroy( data );                        
       
   761     CleanupStack::PopAndDestroy( 2 ); // file, rfs        
       
   762 
       
   763     return error;
       
   764     }
       
   765      
       
   766 // Added for Widget Extension Test
       
   767 TInt CBrCtlApiTestContainer::CreateBrCtlInterfaceAndWidgetExtensionL()
       
   768     {
       
   769     TPoint base( 0, 0 );
       
   770     TPoint extent( 352, 295 );
       
   771     TRect rect( base, extent );
       
   772     
       
   773 	iBrCtlInterface = CreateBrowserControlL(
       
   774         this,
       
   775         rect,
       
   776         TBrCtlDefs::ECapabilityLoadHttpFw |
       
   777         TBrCtlDefs::ECapabilityCursorNavigation|
       
   778         TBrCtlDefs::ECapabilityWebKitLite |
       
   779         TBrCtlDefs::ECapabilityClientResolveEmbeddedURL,
       
   780         TBrCtlDefs::ECommandIdBase,
       
   781         iBrCtlApiTestObserver, /* softkeys */
       
   782         iBrCtlApiTestObserver, /* link resolver */
       
   783         iBrCtlApiTestObserver, /* special load observer */
       
   784         iBrCtlApiTestObserver, /* layout observer */
       
   785         iBrCtlDialogs,  //iWidgetUiDialogsProviderProxy,
       
   786         iBrCtlApiTestObserver, /* window observer */
       
   787         iBrCtlApiTestObserver /* download observer */
       
   788         ); 
       
   789         
       
   790     iBrCtlInterface->AddLoadEventObserverL( iBrCtlApiTestObserver );
       
   791     iBrCtlInterface->AddStateChangeObserverL( iBrCtlApiTestStateChangeObserver );
       
   792     iBrCtlInterface->SetComponentsToInheritVisibility();
       
   793     
       
   794     iWidgetExtension = iBrCtlInterface->CreateWidgetExtensionL( *this );
       
   795     
       
   796     if ( iWidgetExtension )
       
   797         {
       
   798         return KErrNone;
       
   799         }
       
   800     else
       
   801         {
       
   802         return KErrGeneral;
       
   803         }
       
   804 
       
   805     }
       
   806 
       
   807 TInt CBrCtlApiTestContainer::HistoryLoad1L()
       
   808     {
       
   809     TInt err( KErrNone );
       
   810     if(iBrCtlInterface)
       
   811         {
       
   812         TRAP(err, iBrCtlInterface->LoadUrlL(KUrlHistoryHandlerHtml1));
       
   813         }
       
   814 
       
   815     return err;
       
   816     }
       
   817 
       
   818 TInt CBrCtlApiTestContainer::HistoryLoad2L()
       
   819     {
       
   820     TInt err( KErrNone );
       
   821     if(iBrCtlInterface)
       
   822         {
       
   823         TRAP(err, iBrCtlInterface->LoadUrlL(KUrlHistoryHandlerHtml2));
       
   824         }
       
   825 
       
   826     return err;
       
   827     }
       
   828 
       
   829 TInt CBrCtlApiTestContainer::HistoryLoad3L()
       
   830     {
       
   831     TInt err( KErrNone );
       
   832     if(iBrCtlInterface)
       
   833         {
       
   834         TRAP(err, iBrCtlInterface->LoadUrlL(KUrlHistoryHandlerHtml3));
       
   835         }
       
   836 
       
   837     return err;
       
   838     }
       
   839 
       
   840 TInt CBrCtlApiTestContainer::WMLLoad1L()
       
   841     {
       
   842     TInt err( KErrNone );
       
   843     if(iBrCtlInterface)
       
   844         {
       
   845         TRAP(err, iBrCtlInterface->LoadUrlL(KUrlLoadTestWml1));
       
   846         }
       
   847 
       
   848     return err;
       
   849     }
       
   850 
       
   851 TInt CBrCtlApiTestContainer::WMLLoad2L()
       
   852     {
       
   853     TInt err( KErrNone );
       
   854     if(iBrCtlInterface)
       
   855         {
       
   856         TRAP(err, iBrCtlInterface->LoadUrlL(KUrlLoadTestWml2));
       
   857         }
       
   858 
       
   859     return err;
       
   860     }
       
   861 
       
   862 TInt CBrCtlApiTestContainer::WMLLoad3L()
       
   863     {
       
   864     TInt err( KErrNone );
       
   865     if(iBrCtlInterface)
       
   866         {
       
   867         TRAP(err, iBrCtlInterface->LoadUrlL(KUrlLoadTestWml3));
       
   868         }
       
   869 
       
   870     return err;
       
   871     }
       
   872 
       
   873 // Dummy function definitions for the MWidgetCallback functions
       
   874 TBool CBrCtlApiTestContainer::DialogMimeFileSelectLC(HBufC*& /* aSelectedFileName */,
       
   875                          const TDesC& /* aMimeType */) 
       
   876 	{
       
   877 		
       
   878 	}
       
   879 
       
   880 /**
       
   881 * Called to show or hide softkeys
       
   882 * @since 3.1
       
   883 * @param aVisible ETrue to show softkeys, EFalse when full screen is needed
       
   884 */
       
   885 void CBrCtlApiTestContainer::SetSoftkeysVisible(TBool /* aVisible */) 
       
   886 	{
       
   887 		
       
   888 	}
       
   889 
       
   890 /**
       
   891 * Called to change the display orientation to landscape
       
   892 * @since 3.1
       
   893 */
       
   894 void CBrCtlApiTestContainer::SetDisplayMode(TBrCtlDefs::TBrCtlOrientation /* aOrientation */) 
       
   895 	{
       
   896 		
       
   897 	}
       
   898 
       
   899 //Reserved for future use
       
   900 TInt CBrCtlApiTestContainer::Reserved_1(TAny*& a0, TAny* a1, TAny* a2) 
       
   901 	{
       
   902 		
       
   903 	}
       
   904 TInt CBrCtlApiTestContainer::Reserved_2(TAny*& a0, TAny* a1, TAny* a2) 
       
   905 	{
       
   906 		
       
   907 	}
       
   908 TInt CBrCtlApiTestContainer::Reserved_3(TAny*& a0, TAny* a1, TAny* a2) 
       
   909 	{
       
   910 		
       
   911 	}
       
   912 TInt CBrCtlApiTestContainer::Reserved_4(TAny*& a0, TAny* a1, TAny* a2) 
       
   913 	{
       
   914 		
       
   915 	}
       
   916 TInt CBrCtlApiTestContainer::Reserved_5(TAny*& a0, TAny* a1, TAny* a2) 
       
   917 	{
       
   918 		
       
   919 	}
       
   920 TInt CBrCtlApiTestContainer::Reserved_6(TAny*& a0, TAny* a1, TAny* a2) 
       
   921 	{
       
   922 		
       
   923 	}
       
   924 TInt CBrCtlApiTestContainer::Reserved_7(TAny*& a0, TAny* a1, TAny* a2) 
       
   925 	{
       
   926 		
       
   927 	}
       
   928 TInt CBrCtlApiTestContainer::Reserved_8(TAny*& a0, TAny* a1, TAny* a2) 
       
   929 	{
       
   930 		
       
   931 	}
       
   932 TInt CBrCtlApiTestContainer::Reserved_9(TAny*& a0, TAny* a1, TAny* a2) 
       
   933 	{
       
   934 		
       
   935 	}
       
   936 TInt CBrCtlApiTestContainer::Reserved_10(TAny*& a0, TAny* a1, TAny* a2) 
       
   937 	{
       
   938 		
       
   939 	}
       
   940     
       
   941 // End of File