125
|
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 |
#include "t_afactivation.h"
|
|
18 |
|
|
19 |
#include <QtTest/QtTest>
|
|
20 |
|
|
21 |
#include "afactivation.h"
|
|
22 |
#include "afactivation_p.h"
|
|
23 |
#include "applicationlauncher_p.h"
|
|
24 |
|
|
25 |
TestAfActivation::TestAfActivation()
|
|
26 |
{
|
|
27 |
mDefaultActivityName = QString("appto://EBADC0DE?%1=TestActivity&TestParam=TestValue").arg(
|
|
28 |
Af::KActivityUriNameKey);
|
|
29 |
qRegisterMetaType<Af::ActivationReason> ("Af::ActivationReason");
|
|
30 |
}
|
|
31 |
|
|
32 |
void TestAfActivation::init()
|
|
33 |
{
|
|
34 |
mActivation = new AfActivation();
|
|
35 |
mServiceProvider = AfStorageProxy::instance;
|
|
36 |
}
|
|
37 |
|
|
38 |
void TestAfActivation::cleanup()
|
|
39 |
{
|
|
40 |
delete mActivation;
|
|
41 |
mActivation = NULL;
|
|
42 |
}
|
|
43 |
|
|
44 |
void TestAfActivation::invokeActivationPublicInterface()
|
|
45 |
{
|
|
46 |
// AfActivation is only responsible of correct creation of AfActivationPrivate and
|
|
47 |
// forwarding requests. Since it's impossible to verify the effects of the member
|
|
48 |
// calls, just invoke the methods.
|
|
49 |
AfActivation activation;
|
|
50 |
|
|
51 |
activation.parameters();
|
|
52 |
activation.reason();
|
|
53 |
activation.name();
|
|
54 |
}
|
|
55 |
|
|
56 |
void TestAfActivation::invokeActivationPublicInterfaceCorrupt()
|
|
57 |
{
|
|
58 |
bool errorReceived = false;
|
|
59 |
//af storage proxy is mocked so I can set static variable making it leave
|
|
60 |
AfStorageProxy::waitFailed = true;
|
|
61 |
try
|
|
62 |
{
|
|
63 |
AfActivation *activation = new AfActivation();
|
|
64 |
}
|
|
65 |
catch(...)
|
|
66 |
{
|
|
67 |
errorReceived = true;
|
|
68 |
}
|
|
69 |
QVERIFY(errorReceived);
|
|
70 |
}
|
|
71 |
|
|
72 |
void TestAfActivation::testDefaultValuesAfterCreation()
|
|
73 |
{
|
|
74 |
QCOMPARE(mActivation->parameters(), QVariantHash());
|
|
75 |
QCOMPARE(mActivation->reason(), Af::ActivationReasonNormal);
|
|
76 |
QCOMPARE(mActivation->name(), QString());
|
|
77 |
}
|
|
78 |
|
|
79 |
void TestAfActivation::testSignalIsEmittedWhenActivityIsRequested()
|
|
80 |
{
|
|
81 |
QSignalSpy activatedSpy(mActivation,
|
|
82 |
SIGNAL(activated(Af::ActivationReason,QString,QVariantHash)));
|
|
83 |
QVERIFY(activatedSpy.isValid());
|
|
84 |
|
|
85 |
mServiceProvider->emitActivityRequested(mDefaultActivityName);
|
|
86 |
|
|
87 |
QCOMPARE(activatedSpy.count(), 1);
|
|
88 |
}
|
|
89 |
|
|
90 |
void TestAfActivation::testValuesChangeWhenActivityIsRequested()
|
|
91 |
{
|
|
92 |
QSignalSpy activatedSpy(mActivation,
|
|
93 |
SIGNAL(activated(Af::ActivationReason,QString,QVariantHash)));
|
|
94 |
QVERIFY(activatedSpy.isValid());
|
|
95 |
|
|
96 |
mServiceProvider->emitActivityRequested(mDefaultActivityName);
|
|
97 |
|
|
98 |
QCOMPARE(activatedSpy.count(), 1);
|
|
99 |
QCOMPARE(mActivation->reason(), Af::ActivationReasonActivity);
|
|
100 |
QCOMPARE(mActivation->name(), QString("TestActivity"));
|
|
101 |
QVERIFY(mActivation->parameters().contains("TestParam"));
|
|
102 |
QCOMPARE(mActivation->parameters().value("TestParam").toString(), QString("TestValue"));
|
|
103 |
}
|
|
104 |
|
|
105 |
void TestAfActivation::testValuesChangeWhenActivityIsRequestedNoName()
|
|
106 |
{
|
|
107 |
QString activityname("appto://EBADC0DE?TestParam=TestValue");
|
|
108 |
QSignalSpy activatedSpy(mActivation,
|
|
109 |
SIGNAL(activated(Af::ActivationReason,QString,QVariantHash)));
|
|
110 |
QVERIFY(activatedSpy.isValid());
|
|
111 |
|
|
112 |
mServiceProvider->emitActivityRequested(activityname);
|
|
113 |
QCOMPARE(activatedSpy.count(), 1);
|
|
114 |
|
|
115 |
QCOMPARE(mActivation->reason(), Af::ActivationReasonActivity);
|
|
116 |
QCOMPARE(mActivation->name(), QString());
|
|
117 |
QVERIFY(mActivation->parameters().contains("TestParam"));
|
|
118 |
QCOMPARE(mActivation->parameters().value("TestParam").toString(), QString("TestValue"));
|
|
119 |
}
|
|
120 |
|
|
121 |
void TestAfActivation::testChangingActivityInBackground()
|
|
122 |
{
|
|
123 |
// bring to foreground is called by default
|
|
124 |
mServiceProvider->emitActivityRequested(mDefaultActivityName);
|
|
125 |
|
|
126 |
ApplicationLauncherPrivate *launcher = ApplicationLauncherPrivate::instance;
|
|
127 |
QVERIFY(launcher);
|
|
128 |
QCOMPARE(launcher->bringToForegroundCalls.count(), 1);
|
|
129 |
launcher->bringToForegroundCalls.clear();
|
|
130 |
|
|
131 |
// bring to foreground is not called if background parameter is present
|
|
132 |
mServiceProvider->emitActivityRequested(
|
|
133 |
QString("appto://EBADC0DE?%1=TestActivity&%2=").arg(Af::KActivityUriNameKey).arg(
|
|
134 |
Af::KActivityUriBackgroundKey));
|
|
135 |
|
|
136 |
launcher = ApplicationLauncherPrivate::instance;
|
|
137 |
QVERIFY(launcher);
|
|
138 |
QCOMPARE(launcher->bringToForegroundCalls.count(), 0);
|
|
139 |
}
|
|
140 |
|
|
141 |
QTEST_MAIN(TestAfActivation)
|