0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
#include <QStandardItemModel>
|
|
45 |
#include <qdebug.h>
|
|
46 |
#include <qdesktopservices.h>
|
|
47 |
|
|
48 |
//#define RUN_MANUAL_TESTS
|
|
49 |
//TESTED_CLASS=
|
|
50 |
//TESTED_FILES=
|
|
51 |
|
|
52 |
class tst_qdesktopservices : public QObject {
|
|
53 |
Q_OBJECT
|
|
54 |
|
|
55 |
public:
|
|
56 |
tst_qdesktopservices();
|
|
57 |
virtual ~tst_qdesktopservices();
|
|
58 |
|
|
59 |
private slots:
|
|
60 |
void init();
|
|
61 |
void cleanup();
|
|
62 |
void openUrl();
|
|
63 |
#ifdef Q_OS_SYMBIAN
|
|
64 |
// These test are manual ones, you need to check from device that
|
|
65 |
// correct system application is started with correct content
|
|
66 |
// When you want to run these test, uncomment //#define RUN_MANUAL_TESTS
|
|
67 |
void openHttpUrl_data();
|
|
68 |
void openHttpUrl();
|
|
69 |
void openMailtoUrl_data();
|
|
70 |
void openMailtoUrl();
|
|
71 |
void openFileUrl_data();
|
|
72 |
void openFileUrl();
|
|
73 |
#endif
|
|
74 |
void handlers();
|
|
75 |
void storageLocation_data();
|
|
76 |
void storageLocation();
|
|
77 |
|
|
78 |
void storageLocationDoesNotEndWithSlash_data();
|
|
79 |
void storageLocationDoesNotEndWithSlash();
|
|
80 |
|
|
81 |
protected:
|
|
82 |
};
|
|
83 |
|
|
84 |
tst_qdesktopservices::tst_qdesktopservices()
|
|
85 |
{
|
|
86 |
QCoreApplication::setOrganizationName("Nokia");
|
|
87 |
QCoreApplication::setApplicationName("tst_qdesktopservices");
|
|
88 |
}
|
|
89 |
|
|
90 |
tst_qdesktopservices::~tst_qdesktopservices()
|
|
91 |
{
|
|
92 |
}
|
|
93 |
|
|
94 |
void tst_qdesktopservices::init()
|
|
95 |
{
|
|
96 |
}
|
|
97 |
|
|
98 |
void tst_qdesktopservices::cleanup()
|
|
99 |
{
|
|
100 |
}
|
|
101 |
|
|
102 |
void tst_qdesktopservices::openUrl()
|
|
103 |
{
|
|
104 |
// At the bare minimum check that they return false for invalid url's
|
|
105 |
QCOMPARE(QDesktopServices::openUrl(QUrl()), false);
|
|
106 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
|
|
107 |
// this test is only valid on windows on other systems it might mean open a new document in the application handling .file
|
|
108 |
QCOMPARE(QDesktopServices::openUrl(QUrl("file://invalid.file")), false);
|
|
109 |
#endif
|
|
110 |
}
|
|
111 |
|
|
112 |
#ifdef Q_OS_SYMBIAN
|
|
113 |
void tst_qdesktopservices::openHttpUrl_data()
|
|
114 |
{
|
|
115 |
QTest::addColumn<QUrl>("url");
|
|
116 |
QTest::addColumn<bool>("result");
|
|
117 |
QTest::newRow("BasicWithHttp") << QUrl("http://www.google.fi") << true;
|
|
118 |
QTest::newRow("BasicWithoutHttp") << QUrl("www.nokia.fi") << true;
|
|
119 |
QTest::newRow("BasicWithUserAndPw") << QUrl("http://s60prereleases:oslofjord@pepper.troll.no/s60prereleases/patches/") << true;
|
|
120 |
QTest::newRow("URL with space") << QUrl("http://www.manataka.org/Contents Page.html") << true;
|
|
121 |
|
|
122 |
}
|
|
123 |
|
|
124 |
void tst_qdesktopservices::openHttpUrl()
|
|
125 |
{
|
|
126 |
#ifndef RUN_MANUAL_TESTS
|
|
127 |
QSKIP("Test disabled -- only for manual purposes", SkipAll);
|
|
128 |
#endif
|
|
129 |
|
|
130 |
QFETCH(QUrl, url);
|
|
131 |
QFETCH(bool, result);
|
|
132 |
QCOMPARE(QDesktopServices::openUrl(url), result);
|
|
133 |
QTest::qWait(30000);
|
|
134 |
}
|
|
135 |
|
|
136 |
void tst_qdesktopservices::openMailtoUrl_data()
|
|
137 |
{
|
|
138 |
QTest::addColumn<QUrl>("url");
|
|
139 |
QTest::addColumn<bool>("result");
|
|
140 |
|
|
141 |
// http://en.wikipedia.org/wiki/E-mail_address
|
|
142 |
// RFC Valid e-mail addresses
|
|
143 |
QTest::newRow("Wiki valid email 1") << QUrl("mailto:abc@example.com") << true;
|
|
144 |
QTest::newRow("Wiki valid email 2") << QUrl("mailto:Abc@example.com") << true;
|
|
145 |
QTest::newRow("Wiki valid email 3") << QUrl("mailto:aBC@example.com") << true;
|
|
146 |
QTest::newRow("Wiki valid email 4") << QUrl("mailto:abc.123@example.com") << true;
|
|
147 |
QTest::newRow("Wiki valid email 5") << QUrl("mailto:1234567890@example.com") << true;
|
|
148 |
QTest::newRow("Wiki valid email 6") << QUrl("mailto:_______@example.com") << true;
|
|
149 |
QTest::newRow("Wiki valid email 7") << QUrl("mailto:abc+mailbox/department=shipping@example.com") << true;
|
|
150 |
// S60 email client considers the next URL invalid, even ity should be valid
|
|
151 |
QTest::newRow("Wiki valid email 8") << QUrl("mailto:!#$%&'*+-/=?^_`.{|}~@example.com") << true; // all of these characters are allowed
|
|
152 |
QTest::newRow("Wiki valid email 9") << QUrl("mailto:\"abc@def\"@example.com") << true; // anything goes inside quotation marks
|
|
153 |
QTest::newRow("Wiki valid email 10") << QUrl("mailto:\"Fred \\\"quota\\\" Bloggs\"@example.com") << true; // however, quotes need escaping
|
|
154 |
|
|
155 |
// RFC invalid e-mail addresses
|
|
156 |
// These return true even though they are invalid, but check that user is notified about invalid URL in mail application
|
|
157 |
QTest::newRow("Wiki invalid email 1") << QUrl("mailto:Abc.example.com") << true; // character @ is missing
|
|
158 |
QTest::newRow("Wiki invalid email 2") << QUrl("mailto:Abc.@example.com") << true; // character dot(.) is last in local part
|
|
159 |
QTest::newRow("Wiki invalid email 3") << QUrl("mailto:Abc..123@example.com") << true; // character dot(.) is double
|
|
160 |
QTest::newRow("Wiki invalid email 4") << QUrl("mailto:A@b@c@example.com") << true; // only one @ is allowed outside quotations marks
|
|
161 |
QTest::newRow("Wiki invalid email 5") << QUrl("mailto:()[]\\;:,<>@example.com") << true; // none of the characters before the @ is allowed outside quotation marks
|
|
162 |
|
|
163 |
QTest::newRow("Basic") << QUrl("mailto:test@nokia.com") << true;
|
|
164 |
QTest::newRow("BasicSeveralAddr") << QUrl("mailto:test@nokia.com,test2@nokia.com,test3@nokia.com") << true;
|
|
165 |
QTest::newRow("BasicAndSubject") << QUrl("mailto:test@nokia.com?subject=hello nokia") << true;
|
|
166 |
QTest::newRow("BasicAndTo") << QUrl("mailto:test@nokia.com?to=test2@nokia.com") << true;
|
|
167 |
|
|
168 |
QTest::newRow("BasicAndCc") << QUrl("mailto:test@nokia.com?cc=mycc@address.com") << true;
|
|
169 |
QTest::newRow("BasicAndBcc") << QUrl("mailto:test@nokia.com?bcc=mybcc@address.com") << true;
|
|
170 |
QTest::newRow("BasicAndBody") << QUrl("mailto:test@nokia.com?body=Test email message body") << true;
|
|
171 |
|
|
172 |
// RFC examples, these are actually invalid because there is not host defined
|
|
173 |
// Check that user is notified about invalid URL in mail application
|
|
174 |
QTest::newRow("RFC2368 Example 1") << QUrl::fromEncoded("mailto:addr1%2C%20addr2") << true;
|
|
175 |
QTest::newRow("RFC2368 Example 2") << QUrl::fromEncoded("mailto:?to=addr1%2C%20addr2") << true;
|
|
176 |
QTest::newRow("RFC2368 Example 3") << QUrl("mailto:addr1?to=addr2") << true;
|
|
177 |
|
|
178 |
QTest::newRow("RFC2368 Example 4") << QUrl("mailto:joe@example.com?cc=bob@example.com&body=hello") << true;
|
|
179 |
QTest::newRow("RFC2368 Example 5") << QUrl("mailto:?to=joe@example.com&cc=bob@example.com&body=hello") << true;
|
|
180 |
QTest::newRow("RFC2368 Example 6") << QUrl("mailto:foobar@example.com?In-Reply-To=%3c3469A91.D10AF4C@example.com") << true; // OpaqueData
|
|
181 |
QTest::newRow("RFC2368 Example 7") << QUrl::fromEncoded("mailto:infobot@example.com?body=send%20current-issue%0D%0Asend%20index") << true;
|
|
182 |
QTest::newRow("RFC2368 Example 8") << QUrl::fromEncoded("mailto:infobot@example.com?body=send%20current-issue") << true;
|
|
183 |
QTest::newRow("RFC2368 Example 9") << QUrl("mailto:infobot@example.com?subject=current-issue") << true;
|
|
184 |
QTest::newRow("RFC2368 Example 10") << QUrl("mailto:chris@example.com") << true;
|
|
185 |
|
|
186 |
//QTest::newRow("RFC2368 Example 11 - illegal chars") << QUrl("mailto:joe@example.com?cc=bob@example.com?body=hello") << false;
|
|
187 |
QTest::newRow("RFC2368 Example 12") << QUrl::fromEncoded("mailto:gorby%25kremvax@example.com") << true; // encoded reserved chars '%'
|
|
188 |
QTest::newRow("RFC2368 Example 13") << QUrl::fromEncoded("mailto:unlikely%3Faddress@example.com?blat=foop") << true; // encoded reserved chars `?'
|
|
189 |
}
|
|
190 |
|
|
191 |
void tst_qdesktopservices::openMailtoUrl()
|
|
192 |
{
|
|
193 |
#ifndef RUN_MANUAL_TESTS
|
|
194 |
QSKIP("Test disabled -- only for manual purposes", SkipAll);
|
|
195 |
#endif
|
|
196 |
|
|
197 |
QFETCH(QUrl, url);
|
|
198 |
QFETCH(bool, result);
|
|
199 |
QCOMPARE(QDesktopServices::openUrl(url), result);
|
|
200 |
}
|
|
201 |
|
|
202 |
void tst_qdesktopservices::openFileUrl_data()
|
|
203 |
{
|
|
204 |
QTest::addColumn<QUrl>("url");
|
|
205 |
QTest::addColumn<bool>("result");
|
|
206 |
|
|
207 |
// Text files
|
|
208 |
QTest::newRow("DOS text file") << QUrl("file:///c:/data/others/dosfile.txt") << true;
|
|
209 |
QTest::newRow("No EOF text file") << QUrl("file:///c:/data/others/noendofline.txt") << true;
|
|
210 |
QTest::newRow("text file") << QUrl("file:///c:/data/others/testfile.txt") << true;
|
|
211 |
QTest::newRow("text file with space") << QUrl("file:///c:/data/others/test file.txt") << true;
|
|
212 |
|
|
213 |
// Images
|
|
214 |
QTest::newRow("BMP image") << QUrl("file:///c:/data/images/image.bmp") << true;
|
|
215 |
QTest::newRow("GIF image") << QUrl("file:///c:/data/images/image.gif") << true;
|
|
216 |
QTest::newRow("JPG image") << QUrl("file:///c:/data/images/image.jpg") << true;
|
|
217 |
QTest::newRow("PNG image") << QUrl("file:///c:/data/images/image.png") << true;
|
|
218 |
|
|
219 |
// Audio
|
|
220 |
QTest::newRow("MP4 audio") << QUrl("file:///c:/data/sounds/aac-only.mp4") << true;
|
|
221 |
QTest::newRow("3GP audio") << QUrl("file:///c:/data/sounds/audio_3gpp.3gp") << true;
|
|
222 |
|
|
223 |
// Video
|
|
224 |
QTest::newRow("MP4 video") << QUrl("file:///c:/data/videos/vid-mpeg4-22k.mp4") << true;
|
|
225 |
|
|
226 |
// Installs
|
|
227 |
QTest::newRow("SISX") << QUrl("file:///c:/data/installs/ErrRd.sisx") << true;
|
|
228 |
|
|
229 |
// Errors
|
|
230 |
QTest::newRow("File does not exist") << QUrl("file:///c:/thisfileneverexists.txt") << false;
|
|
231 |
}
|
|
232 |
|
|
233 |
void tst_qdesktopservices::openFileUrl()
|
|
234 |
{
|
|
235 |
#ifndef RUN_MANUAL_TESTS
|
|
236 |
QSKIP("Test disabled -- only for manual purposes", SkipAll);
|
|
237 |
#endif
|
|
238 |
|
|
239 |
QFETCH(QUrl, url);
|
|
240 |
QFETCH(bool, result);
|
|
241 |
QCOMPARE(QDesktopServices::openUrl(url), result);
|
|
242 |
QTest::qWait(15000);
|
|
243 |
}
|
|
244 |
#endif
|
|
245 |
|
|
246 |
|
|
247 |
class MyUrlHandler : public QObject
|
|
248 |
{
|
|
249 |
Q_OBJECT
|
|
250 |
public:
|
|
251 |
QUrl lastHandledUrl;
|
|
252 |
|
|
253 |
public slots:
|
|
254 |
inline void handle(const QUrl &url) {
|
|
255 |
lastHandledUrl = url;
|
|
256 |
}
|
|
257 |
};
|
|
258 |
|
|
259 |
void tst_qdesktopservices::handlers()
|
|
260 |
{
|
|
261 |
MyUrlHandler fooHandler;
|
|
262 |
MyUrlHandler barHandler;
|
|
263 |
|
|
264 |
QDesktopServices::setUrlHandler(QString("foo"), &fooHandler, "handle");
|
|
265 |
QDesktopServices::setUrlHandler(QString("bar"), &barHandler, "handle");
|
|
266 |
|
|
267 |
QUrl fooUrl("foo://blub/meh");
|
|
268 |
QUrl barUrl("bar://hmm/hmmmm");
|
|
269 |
|
|
270 |
QVERIFY(QDesktopServices::openUrl(fooUrl));
|
|
271 |
QVERIFY(QDesktopServices::openUrl(barUrl));
|
|
272 |
|
|
273 |
QCOMPARE(fooHandler.lastHandledUrl.toString(), fooUrl.toString());
|
|
274 |
QCOMPARE(barHandler.lastHandledUrl.toString(), barUrl.toString());
|
|
275 |
}
|
|
276 |
|
|
277 |
Q_DECLARE_METATYPE(QDesktopServices::StandardLocation)
|
|
278 |
void tst_qdesktopservices::storageLocation_data()
|
|
279 |
{
|
|
280 |
QTest::addColumn<QDesktopServices::StandardLocation>("location");
|
|
281 |
QTest::newRow("DesktopLocation") << QDesktopServices::DesktopLocation;
|
|
282 |
QTest::newRow("DocumentsLocation") << QDesktopServices::DocumentsLocation;
|
|
283 |
QTest::newRow("FontsLocation") << QDesktopServices::FontsLocation;
|
|
284 |
QTest::newRow("ApplicationsLocation") << QDesktopServices::ApplicationsLocation;
|
|
285 |
QTest::newRow("MusicLocation") << QDesktopServices::MusicLocation;
|
|
286 |
QTest::newRow("MoviesLocation") << QDesktopServices::MoviesLocation;
|
|
287 |
QTest::newRow("PicturesLocation") << QDesktopServices::PicturesLocation;
|
|
288 |
QTest::newRow("TempLocation") << QDesktopServices::TempLocation;
|
|
289 |
QTest::newRow("HomeLocation") << QDesktopServices::HomeLocation;
|
|
290 |
QTest::newRow("DataLocation") << QDesktopServices::DataLocation;
|
|
291 |
}
|
|
292 |
|
|
293 |
void tst_qdesktopservices::storageLocation()
|
|
294 |
{
|
|
295 |
QFETCH(QDesktopServices::StandardLocation, location);
|
|
296 |
#ifdef Q_OS_SYMBIAN
|
|
297 |
QString storageLocation = QDesktopServices::storageLocation(location);
|
|
298 |
QString displayName = QDesktopServices::displayName(location);
|
|
299 |
//qDebug( "displayName: %s", displayName );
|
|
300 |
|
|
301 |
storageLocation = storageLocation.toLower();
|
|
302 |
displayName = displayName.toLower();
|
|
303 |
|
|
304 |
QString drive = QDir::currentPath().left(2).toLower();
|
|
305 |
if( drive == "z:" )
|
|
306 |
drive = "c:";
|
|
307 |
|
|
308 |
switch(location) {
|
|
309 |
case QDesktopServices::DesktopLocation:
|
|
310 |
QCOMPARE( storageLocation, drive + QString("/data") );
|
|
311 |
break;
|
|
312 |
case QDesktopServices::DocumentsLocation:
|
|
313 |
QCOMPARE( storageLocation, drive + QString("/data") );
|
|
314 |
break;
|
|
315 |
case QDesktopServices::FontsLocation:
|
|
316 |
// Currently point always to ROM
|
|
317 |
QCOMPARE( storageLocation, QString("z:/resource/fonts") );
|
|
318 |
break;
|
|
319 |
case QDesktopServices::ApplicationsLocation:
|
|
320 |
#ifdef Q_CC_NOKIAX86
|
|
321 |
QCOMPARE( storageLocation, QString("z:/sys/bin") );
|
|
322 |
#else
|
|
323 |
QCOMPARE( storageLocation, drive + QString("/sys/bin") );
|
|
324 |
#endif
|
|
325 |
break;
|
|
326 |
case QDesktopServices::MusicLocation:
|
|
327 |
QCOMPARE( storageLocation, drive + QString("/data/sounds") );
|
|
328 |
break;
|
|
329 |
case QDesktopServices::MoviesLocation:
|
|
330 |
QCOMPARE( storageLocation, drive + QString("/data/videos") );
|
|
331 |
break;
|
|
332 |
case QDesktopServices::PicturesLocation:
|
|
333 |
QCOMPARE( storageLocation, drive + QString("/data/images") );
|
|
334 |
break;
|
|
335 |
case QDesktopServices::TempLocation:
|
|
336 |
QCOMPARE( storageLocation, QDir::tempPath().toLower());
|
|
337 |
break;
|
|
338 |
case QDesktopServices::HomeLocation:
|
|
339 |
QCOMPARE( storageLocation, QDir::homePath().toLower());
|
|
340 |
break;
|
|
341 |
case QDesktopServices::DataLocation:
|
|
342 |
// Just check the folder not the drive
|
|
343 |
QCOMPARE( storageLocation.mid(2), QDir::currentPath().mid(2).toLower());
|
|
344 |
break;
|
|
345 |
default:
|
|
346 |
QCOMPARE( storageLocation, QString() );
|
|
347 |
break;
|
|
348 |
}
|
|
349 |
|
|
350 |
#else
|
|
351 |
QDesktopServices::storageLocation(location);
|
|
352 |
QDesktopServices::displayName(location);
|
|
353 |
#endif
|
|
354 |
}
|
|
355 |
|
|
356 |
|
|
357 |
void tst_qdesktopservices::storageLocationDoesNotEndWithSlash_data()
|
|
358 |
{
|
|
359 |
storageLocation_data();
|
|
360 |
}
|
|
361 |
|
|
362 |
void tst_qdesktopservices::storageLocationDoesNotEndWithSlash()
|
|
363 |
{
|
|
364 |
// Currently all desktop locations return their storage location
|
|
365 |
// with "Unix-style" paths (i.e. they use a slash, not backslash).
|
|
366 |
QFETCH(QDesktopServices::StandardLocation, location);
|
|
367 |
QString loc = QDesktopServices::storageLocation(location);
|
|
368 |
if (loc.size() > 1) // workaround for unlikely case of locations that return '/'
|
|
369 |
QCOMPARE(loc.endsWith(QLatin1Char('/')), false);
|
|
370 |
}
|
|
371 |
|
|
372 |
|
|
373 |
QTEST_MAIN(tst_qdesktopservices)
|
|
374 |
#include "tst_qdesktopservices.moc"
|