~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to apps/konqueror/src/tests/historymanagertest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-27 12:09:48 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080527120948-dottsyd5rcwhzd36
Tags: 4:4.0.80-1ubuntu1
* Merge with Debian
 - remove 97_fix_target_link_libraries.diff
 - Add replaces/conflicts on -kde4 packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of KDE
 
2
    Copyright (c) 2006 David Faure <faure@kde.org>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
#include "historymanagertest.h"
 
21
#include <qtest_kde.h>
 
22
#include <konqhistorymanager.h>
 
23
#include <kio/netaccess.h>
 
24
#include <QDateTime>
 
25
 
 
26
#include "historymanagertest.moc"
 
27
 
 
28
QTEST_KDEMAIN( HistoryManagerTest, NoGUI )
 
29
 
 
30
void HistoryManagerTest::testGetSetMaxCount()
 
31
{
 
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 );
 
44
}
 
45
 
 
46
void HistoryManagerTest::testGetSetMaxAge()
 
47
{
 
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 );
 
57
}
 
58
 
 
59
static void waitForAddedSignal( KonqHistoryManager* mgr )
 
60
{
 
61
    QEventLoop eventLoop;
 
62
    QObject::connect(mgr, SIGNAL(entryAdded(KonqHistoryEntry)), &eventLoop, SLOT(quit()));
 
63
    eventLoop.exec( QEventLoop::ExcludeUserInputEvents );
 
64
}
 
65
 
 
66
static void waitForRemovedSignal( KonqHistoryManager* mgr )
 
67
{
 
68
    QEventLoop eventLoop;
 
69
    QObject::connect(mgr, SIGNAL(entryRemoved(KonqHistoryEntry)), &eventLoop, SLOT(quit()));
 
70
    eventLoop.exec( QEventLoop::ExcludeUserInputEvents );
 
71
}
 
72
 
 
73
void HistoryManagerTest::testAddHistoryEntry()
 
74
{
 
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 );
 
83
 
 
84
    waitForAddedSignal( &mgr );
 
85
 
 
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 );
 
95
 
 
96
    // Now confirm it
 
97
    mgr.confirmPending( url, typedUrl, title );
 
98
    // ## alternate code path: mgr.removePending()
 
99
 
 
100
    waitForAddedSignal( &mgr );
 
101
 
 
102
    QCOMPARE( addedSpy.count(), 2 );
 
103
    QCOMPARE( removedSpy.count(), 0 );
 
104
    args = addedSpy[1];
 
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 );
 
111
 
 
112
    // Now clean it up
 
113
 
 
114
    mgr.emitRemoveFromHistory( url );
 
115
 
 
116
    waitForRemovedSignal( &mgr );
 
117
 
 
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 );
 
127
}