/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/
/*
* T_caapphandlerplugin.cpp
*
* Created on: 2009-09-16
* Author:
*/
// for CleanupResetAndDestroyPushL
#include <mmf/common/mmfcontrollerpluginresolver.h>
#include <w32std.h>
#include <apgtask.h>
#include <apgcli.h>
#include <qservicemanager.h>
#include <cadef.h>
#include "T_caurlhandlerplugin.h"
#include "waitactive.h"
#include "caurlhandler.h"
#include "caurlhandlerplugin.h"
#include "caentry.h"
QTM_USE_NAMESPACE
const TInt KBrowserUid = { 0x10008D39 };
static const char caUrlAddress[] = "http://www.nokia.com";
static const char caTypeUrl[] = "url";
static const char caAttrUrl[] = "url";
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
T_CaUrlHandler::T_CaUrlHandler():
iUrlHandler(NULL)
{
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_CaUrlHandler::cleanup()
{
delete iUrlHandler;
iUrlHandler = NULL;
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_CaUrlHandler::initTestCase()
{
QStringList pluginPaths;
QString xmlName("caurlhandlerplugin.xml");
pluginPaths.append("c:/resource/qt/plugins/commandhandler");
pluginPaths.append("z:/resource/qt/plugins/commandhandler");
QServiceManager serviceManager;
foreach (QString path, pluginPaths) {
QApplication::addLibraryPath(path);
QDir dir(path);
if (dir.exists(xmlName)) {
serviceManager.addService(dir.absoluteFilePath(xmlName));
}
}
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_CaUrlHandler::urlHandlerConstruction()
{
delete iUrlHandler;
iUrlHandler = NULL;
TInt error = KErrNone;
QT_TRYCATCH_ERROR(error, iUrlHandler = new CaUrlHandler());
QCOMPARE(error, KErrNone);
QVERIFY(iUrlHandler);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_CaUrlHandler::urlHandlerMultipleLoad()
{
RPointerArray<CaUrlHandler> handlerArray;
bool foundNull(false);
TRAPD(err,
CleanupResetAndDestroyPushL(handlerArray);
for (TInt i(0); i < 10; ++i) {
handlerArray.AppendL(
new CaUrlHandler());
if (handlerArray[i] == NULL) {
foundNull = true;
break;
}
}
CleanupStack::PopAndDestroy(&handlerArray);
);
QCOMPARE(err, KErrNone);
QVERIFY(!foundNull);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_CaUrlHandler::urlHandlerMultipleLoadAndDelete()
{
bool foundNull(false);
CaUrlHandler *handlerPtr(NULL);
for (TInt i(0); i < 10; ++i) {
handlerPtr = new CaUrlHandler();
if (handlerPtr == NULL) {
foundNull = true;
break;
};
delete handlerPtr;
handlerPtr = NULL;
}
QVERIFY(!foundNull);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_CaUrlHandler::urlHandlerOpenFails()
{
urlHandlerConstruction();
TInt errorUnsupportedCommand(KErrNone);
TInt errorOpen(KErrNone);
bool notStarted(false);
RWsSession wsSession;
TRAPD(err,
CleanupClosePushL(wsSession);
User::LeaveIfError(wsSession.Connect());
TApaTaskList taskList(wsSession);
TApaTask taskBefore = taskList.FindApp(TUid::Uid(KBrowserUid));
if (taskBefore.Exists()) {
taskBefore.EndTask();
}
CaEntry *entry = new CaEntry();
// valid entry type name
entry->setEntryTypeName(caTypeUrl);
//invalid command name
errorUnsupportedCommand = iUrlHandler->execute(
*entry, "unsupported_command_name");
// no attribute
errorOpen = iUrlHandler->execute(*entry, caCmdOpen);
QTest::qWait(3000);
TApaTask taskAfter = taskList.FindApp(TUid::Uid(KBrowserUid));
notStarted = !taskAfter.Exists();
delete entry;
entry = NULL;
CleanupStack::PopAndDestroy(&wsSession);
);
QCOMPARE(err, KErrNone);
QCOMPARE(errorUnsupportedCommand, errorUnsupportedCommand);
//QCOMPARE(errorUnsupportedCommand, KErrNotSupported);
QVERIFY(notStarted);
QCOMPARE(errorOpen, KErrGeneral);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
/* uncomment and check test when browser is in TB10.1 platfrom */
void T_CaUrlHandler::urlHandlerRunApplication()
{
urlHandlerConstruction();
TInt errorOpen(KErrNone);
bool started(false);
TRAPD(err,
CaEntry *entry = new CaEntry();
RWsSession wsSession;
CleanupClosePushL(wsSession);
User::LeaveIfError(wsSession.Connect());
TApaTaskList taskList(wsSession);
TApaTask taskBefore = taskList.FindApp(TUid::Uid(KBrowserUid));
if (taskBefore.Exists()) {
taskBefore.EndTask();
}
// valid data needed to launch url
entry->setEntryTypeName(caTypeUrl);
entry->setAttribute(caAttrUrl,caUrlAddress);
errorOpen = iUrlHandler->execute(*entry, caCmdOpen);
QTest::qWait(3000);
TApaTask taskAfter = taskList.FindApp(TUid::Uid(KBrowserUid));
started = taskAfter.Exists();
taskAfter.EndTask();
delete entry;
entry = NULL;
CleanupStack::PopAndDestroy(&wsSession);
);
QCOMPARE(err, KErrNone);
QCOMPARE(errorOpen, KErrNone);
//QEXPECT_FAIL("", "No web browser now, so the check for running browser is expect to fail.\n"
// "Ensure once the browser is available this failure expectation is removed.",
// Continue);
QVERIFY(started);
}
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
void T_CaUrlHandler::urlHandlerCreateInstance()
{
QServiceManager serviceManager;
CaUrlHandlerPlugin plugin;
QServiceFilter serviceFilter("com.nokia.homescreen.ICommandHandler");
serviceFilter.setCustomAttribute("entryTypeName", "application");
QList<QServiceInterfaceDescriptor> serviceInterfaceDescriptorList =
serviceManager.findInterfaces(serviceFilter);
int len = serviceInterfaceDescriptorList.size();
QVERIFY(len>0);
QServiceInterfaceDescriptor serviceInterfaceDescriptor =
serviceInterfaceDescriptorList[0];
QObject *handler = plugin.createInstance(
serviceInterfaceDescriptor, NULL, NULL);
QVERIFY(handler);
delete handler;
}
QTEST_MAIN(T_CaUrlHandler)