1
/* This file is part of KDE
2
Copyright (c) 2006 David Faure <faure@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#include "historymanagertest.h"
21
#include <qtest_kde.h>
22
#include <konqhistorymanager.h>
23
#include <kio/netaccess.h>
26
#include "historymanagertest.moc"
28
QTEST_KDEMAIN( HistoryManagerTest, NoGUI )
30
void HistoryManagerTest::testGetSetMaxCount()
32
KonqHistoryManager mgr(0);
33
const int oldMaxCount = mgr.maxCount();
34
qDebug( "oldMaxCount=%d", oldMaxCount );
35
mgr.emitSetMaxCount( 4242 );
36
QTest::qWait( 100 ); // ### fragile. We have no signal to wait for, so we must just wait a little bit...
37
// Yes this is just a set+get test, but given that it goes via DBUS before changing the member variable
38
// we do test quite a lot with it. We can't really instanciate two KonqHistoryManagers (same dbus path),
39
// so we'd need two processes to test the dbus signal 'for real', if the setter changed the member var...
40
QCOMPARE( mgr.maxCount(), 4242 );
41
mgr.emitSetMaxCount( oldMaxCount );
42
QTest::qWait( 100 ); // ### fragile. Wait again otherwise the change will be lost
43
QCOMPARE( mgr.maxCount(), oldMaxCount );
46
void HistoryManagerTest::testGetSetMaxAge()
48
KonqHistoryManager mgr(0);
49
const int oldMaxAge = mgr.maxAge();
50
qDebug( "oldMaxAge=%d", oldMaxAge );
51
mgr.emitSetMaxAge( 4242 );
52
QTest::qWait( 100 ); // ### fragile. We have no signal to wait for, so we must just wait a little bit...
53
QCOMPARE( mgr.maxAge(), 4242 );
54
mgr.emitSetMaxAge( oldMaxAge );
55
QTest::qWait( 100 ); // ### fragile. Wait again otherwise the change will be lost
56
QCOMPARE( mgr.maxAge(), oldMaxAge );
59
static void waitForAddedSignal( KonqHistoryManager* mgr )
62
QObject::connect(mgr, SIGNAL(entryAdded(KonqHistoryEntry)), &eventLoop, SLOT(quit()));
63
eventLoop.exec( QEventLoop::ExcludeUserInputEvents );
66
static void waitForRemovedSignal( KonqHistoryManager* mgr )
69
QObject::connect(mgr, SIGNAL(entryRemoved(KonqHistoryEntry)), &eventLoop, SLOT(quit()));
70
eventLoop.exec( QEventLoop::ExcludeUserInputEvents );
73
void HistoryManagerTest::testAddHistoryEntry()
75
KonqHistoryManager mgr(0);
76
qRegisterMetaType<KonqHistoryEntry>("KonqHistoryEntry");
77
QSignalSpy addedSpy( &mgr, SIGNAL(entryAdded(KonqHistoryEntry)) );
78
QSignalSpy removedSpy( &mgr, SIGNAL(entryRemoved(KonqHistoryEntry)) );
79
const KUrl url( "http://user@historymgrtest.org/" );
80
const QString typedUrl = "http://www.example.net";
81
const QString title = "The Title";
82
mgr.addPending( url, typedUrl, title );
84
waitForAddedSignal( &mgr );
86
QCOMPARE( addedSpy.count(), 1 );
87
QCOMPARE( removedSpy.count(), 0 );
88
QList<QVariant> args = addedSpy[0];
89
QCOMPARE( args.count(), 1 );
90
KonqHistoryEntry entry = qvariant_cast<KonqHistoryEntry>( args[0] );
91
QCOMPARE( entry.url.url(), url.url() );
92
QCOMPARE( entry.typedUrl, typedUrl );
93
QCOMPARE( entry.title, QString() ); // not set yet, still pending
94
QCOMPARE( (int)entry.numberOfTimesVisited, 1 );
97
mgr.confirmPending( url, typedUrl, title );
98
// ## alternate code path: mgr.removePending()
100
waitForAddedSignal( &mgr );
102
QCOMPARE( addedSpy.count(), 2 );
103
QCOMPARE( removedSpy.count(), 0 );
105
QCOMPARE( args.count(), 1 );
106
entry = qvariant_cast<KonqHistoryEntry>( args[0] );
107
QCOMPARE( entry.url.url(), url.url() );
108
QCOMPARE( entry.typedUrl, typedUrl );
109
QCOMPARE( entry.title, title ); // now it's there
110
QCOMPARE( (int)entry.numberOfTimesVisited, 1 );
114
mgr.emitRemoveFromHistory( url );
116
waitForRemovedSignal( &mgr );
118
QCOMPARE( removedSpy.count(), 1 );
119
QCOMPARE( addedSpy.count(), 2 ); // unchanged
120
args = removedSpy[0];
121
QCOMPARE( args.count(), 1 );
122
entry = qvariant_cast<KonqHistoryEntry>( args[0] );
123
QCOMPARE( entry.url.url(), url.url() );
124
QCOMPARE( entry.typedUrl, typedUrl );
125
QCOMPARE( entry.title, title );
126
QCOMPARE( (int)entry.numberOfTimesVisited, 1 );