contentstorage/cahandler/url/tsrc/t_caurlhandler/src/T_caurlhandlerplugin.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 /*
       
     2 * Copyright (c) 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 "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  * T_caapphandlerplugin.cpp
       
    19  *
       
    20  *  Created on: 2009-09-16
       
    21  *      Author:
       
    22  */
       
    23 
       
    24 // for CleanupResetAndDestroyPushL
       
    25 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    26 #include <w32std.h>
       
    27 #include <apgtask.h>
       
    28 #include <apgcli.h>
       
    29 #include <qservicemanager.h>
       
    30 
       
    31 #include <cadef.h>
       
    32 
       
    33 #include "T_caurlhandlerplugin.h"
       
    34 #include "waitactive.h"
       
    35 #include "caurlhandler.h"
       
    36 #include "caurlhandlerplugin.h"
       
    37 #include "caentry.h"
       
    38 
       
    39 QTM_USE_NAMESPACE
       
    40 
       
    41 const TInt KBrowserUid = { 0x10008D39 };
       
    42 static const char caUrlAddress[] = "http://www.nokia.com";
       
    43 static const char caTypeUrl[] = "url";
       
    44 static const char caAttrUrl[] = "url";
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 T_CaUrlHandler::T_CaUrlHandler():
       
    51     iUrlHandler(NULL)
       
    52 {
       
    53 }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void T_CaUrlHandler::cleanup()
       
    60 {
       
    61     delete iUrlHandler;
       
    62     iUrlHandler = NULL;
       
    63 }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void T_CaUrlHandler::initTestCase()
       
    70 {
       
    71     QStringList pluginPaths;
       
    72     QString xmlName("caurlhandlerplugin.xml");
       
    73 
       
    74     pluginPaths.append("c:/resource/qt/plugins/commandhandler");
       
    75     pluginPaths.append("z:/resource/qt/plugins/commandhandler");
       
    76 
       
    77     QServiceManager serviceManager;
       
    78     foreach (QString path, pluginPaths) {
       
    79         QApplication::addLibraryPath(path);
       
    80         QDir dir(path);
       
    81         if (dir.exists(xmlName)) {
       
    82             serviceManager.addService(dir.absoluteFilePath(xmlName));
       
    83         }
       
    84     }
       
    85 }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void T_CaUrlHandler::urlHandlerConstruction()
       
    92 {
       
    93     delete iUrlHandler;
       
    94     iUrlHandler = NULL;
       
    95     TInt error = KErrNone;
       
    96     QT_TRYCATCH_ERROR(error, iUrlHandler = new CaUrlHandler());
       
    97     QCOMPARE(error, KErrNone);
       
    98     QVERIFY(iUrlHandler);
       
    99 }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void T_CaUrlHandler::urlHandlerMultipleLoad()
       
   106 {
       
   107     RPointerArray<CaUrlHandler> handlerArray;
       
   108     bool foundNull(false);
       
   109     TRAPD(err,
       
   110           CleanupResetAndDestroyPushL(handlerArray);
       
   111     for (TInt i(0); i < 10; ++i) {
       
   112     handlerArray.AppendL(
       
   113         new CaUrlHandler());
       
   114     if (handlerArray[i] == NULL) {
       
   115         foundNull = true;
       
   116         break;
       
   117     }
       
   118     }
       
   119     CleanupStack::PopAndDestroy(&handlerArray);
       
   120          );
       
   121     QCOMPARE(err, KErrNone);
       
   122     QVERIFY(!foundNull);
       
   123 }
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void T_CaUrlHandler::urlHandlerMultipleLoadAndDelete()
       
   130 {
       
   131     bool foundNull(false);
       
   132     CaUrlHandler *handlerPtr(NULL);
       
   133     for (TInt i(0); i < 10; ++i) {
       
   134         handlerPtr = new CaUrlHandler();
       
   135         if (handlerPtr == NULL) {
       
   136             foundNull = true;
       
   137             break;
       
   138         };
       
   139         delete handlerPtr;
       
   140         handlerPtr = NULL;
       
   141     }
       
   142     QVERIFY(!foundNull);
       
   143 }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 void T_CaUrlHandler::urlHandlerOpenFails()
       
   150 {
       
   151     urlHandlerConstruction();
       
   152     TInt errorUnsupportedCommand(KErrNone);
       
   153     TInt errorOpen(KErrNone);
       
   154     bool notStarted(false);
       
   155 
       
   156     RWsSession wsSession;
       
   157     TRAPD(err,
       
   158           CleanupClosePushL(wsSession);
       
   159           User::LeaveIfError(wsSession.Connect());
       
   160 
       
   161           TApaTaskList taskList(wsSession);
       
   162           TApaTask taskBefore = taskList.FindApp(TUid::Uid(KBrowserUid));
       
   163 
       
   164         if (taskBefore.Exists()) {
       
   165             taskBefore.EndTask();
       
   166         }
       
   167 
       
   168         CaEntry *entry = new CaEntry();
       
   169 
       
   170         // valid entry type name
       
   171         entry->setEntryTypeName(caTypeUrl);
       
   172 
       
   173         //invalid command name
       
   174         errorUnsupportedCommand = iUrlHandler->execute(
       
   175                  *entry, "unsupported_command_name");
       
   176 
       
   177         // no attribute
       
   178         errorOpen = iUrlHandler->execute(*entry, caCmdOpen);
       
   179         QTest::qWait(3000);
       
   180 
       
   181 
       
   182         TApaTask taskAfter = taskList.FindApp(TUid::Uid(KBrowserUid));
       
   183         notStarted = !taskAfter.Exists();
       
   184 
       
   185         delete entry;
       
   186         entry = NULL;
       
   187         CleanupStack::PopAndDestroy(&wsSession);
       
   188          );
       
   189     QCOMPARE(err, KErrNone);
       
   190     QCOMPARE(errorUnsupportedCommand, errorUnsupportedCommand);
       
   191     //QCOMPARE(errorUnsupportedCommand, KErrNotSupported);
       
   192     QVERIFY(notStarted);
       
   193     QCOMPARE(errorOpen, KErrGeneral);
       
   194 }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 /* uncomment and check test when browser is in TB10.1 platfrom */
       
   201 void T_CaUrlHandler::urlHandlerRunApplication()
       
   202 {
       
   203     urlHandlerConstruction();
       
   204 
       
   205     TInt errorOpen(KErrNone);
       
   206     bool started(false);
       
   207     TRAPD(err,
       
   208           CaEntry *entry = new CaEntry();
       
   209 
       
   210           RWsSession wsSession;
       
   211           CleanupClosePushL(wsSession);
       
   212           User::LeaveIfError(wsSession.Connect());
       
   213 
       
   214           TApaTaskList taskList(wsSession);
       
   215           TApaTask taskBefore = taskList.FindApp(TUid::Uid(KBrowserUid));
       
   216 
       
   217         if (taskBefore.Exists()) {
       
   218         taskBefore.EndTask();
       
   219         }
       
   220 
       
   221         // valid data needed to launch url
       
   222         entry->setEntryTypeName(caTypeUrl);
       
   223         entry->setAttribute(caAttrUrl,caUrlAddress);
       
   224 
       
   225         errorOpen = iUrlHandler->execute(*entry, caCmdOpen);
       
   226         QTest::qWait(3000);
       
   227 
       
   228         TApaTask taskAfter = taskList.FindApp(TUid::Uid(KBrowserUid));
       
   229         started =  taskAfter.Exists();
       
   230         taskAfter.EndTask();
       
   231     
       
   232         delete entry;
       
   233         entry = NULL;
       
   234         CleanupStack::PopAndDestroy(&wsSession);
       
   235          );
       
   236     QCOMPARE(err, KErrNone);
       
   237     QCOMPARE(errorOpen, KErrNone);
       
   238     //QEXPECT_FAIL("", "No web browser now, so the check for running browser is expect to fail.\n"
       
   239     //        "Ensure once the browser is available this failure expectation is removed.",
       
   240     //        Continue);
       
   241     QVERIFY(started);
       
   242 }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 void T_CaUrlHandler::urlHandlerCreateInstance()
       
   249 {
       
   250     QServiceManager serviceManager;
       
   251     CaUrlHandlerPlugin plugin;
       
   252     QServiceFilter serviceFilter("com.nokia.homescreen.ICommandHandler");
       
   253     serviceFilter.setCustomAttribute("entryTypeName", "application");
       
   254     QList<QServiceInterfaceDescriptor> serviceInterfaceDescriptorList =
       
   255         serviceManager.findInterfaces(serviceFilter);
       
   256     int len = serviceInterfaceDescriptorList.size();
       
   257     QVERIFY(len>0);
       
   258     QServiceInterfaceDescriptor serviceInterfaceDescriptor =
       
   259         serviceInterfaceDescriptorList[0];
       
   260     QObject *handler = plugin.createInstance(
       
   261         serviceInterfaceDescriptor, NULL, NULL);
       
   262     QVERIFY(handler);
       
   263     delete handler;
       
   264 }
       
   265 
       
   266 QTEST_MAIN(T_CaUrlHandler)