~osomon/webbrowser-app/fix-deleting-multiple-domains

« back to all changes in this revision

Viewing changes to tests/unittests/history-timeframe-model/tst_HistoryTimeframeModelTests.cpp

  • Committer: CI Train Bot
  • Date: 2015-12-10 15:31:37 UTC
  • mfrom: (1292.1.7 webbrowser-app)
  • Revision ID: ci-train-bot@canonical.com-20151210153137-xi93xu5wgxcuyyae
Resync trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2013 Canonical Ltd.
3
 
 *
4
 
 * This file is part of webbrowser-app.
5
 
 *
6
 
 * webbrowser-app is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; version 3.
9
 
 *
10
 
 * webbrowser-app is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
// Qt
20
 
#include <QtTest/QSignalSpy>
21
 
#include <QtTest/QtTest>
22
 
 
23
 
// local
24
 
#include "history-model.h"
25
 
#include "history-timeframe-model.h"
26
 
 
27
 
 
28
 
class HistoryTimeframeModelTests : public QObject
29
 
{
30
 
    Q_OBJECT
31
 
 
32
 
private:
33
 
    HistoryModel* model;
34
 
    HistoryTimeframeModel* timeframe;
35
 
 
36
 
private Q_SLOTS:
37
 
    void init()
38
 
    {
39
 
        model = new HistoryModel;
40
 
        model->setDatabasePath(":memory:");
41
 
        timeframe = new HistoryTimeframeModel;
42
 
        timeframe->setSourceModel(model);
43
 
    }
44
 
 
45
 
    void cleanup()
46
 
    {
47
 
        delete timeframe;
48
 
        delete model;
49
 
    }
50
 
 
51
 
    void shouldBeInitiallyEmpty()
52
 
    {
53
 
        QCOMPARE(timeframe->rowCount(), 0);
54
 
    }
55
 
 
56
 
    void shouldNotifyWhenChangingSourceModel()
57
 
    {
58
 
        QSignalSpy spy(timeframe, SIGNAL(sourceModelChanged()));
59
 
        timeframe->setSourceModel(model);
60
 
        QVERIFY(spy.isEmpty());
61
 
        HistoryModel* model2 = new HistoryModel;
62
 
        timeframe->setSourceModel(model2);
63
 
        QCOMPARE(spy.count(), 1);
64
 
        QCOMPARE(timeframe->sourceModel(), model2);
65
 
        timeframe->setSourceModel(0);
66
 
        QCOMPARE(spy.count(), 2);
67
 
        QCOMPARE(timeframe->sourceModel(), (HistoryModel*) 0);
68
 
        delete model2;
69
 
    }
70
 
 
71
 
    void shouldNotifyWhenChangingStart()
72
 
    {
73
 
        QSignalSpy spy(timeframe, SIGNAL(startChanged()));
74
 
        QDateTime start = QDateTime::currentDateTimeUtc();
75
 
        timeframe->setStart(start);
76
 
        QCOMPARE(timeframe->start(), start);
77
 
        QCOMPARE(spy.count(), 1);
78
 
        timeframe->setStart(start);
79
 
        QCOMPARE(spy.count(), 1);
80
 
        QTest::qWait(100);
81
 
        timeframe->setStart(QDateTime::currentDateTimeUtc());
82
 
        QCOMPARE(spy.count(), 2);
83
 
        timeframe->setStart(QDateTime());
84
 
        QCOMPARE(spy.count(), 3);
85
 
    }
86
 
 
87
 
    void shouldNotifyWhenChangingEnd()
88
 
    {
89
 
        QSignalSpy spy(timeframe, SIGNAL(endChanged()));
90
 
        QDateTime end = QDateTime::currentDateTimeUtc();
91
 
        timeframe->setEnd(end);
92
 
        QCOMPARE(timeframe->end(), end);
93
 
        QCOMPARE(spy.count(), 1);
94
 
        timeframe->setEnd(end);
95
 
        QCOMPARE(spy.count(), 1);
96
 
        QTest::qWait(100);
97
 
        timeframe->setEnd(QDateTime::currentDateTimeUtc());
98
 
        QCOMPARE(spy.count(), 2);
99
 
        timeframe->setEnd(QDateTime());
100
 
        QCOMPARE(spy.count(), 3);
101
 
    }
102
 
 
103
 
    void shouldMatchAllWhenNoBoundsSet()
104
 
    {
105
 
        model->add(QUrl("http://example.org"), "Example Domain", QUrl());
106
 
        QTest::qWait(100);
107
 
        model->add(QUrl("http://example.com"), "Example Domain", QUrl());
108
 
        QCOMPARE(timeframe->rowCount(), 2);
109
 
    }
110
 
 
111
 
    void shouldFilterOutOlderEntries()
112
 
    {
113
 
        model->add(QUrl("http://example.org"), "Example Domain", QUrl());
114
 
        QTest::qWait(100);
115
 
        QDateTime start = QDateTime::currentDateTimeUtc();
116
 
        QTest::qWait(100);
117
 
        model->add(QUrl("http://example.com"), "Example Domain", QUrl());
118
 
        QCOMPARE(timeframe->rowCount(), 2);
119
 
        timeframe->setStart(start);
120
 
        QCOMPARE(timeframe->rowCount(), 1);
121
 
        QCOMPARE(timeframe->data(timeframe->index(0, 0), HistoryModel::Url).toUrl(),
122
 
                 QUrl("http://example.com"));
123
 
    }
124
 
 
125
 
    void shouldFilterOutMoreRecentEntries()
126
 
    {
127
 
        model->add(QUrl("http://example.org"), "Example Domain", QUrl());
128
 
        QTest::qWait(100);
129
 
        QDateTime end = QDateTime::currentDateTimeUtc();
130
 
        QTest::qWait(100);
131
 
        model->add(QUrl("http://example.com"), "Example Domain", QUrl());
132
 
        QCOMPARE(timeframe->rowCount(), 2);
133
 
        timeframe->setEnd(end);
134
 
        QCOMPARE(timeframe->rowCount(), 1);
135
 
        QCOMPARE(timeframe->data(timeframe->index(0, 0), HistoryModel::Url).toUrl(),
136
 
                 QUrl("http://example.org"));
137
 
    }
138
 
 
139
 
    void shouldFilterOutOlderAndMoreRecentEntries()
140
 
    {
141
 
        model->add(QUrl("http://example.org"), "Example Domain", QUrl());
142
 
        QTest::qWait(100);
143
 
        QDateTime start = QDateTime::currentDateTimeUtc();
144
 
        QTest::qWait(100);
145
 
        model->add(QUrl("http://ubuntu.com"), "Ubuntu", QUrl());
146
 
        QTest::qWait(100);
147
 
        QDateTime end = QDateTime::currentDateTimeUtc();
148
 
        QTest::qWait(100);
149
 
        model->add(QUrl("http://example.com"), "Example Domain", QUrl());
150
 
        QCOMPARE(timeframe->rowCount(), 3);
151
 
        timeframe->setStart(start);
152
 
        timeframe->setEnd(end);
153
 
        QCOMPARE(timeframe->rowCount(), 1);
154
 
        QCOMPARE(timeframe->data(timeframe->index(0, 0), HistoryModel::Url).toUrl(),
155
 
                 QUrl("http://ubuntu.com"));
156
 
    }
157
 
};
158
 
 
159
 
QTEST_MAIN(HistoryTimeframeModelTests)
160
 
#include "tst_HistoryTimeframeModelTests.moc"