author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 <qtextbrowser.h> |
|
45 |
#include <qdatetime.h> |
|
46 |
#include <qapplication.h> |
|
47 |
#include <qscrollbar.h> |
|
48 |
||
49 |
#include <qtextbrowser.h> |
|
50 |
#include <qtextobject.h> |
|
51 |
||
52 |
#include "../../shared/util.h" |
|
53 |
||
54 |
//TESTED_CLASS= |
|
55 |
//TESTED_FILES= |
|
56 |
||
57 |
#if defined(Q_OS_SYMBIAN) |
|
58 |
# define SRCDIR "" |
|
59 |
#endif |
|
60 |
||
61 |
class TestBrowser : public QTextBrowser |
|
62 |
{ |
|
63 |
public: |
|
64 |
inline TestBrowser() : htmlLoadAttempts(0) { |
|
65 |
show(); |
|
66 |
QApplication::setActiveWindow(this); |
|
67 |
QTest::qWaitForWindowShown(this); |
|
68 |
activateWindow(); |
|
69 |
setFocus(); |
|
70 |
QTest::qWait(50); |
|
71 |
QTRY_VERIFY(hasFocus()); |
|
72 |
} |
|
73 |
||
74 |
virtual QVariant loadResource(int type, const QUrl &name); |
|
75 |
||
76 |
int htmlLoadAttempts; |
|
77 |
QUrl lastResource; |
|
78 |
QUrl sourceInsideLoadResource; |
|
79 |
}; |
|
80 |
||
81 |
QVariant TestBrowser::loadResource(int type, const QUrl &name) |
|
82 |
{ |
|
83 |
if (type == QTextDocument::HtmlResource) |
|
84 |
htmlLoadAttempts++; |
|
85 |
lastResource = name; |
|
86 |
sourceInsideLoadResource = source(); |
|
87 |
return QTextBrowser::loadResource(type, name); |
|
88 |
} |
|
89 |
||
90 |
class tst_QTextBrowser : public QObject |
|
91 |
{ |
|
92 |
Q_OBJECT |
|
93 |
public: |
|
94 |
tst_QTextBrowser(); |
|
95 |
virtual ~tst_QTextBrowser(); |
|
96 |
||
97 |
public slots: |
|
98 |
void init(); |
|
99 |
void cleanup(); |
|
100 |
||
101 |
private slots: |
|
102 |
void noReloadOnAnchorJump(); |
|
103 |
void bgColorOnSourceChange(); |
|
104 |
void forwardButton(); |
|
105 |
void viewportPositionInHistory(); |
|
106 |
void relativeLinks(); |
|
107 |
void anchors(); |
|
108 |
void resourceAutoDetection(); |
|
109 |
void forwardBackwardAvailable(); |
|
110 |
void clearHistory(); |
|
111 |
void sourceInsideLoadResource(); |
|
112 |
void textInteractionFlags_vs_readOnly(); |
|
113 |
void anchorsWithSelfBuiltHtml(); |
|
114 |
void relativeNonLocalUrls(); |
|
115 |
void adjacentAnchors(); |
|
116 |
void loadResourceOnRelativeLocalFiles(); |
|
117 |
void focusIndicator(); |
|
118 |
void focusHistory(); |
|
119 |
void urlEncoding(); |
|
120 |
||
121 |
private: |
|
122 |
TestBrowser *browser; |
|
123 |
}; |
|
124 |
||
125 |
tst_QTextBrowser::tst_QTextBrowser() |
|
126 |
{ |
|
127 |
} |
|
128 |
||
129 |
tst_QTextBrowser::~tst_QTextBrowser() |
|
130 |
{ |
|
131 |
} |
|
132 |
void tst_QTextBrowser::init() |
|
133 |
{ |
|
134 |
#if !defined(Q_OS_IRIX) && !defined(Q_OS_WINCE) |
|
135 |
QDir::setCurrent(SRCDIR); |
|
136 |
#endif |
|
137 |
browser = new TestBrowser; |
|
138 |
browser->show(); |
|
139 |
} |
|
140 |
||
141 |
void tst_QTextBrowser::cleanup() |
|
142 |
{ |
|
143 |
delete browser; |
|
144 |
browser = 0; |
|
145 |
} |
|
146 |
||
147 |
void tst_QTextBrowser::noReloadOnAnchorJump() |
|
148 |
{ |
|
149 |
QUrl url("anchor.html"); |
|
150 |
||
151 |
browser->htmlLoadAttempts = 0; |
|
152 |
browser->setSource(url); |
|
153 |
QCOMPARE(browser->htmlLoadAttempts, 1); |
|
154 |
QVERIFY(!browser->toPlainText().isEmpty()); |
|
155 |
||
156 |
url.setFragment("jumphere"); // anchor.html#jumphere |
|
157 |
browser->setSource(url); |
|
158 |
QCOMPARE(browser->htmlLoadAttempts, 1); |
|
159 |
QVERIFY(!browser->toPlainText().isEmpty()); |
|
160 |
QVERIFY(browser->source() == url); |
|
161 |
} |
|
162 |
||
163 |
void tst_QTextBrowser::bgColorOnSourceChange() |
|
164 |
{ |
|
165 |
browser->setSource(QUrl("pagewithbg.html")); |
|
166 |
QVERIFY(browser->document()->rootFrame()->frameFormat().hasProperty(QTextFormat::BackgroundBrush)); |
|
167 |
QVERIFY(browser->document()->rootFrame()->frameFormat().background().color() == Qt::blue); |
|
168 |
||
169 |
browser->setSource(QUrl("pagewithoutbg.html")); |
|
170 |
QVERIFY(!browser->document()->rootFrame()->frameFormat().hasProperty(QTextFormat::BackgroundBrush)); |
|
171 |
} |
|
172 |
||
173 |
void tst_QTextBrowser::forwardButton() |
|
174 |
{ |
|
175 |
QSignalSpy forwardEmissions(browser, SIGNAL(forwardAvailable(bool))); |
|
176 |
QSignalSpy backwardEmissions(browser, SIGNAL(backwardAvailable(bool))); |
|
177 |
||
178 |
QVERIFY(browser->historyTitle(-1).isEmpty()); |
|
179 |
QVERIFY(browser->historyTitle(0).isEmpty()); |
|
180 |
QVERIFY(browser->historyTitle(1).isEmpty()); |
|
181 |
||
182 |
browser->setSource(QUrl("pagewithbg.html")); |
|
183 |
||
184 |
QVERIFY(!forwardEmissions.isEmpty()); |
|
185 |
QVariant val = forwardEmissions.takeLast()[0]; |
|
186 |
QVERIFY(val.type() == QVariant::Bool); |
|
187 |
QVERIFY(val.toBool() == false); |
|
188 |
||
189 |
QVERIFY(!backwardEmissions.isEmpty()); |
|
190 |
val = backwardEmissions.takeLast()[0]; |
|
191 |
QVERIFY(val.type() == QVariant::Bool); |
|
192 |
QVERIFY(val.toBool() == false); |
|
193 |
||
194 |
QVERIFY(browser->historyTitle(-1).isEmpty()); |
|
195 |
QCOMPARE(browser->historyUrl(0), QUrl("pagewithbg.html")); |
|
196 |
QCOMPARE(browser->documentTitle(), QString("Page With BG")); |
|
197 |
QCOMPARE(browser->historyTitle(0), QString("Page With BG")); |
|
198 |
QVERIFY(browser->historyTitle(1).isEmpty()); |
|
199 |
||
200 |
browser->setSource(QUrl("anchor.html")); |
|
201 |
||
202 |
QVERIFY(!forwardEmissions.isEmpty()); |
|
203 |
val = forwardEmissions.takeLast()[0]; |
|
204 |
QVERIFY(val.type() == QVariant::Bool); |
|
205 |
QVERIFY(val.toBool() == false); |
|
206 |
||
207 |
QVERIFY(!backwardEmissions.isEmpty()); |
|
208 |
val = backwardEmissions.takeLast()[0]; |
|
209 |
QVERIFY(val.type() == QVariant::Bool); |
|
210 |
QVERIFY(val.toBool() == true); |
|
211 |
||
212 |
QCOMPARE(browser->historyTitle(-1), QString("Page With BG")); |
|
213 |
QCOMPARE(browser->historyTitle(0), QString("Sample Anchor")); |
|
214 |
QVERIFY(browser->historyTitle(1).isEmpty()); |
|
215 |
||
216 |
browser->backward(); |
|
217 |
||
218 |
QVERIFY(!forwardEmissions.isEmpty()); |
|
219 |
val = forwardEmissions.takeLast()[0]; |
|
220 |
QVERIFY(val.type() == QVariant::Bool); |
|
221 |
QVERIFY(val.toBool() == true); |
|
222 |
||
223 |
QVERIFY(!backwardEmissions.isEmpty()); |
|
224 |
val = backwardEmissions.takeLast()[0]; |
|
225 |
QVERIFY(val.type() == QVariant::Bool); |
|
226 |
QVERIFY(val.toBool() == false); |
|
227 |
||
228 |
QVERIFY(browser->historyTitle(-1).isEmpty()); |
|
229 |
QCOMPARE(browser->historyTitle(0), QString("Page With BG")); |
|
230 |
QCOMPARE(browser->historyTitle(1), QString("Sample Anchor")); |
|
231 |
||
232 |
browser->setSource(QUrl("pagewithoutbg.html")); |
|
233 |
||
234 |
QVERIFY(!forwardEmissions.isEmpty()); |
|
235 |
val = forwardEmissions.takeLast()[0]; |
|
236 |
QVERIFY(val.type() == QVariant::Bool); |
|
237 |
QVERIFY(val.toBool() == false); |
|
238 |
||
239 |
QVERIFY(!backwardEmissions.isEmpty()); |
|
240 |
val = backwardEmissions.takeLast()[0]; |
|
241 |
QVERIFY(val.type() == QVariant::Bool); |
|
242 |
QVERIFY(val.toBool() == true); |
|
243 |
} |
|
244 |
||
245 |
void tst_QTextBrowser::viewportPositionInHistory() |
|
246 |
{ |
|
247 |
browser->setSource(QUrl("bigpage.html")); |
|
248 |
browser->scrollToAnchor("bottom"); |
|
249 |
QVERIFY(browser->verticalScrollBar()->value() > 0); |
|
250 |
||
251 |
browser->setSource(QUrl("pagewithbg.html")); |
|
252 |
QCOMPARE(browser->verticalScrollBar()->value(), 0); |
|
253 |
||
254 |
browser->backward(); |
|
255 |
QVERIFY(browser->verticalScrollBar()->value() > 0); |
|
256 |
} |
|
257 |
||
258 |
void tst_QTextBrowser::relativeLinks() |
|
259 |
{ |
|
260 |
qRegisterMetaType<QUrl>("QUrl"); |
|
261 |
QSignalSpy sourceChangedSpy(browser, SIGNAL(sourceChanged(const QUrl &))); |
|
262 |
browser->setSource(QUrl("../qtextbrowser.html")); |
|
263 |
QVERIFY(sourceChangedSpy.count() == 1); |
|
264 |
QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("../qtextbrowser.html")); |
|
265 |
browser->setSource(QUrl("qtextbrowser/subdir/index.html")); |
|
266 |
QVERIFY(sourceChangedSpy.count() == 1); |
|
267 |
QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("qtextbrowser/subdir/index.html")); |
|
268 |
browser->setSource(QUrl("../anchor.html")); |
|
269 |
QVERIFY(sourceChangedSpy.count() == 1); |
|
270 |
QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("../anchor.html")); |
|
271 |
browser->setSource(QUrl("subdir/index.html")); |
|
272 |
QVERIFY(sourceChangedSpy.count() == 1); |
|
273 |
QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("subdir/index.html")); |
|
274 |
||
275 |
// using QUrl::fromLocalFile() |
|
276 |
browser->setSource(QUrl::fromLocalFile("anchor.html")); |
|
277 |
QVERIFY(sourceChangedSpy.count() == 1); |
|
278 |
QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("file:anchor.html")); |
|
279 |
browser->setSource(QUrl("../qtextbrowser.html")); |
|
280 |
QVERIFY(sourceChangedSpy.count() == 1); |
|
281 |
QCOMPARE(sourceChangedSpy.takeFirst()[0].toUrl(), QUrl("../qtextbrowser.html")); |
|
282 |
} |
|
283 |
||
284 |
void tst_QTextBrowser::anchors() |
|
285 |
{ |
|
286 |
browser->setSource(QUrl("bigpage.html")); |
|
287 |
browser->setSource(QUrl("#bottom")); |
|
288 |
QVERIFY(browser->verticalScrollBar()->value() > 0); |
|
289 |
||
290 |
browser->setSource(QUrl("bigpage.html")); |
|
291 |
browser->setSource(QUrl("#id-anchor")); |
|
292 |
QVERIFY(browser->verticalScrollBar()->value() > 0); |
|
293 |
} |
|
294 |
||
295 |
void tst_QTextBrowser::resourceAutoDetection() |
|
296 |
{ |
|
297 |
browser->setHtml("<img src=\":/some/resource\"/>"); |
|
298 |
QCOMPARE(browser->lastResource.toString(), QString("qrc:/some/resource")); |
|
299 |
} |
|
300 |
||
301 |
void tst_QTextBrowser::forwardBackwardAvailable() |
|
302 |
{ |
|
303 |
QSignalSpy backwardSpy(browser, SIGNAL(backwardAvailable(bool))); |
|
304 |
QSignalSpy forwardSpy(browser, SIGNAL(forwardAvailable(bool))); |
|
305 |
||
306 |
QVERIFY(!browser->isBackwardAvailable()); |
|
307 |
QVERIFY(!browser->isForwardAvailable()); |
|
308 |
||
309 |
browser->setSource(QUrl("anchor.html")); |
|
310 |
QVERIFY(!browser->isBackwardAvailable()); |
|
311 |
QVERIFY(!browser->isForwardAvailable()); |
|
312 |
QCOMPARE(backwardSpy.count(), 1); |
|
313 |
QVERIFY(!backwardSpy.at(0).at(0).toBool()); |
|
314 |
QCOMPARE(forwardSpy.count(), 1); |
|
315 |
QVERIFY(!forwardSpy.at(0).at(0).toBool()); |
|
316 |
||
317 |
backwardSpy.clear(); |
|
318 |
forwardSpy.clear(); |
|
319 |
||
320 |
browser->setSource(QUrl("bigpage.html")); |
|
321 |
QVERIFY(browser->isBackwardAvailable()); |
|
322 |
QVERIFY(!browser->isForwardAvailable()); |
|
323 |
QCOMPARE(backwardSpy.count(), 1); |
|
324 |
QVERIFY(backwardSpy.at(0).at(0).toBool()); |
|
325 |
QCOMPARE(forwardSpy.count(), 1); |
|
326 |
QVERIFY(!forwardSpy.at(0).at(0).toBool()); |
|
327 |
||
328 |
backwardSpy.clear(); |
|
329 |
forwardSpy.clear(); |
|
330 |
||
331 |
browser->setSource(QUrl("pagewithbg.html")); |
|
332 |
QVERIFY(browser->isBackwardAvailable()); |
|
333 |
QVERIFY(!browser->isForwardAvailable()); |
|
334 |
QCOMPARE(backwardSpy.count(), 1); |
|
335 |
QVERIFY(backwardSpy.at(0).at(0).toBool()); |
|
336 |
QCOMPARE(forwardSpy.count(), 1); |
|
337 |
QVERIFY(!forwardSpy.at(0).at(0).toBool()); |
|
338 |
||
339 |
backwardSpy.clear(); |
|
340 |
forwardSpy.clear(); |
|
341 |
||
342 |
browser->backward(); |
|
343 |
QVERIFY(browser->isBackwardAvailable()); |
|
344 |
QVERIFY(browser->isForwardAvailable()); |
|
345 |
QCOMPARE(backwardSpy.count(), 1); |
|
346 |
QVERIFY(backwardSpy.at(0).at(0).toBool()); |
|
347 |
QCOMPARE(forwardSpy.count(), 1); |
|
348 |
QVERIFY(forwardSpy.at(0).at(0).toBool()); |
|
349 |
||
350 |
backwardSpy.clear(); |
|
351 |
forwardSpy.clear(); |
|
352 |
||
353 |
browser->backward(); |
|
354 |
QVERIFY(!browser->isBackwardAvailable()); |
|
355 |
QVERIFY(browser->isForwardAvailable()); |
|
356 |
QCOMPARE(backwardSpy.count(), 1); |
|
357 |
QVERIFY(!backwardSpy.at(0).at(0).toBool()); |
|
358 |
QCOMPARE(forwardSpy.count(), 1); |
|
359 |
QVERIFY(forwardSpy.at(0).at(0).toBool()); |
|
360 |
||
361 |
backwardSpy.clear(); |
|
362 |
forwardSpy.clear(); |
|
363 |
||
364 |
browser->forward(); |
|
365 |
QVERIFY(browser->isBackwardAvailable()); |
|
366 |
QVERIFY(browser->isForwardAvailable()); |
|
367 |
QCOMPARE(backwardSpy.count(), 1); |
|
368 |
QVERIFY(backwardSpy.at(0).at(0).toBool()); |
|
369 |
QCOMPARE(forwardSpy.count(), 1); |
|
370 |
QVERIFY(forwardSpy.at(0).at(0).toBool()); |
|
371 |
||
372 |
backwardSpy.clear(); |
|
373 |
forwardSpy.clear(); |
|
374 |
||
375 |
browser->forward(); |
|
376 |
QVERIFY(browser->isBackwardAvailable()); |
|
377 |
QVERIFY(!browser->isForwardAvailable()); |
|
378 |
QCOMPARE(backwardSpy.count(), 1); |
|
379 |
QVERIFY(backwardSpy.at(0).at(0).toBool()); |
|
380 |
QCOMPARE(forwardSpy.count(), 1); |
|
381 |
QVERIFY(!forwardSpy.at(0).at(0).toBool()); |
|
382 |
||
383 |
backwardSpy.clear(); |
|
384 |
forwardSpy.clear(); |
|
385 |
} |
|
386 |
||
387 |
void tst_QTextBrowser::clearHistory() |
|
388 |
{ |
|
389 |
QSignalSpy backwardSpy(browser, SIGNAL(backwardAvailable(bool))); |
|
390 |
QSignalSpy forwardSpy(browser, SIGNAL(forwardAvailable(bool))); |
|
391 |
||
392 |
QVERIFY(!browser->isBackwardAvailable()); |
|
393 |
QVERIFY(!browser->isForwardAvailable()); |
|
394 |
||
395 |
browser->clearHistory(); |
|
396 |
QVERIFY(!browser->isBackwardAvailable()); |
|
397 |
QVERIFY(!browser->isForwardAvailable()); |
|
398 |
QCOMPARE(backwardSpy.count(), 1); |
|
399 |
QVERIFY(!backwardSpy.at(0).at(0).toBool()); |
|
400 |
QCOMPARE(forwardSpy.count(), 1); |
|
401 |
QVERIFY(!forwardSpy.at(0).at(0).toBool()); |
|
402 |
QVERIFY(browser->historyTitle(-1).isEmpty()); |
|
403 |
QVERIFY(browser->historyTitle(0).isEmpty()); |
|
404 |
QVERIFY(browser->historyTitle(1).isEmpty()); |
|
405 |
||
406 |
backwardSpy.clear(); |
|
407 |
forwardSpy.clear(); |
|
408 |
||
409 |
browser->setSource(QUrl("anchor.html")); |
|
410 |
QVERIFY(!browser->isBackwardAvailable()); |
|
411 |
QVERIFY(!browser->isForwardAvailable()); |
|
412 |
QCOMPARE(backwardSpy.count(), 1); |
|
413 |
QVERIFY(!backwardSpy.at(0).at(0).toBool()); |
|
414 |
QCOMPARE(forwardSpy.count(), 1); |
|
415 |
QVERIFY(!forwardSpy.at(0).at(0).toBool()); |
|
416 |
||
417 |
backwardSpy.clear(); |
|
418 |
forwardSpy.clear(); |
|
419 |
||
420 |
browser->setSource(QUrl("bigpage.html")); |
|
421 |
QVERIFY(browser->isBackwardAvailable()); |
|
422 |
QVERIFY(!browser->isForwardAvailable()); |
|
423 |
QCOMPARE(backwardSpy.count(), 1); |
|
424 |
QVERIFY(backwardSpy.at(0).at(0).toBool()); |
|
425 |
QCOMPARE(forwardSpy.count(), 1); |
|
426 |
QVERIFY(!forwardSpy.at(0).at(0).toBool()); |
|
427 |
||
428 |
backwardSpy.clear(); |
|
429 |
forwardSpy.clear(); |
|
430 |
||
431 |
browser->clearHistory(); |
|
432 |
QVERIFY(!browser->isBackwardAvailable()); |
|
433 |
QVERIFY(!browser->isForwardAvailable()); |
|
434 |
QCOMPARE(backwardSpy.count(), 1); |
|
435 |
QVERIFY(!backwardSpy.at(0).at(0).toBool()); |
|
436 |
QCOMPARE(forwardSpy.count(), 1); |
|
437 |
QVERIFY(!forwardSpy.at(0).at(0).toBool()); |
|
438 |
QVERIFY(browser->historyTitle(-1).isEmpty()); |
|
439 |
QVERIFY(browser->historyTitle(1).isEmpty()); |
|
440 |
||
441 |
QCOMPARE(browser->source(), QUrl("bigpage.html")); |
|
442 |
browser->backward(); |
|
443 |
QCOMPARE(browser->source(), QUrl("bigpage.html")); |
|
444 |
browser->home(); |
|
445 |
QCOMPARE(browser->source(), QUrl("bigpage.html")); |
|
446 |
} |
|
447 |
||
448 |
void tst_QTextBrowser::sourceInsideLoadResource() |
|
449 |
{ |
|
450 |
QUrl url("pagewithimage.html"); |
|
451 |
browser->setSource(url); |
|
452 |
QCOMPARE(browser->lastResource.toString(), QUrl::fromLocalFile(QDir::current().filePath("foobar.png")).toString()); |
|
453 |
QEXPECT_FAIL("", "This is currently not supported", Continue); |
|
454 |
QCOMPARE(browser->sourceInsideLoadResource.toString(), url.toString()); |
|
455 |
} |
|
456 |
||
457 |
void tst_QTextBrowser::textInteractionFlags_vs_readOnly() |
|
458 |
{ |
|
459 |
QVERIFY(browser->isReadOnly()); |
|
460 |
QVERIFY(browser->textInteractionFlags() == Qt::TextBrowserInteraction); |
|
461 |
browser->setReadOnly(true); |
|
462 |
QVERIFY(browser->textInteractionFlags() == Qt::TextBrowserInteraction); |
|
463 |
browser->setReadOnly(false); |
|
464 |
QVERIFY(browser->textInteractionFlags() == Qt::TextEditorInteraction); |
|
465 |
browser->setReadOnly(true); |
|
466 |
QVERIFY(browser->textInteractionFlags() == Qt::TextBrowserInteraction); |
|
467 |
} |
|
468 |
||
469 |
void tst_QTextBrowser::anchorsWithSelfBuiltHtml() |
|
470 |
{ |
|
471 |
browser->setHtml("<p>Hello <a href=\"#anchor\">Link</a>" |
|
472 |
"<p><a name=\"anchor\"/>Blah</p>"); |
|
473 |
QVERIFY(browser->document()->blockCount() > 1); |
|
474 |
browser->setSource(QUrl("#anchor")); |
|
475 |
QVERIFY(browser->document()->blockCount() > 1); |
|
476 |
} |
|
477 |
||
478 |
class HelpBrowser : public QTextBrowser |
|
479 |
{ |
|
480 |
public: |
|
481 |
virtual QVariant loadResource(int /*type*/, const QUrl &name) { |
|
482 |
QString url = name.toString(); |
|
483 |
if(url == "qhelp://docs/index.html") { |
|
484 |
return "index"; |
|
485 |
} else if (url == "qhelp://docs/classes.html") { |
|
486 |
return "classes"; |
|
487 |
} else if (url == "qhelp://docs/someclass.html") { |
|
488 |
return "someclass"; |
|
489 |
} |
|
490 |
return QVariant(); |
|
491 |
} |
|
492 |
}; |
|
493 |
||
494 |
void tst_QTextBrowser::relativeNonLocalUrls() |
|
495 |
{ |
|
496 |
HelpBrowser browser; |
|
497 |
browser.setSource(QUrl("qhelp://docs/index.html")); |
|
498 |
QCOMPARE(browser.toPlainText(), QString("index")); |
|
499 |
browser.setSource(QUrl("classes.html")); |
|
500 |
QCOMPARE(browser.toPlainText(), QString("classes")); |
|
501 |
browser.setSource(QUrl("someclass.html")); |
|
502 |
QCOMPARE(browser.toPlainText(), QString("someclass")); |
|
503 |
} |
|
504 |
||
505 |
class HackBrowser : public TestBrowser |
|
506 |
{ |
|
507 |
public: |
|
508 |
inline bool focusTheNextChild() { return QTextBrowser::focusNextChild(); } |
|
509 |
inline bool focusThePreviousChild() { return QTextBrowser::focusPreviousChild(); } |
|
510 |
}; |
|
511 |
||
512 |
void tst_QTextBrowser::adjacentAnchors() |
|
513 |
{ |
|
514 |
HackBrowser *browser = new HackBrowser; |
|
515 |
browser->setHtml("<a href=\"#foo\">foo</a><a href=\"#bar\">bar</a>"); |
|
516 |
QVERIFY(browser->focusTheNextChild()); |
|
517 |
QCOMPARE(browser->textCursor().selectedText(), QString("foo")); |
|
518 |
||
519 |
QVERIFY(browser->focusTheNextChild()); |
|
520 |
QCOMPARE(browser->textCursor().selectedText(), QString("bar")); |
|
521 |
||
522 |
QVERIFY(!browser->focusTheNextChild()); |
|
523 |
||
524 |
browser->moveCursor(QTextCursor::End); |
|
525 |
QVERIFY(browser->focusThePreviousChild()); |
|
526 |
QCOMPARE(browser->textCursor().selectedText(), QString("bar")); |
|
527 |
QVERIFY(browser->focusThePreviousChild()); |
|
528 |
QCOMPARE(browser->textCursor().selectedText(), QString("foo")); |
|
529 |
||
530 |
delete browser; |
|
531 |
} |
|
532 |
||
533 |
void tst_QTextBrowser::loadResourceOnRelativeLocalFiles() |
|
534 |
{ |
|
535 |
browser->setSource(QUrl("subdir/index.html")); |
|
536 |
QVERIFY(!browser->toPlainText().isEmpty()); |
|
537 |
QVariant v = browser->loadResource(QTextDocument::HtmlResource, QUrl("../anchor.html")); |
|
538 |
QVERIFY(v.isValid()); |
|
539 |
QVERIFY(v.type() == QVariant::ByteArray); |
|
540 |
QVERIFY(!v.toByteArray().isEmpty()); |
|
541 |
} |
|
542 |
||
543 |
void tst_QTextBrowser::focusIndicator() |
|
544 |
{ |
|
545 |
HackBrowser *browser = new HackBrowser; |
|
546 |
browser->setSource(QUrl("firstpage.html")); |
|
547 |
QVERIFY(!browser->textCursor().hasSelection()); |
|
548 |
||
549 |
browser->focusTheNextChild(); |
|
550 |
||
551 |
QVERIFY(browser->textCursor().hasSelection()); |
|
552 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to second page")); |
|
553 |
||
554 |
#ifdef QT_KEYPAD_NAVIGATION |
|
555 |
browser->setEditFocus(true); |
|
556 |
#endif |
|
557 |
QTest::keyClick(browser, Qt::Key_Enter); |
|
558 |
QVERIFY(!browser->textCursor().hasSelection()); |
|
559 |
||
560 |
browser->focusTheNextChild(); |
|
561 |
||
562 |
QVERIFY(browser->textCursor().hasSelection()); |
|
563 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to third page from second page")); |
|
564 |
||
565 |
QTest::keyClick(browser, Qt::Key_Enter); |
|
566 |
QVERIFY(!browser->textCursor().hasSelection()); |
|
567 |
||
568 |
browser->backward(); |
|
569 |
||
570 |
QVERIFY(browser->textCursor().hasSelection()); |
|
571 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to third page from second page")); |
|
572 |
||
573 |
browser->backward(); |
|
574 |
||
575 |
QVERIFY(browser->textCursor().hasSelection()); |
|
576 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to second page")); |
|
577 |
||
578 |
browser->forward(); |
|
579 |
||
580 |
QVERIFY(browser->textCursor().hasSelection()); |
|
581 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to third page from second page")); |
|
582 |
||
583 |
browser->backward(); |
|
584 |
browser->backward(); |
|
585 |
||
586 |
QVERIFY(browser->textCursor().hasSelection()); |
|
587 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to second page")); |
|
588 |
||
589 |
QTest::keyClick(browser, Qt::Key_Enter); |
|
590 |
QVERIFY(!browser->textCursor().hasSelection()); |
|
591 |
||
592 |
delete browser; |
|
593 |
} |
|
594 |
||
595 |
void tst_QTextBrowser::focusHistory() |
|
596 |
{ |
|
597 |
HackBrowser *browser = new HackBrowser; |
|
598 |
browser->setSource(QUrl("firstpage.html")); |
|
599 |
QVERIFY(!browser->textCursor().hasSelection()); |
|
600 |
||
601 |
browser->focusTheNextChild(); |
|
602 |
||
603 |
QVERIFY(browser->textCursor().hasSelection()); |
|
604 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to second page")); |
|
605 |
||
606 |
#ifdef QT_KEYPAD_NAVIGATION |
|
607 |
browser->setEditFocus(true); |
|
608 |
#endif |
|
609 |
QTest::keyClick(browser, Qt::Key_Enter); |
|
610 |
QVERIFY(!browser->textCursor().hasSelection()); |
|
611 |
||
612 |
browser->focusTheNextChild(); |
|
613 |
||
614 |
QVERIFY(browser->textCursor().hasSelection()); |
|
615 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to third page from second page")); |
|
616 |
||
617 |
browser->backward(); |
|
618 |
||
619 |
QVERIFY(browser->textCursor().hasSelection()); |
|
620 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to second page")); |
|
621 |
||
622 |
browser->focusTheNextChild(); |
|
623 |
||
624 |
QVERIFY(browser->textCursor().hasSelection()); |
|
625 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to third page")); |
|
626 |
||
627 |
// Despite the third page link being highlighted, going forward should go to second, |
|
628 |
// and going back after that should still highlight the third link |
|
629 |
browser->forward(); |
|
630 |
||
631 |
QVERIFY(browser->textCursor().hasSelection()); |
|
632 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to third page from second page")); |
|
633 |
||
634 |
browser->backward(); |
|
635 |
||
636 |
QVERIFY(browser->textCursor().hasSelection()); |
|
637 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to third page")); |
|
638 |
||
639 |
browser->forward(); |
|
640 |
||
641 |
QVERIFY(browser->textCursor().hasSelection()); |
|
642 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to third page from second page")); |
|
643 |
||
644 |
QTest::keyClick(browser, Qt::Key_Enter); |
|
645 |
QVERIFY(!browser->textCursor().hasSelection()); |
|
646 |
||
647 |
browser->backward(); |
|
648 |
browser->backward(); |
|
649 |
||
650 |
QVERIFY(browser->textCursor().hasSelection()); |
|
651 |
QCOMPARE(browser->textCursor().selectedText(), QString("Link to third page")); |
|
652 |
||
653 |
delete browser; |
|
654 |
} |
|
655 |
||
656 |
void tst_QTextBrowser::urlEncoding() |
|
657 |
{ |
|
658 |
HackBrowser *browser = new HackBrowser; |
|
659 |
browser->setOpenLinks(false); |
|
660 |
browser->setHtml("<a href=\"http://www.google.com/q=%22\">link</a>"); |
|
661 |
browser->focusTheNextChild(); |
|
662 |
||
663 |
QSignalSpy spy(browser, SIGNAL(anchorClicked(const QUrl &))); |
|
664 |
||
665 |
#ifdef QT_KEYPAD_NAVIGATION |
|
666 |
browser->setEditFocus(true); |
|
667 |
#endif |
|
668 |
QTest::keyClick(browser, Qt::Key_Enter); |
|
669 |
QCOMPARE(spy.count(), 1); |
|
670 |
||
671 |
QUrl url = spy.at(0).at(0).toUrl(); |
|
672 |
QVERIFY(url.toEncoded() == QByteArray("http://www.google.com/q=%22")); |
|
673 |
||
674 |
delete browser; |
|
675 |
} |
|
676 |
||
677 |
QTEST_MAIN(tst_QTextBrowser) |
|
678 |
#include "tst_qtextbrowser.moc" |