~bfiller/webbrowser-app/fix-tab-tests-etc

« back to all changes in this revision

Viewing changes to tests/unittests/domain-utils/tst_DomainUtilsTests.cpp

  • Committer: Tarmac
  • Author(s): Olivier Tilloy
  • Date: 2013-07-12 16:31:27 UTC
  • mfrom: (188.1.29 domain-name)
  • Revision ID: tarmac-20130712163127-1h0345ccp72kd223
Refactor the models to group history entries by domain name, not by host.

Approved by Bill Filler, PS Jenkins bot.

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/QtTest>
 
21
 
 
22
// local
 
23
#include "domain-utils.h"
 
24
 
 
25
class DomainUtilsTests : public QObject
 
26
{
 
27
    Q_OBJECT
 
28
 
 
29
private Q_SLOTS:
 
30
    void shouldExtractTopLevelDomainName_data()
 
31
    {
 
32
        QTest::addColumn<QUrl>("url");
 
33
        QTest::addColumn<QString>("domain");
 
34
        QTest::newRow("only SLD") << QUrl("http://ubuntu.com") << QString("ubuntu.com");
 
35
        QTest::newRow("SLD with www") << QUrl("http://www.ubuntu.com") << QString("ubuntu.com");
 
36
        QTest::newRow("SLD is www") << QUrl("http://www.com") << QString("www.com");
 
37
        QTest::newRow("subdomain") << QUrl("https://mail.google.com/foo/bar") << QString("google.com");
 
38
        QTest::newRow("subdomain with m") << QUrl("http://m.cnet.com") << QString("cnet.com");
 
39
        QTest::newRow("subdomain with mobile") << QUrl("http://mobile.nytimes.com") << QString("nytimes.com");
 
40
        QTest::newRow("ftp with subdomain") << QUrl("ftp://user:pwd@ftp.london.ac.uk/home/foobar") << QString("london.ac.uk");
 
41
        QTest::newRow("two-letter SLD") << QUrl("https://fb.com/foobar") << QString("fb.com");
 
42
        QTest::newRow("two-letter SLD with www") << QUrl("http://www.fb.com/foobar") << QString("fb.com");
 
43
        QTest::newRow("two-letter SLD with subdomain") << QUrl("http://m.espn.go.com") << QString("go.com");
 
44
        QTest::newRow("two-component TLD") << QUrl("http://bbc.co.uk") << QString("bbc.co.uk");
 
45
        QTest::newRow("another two-component TLD") << QUrl("http://disney.com.es") << QString("disney.com.es");
 
46
        QTest::newRow("two-component TLD with subdomain") << QUrl("http://www.foobar.bbc.co.uk") << QString("bbc.co.uk");
 
47
        QTest::newRow("local file") << QUrl("file:///home/foobar/test.txt") << DomainUtils::TOKEN_LOCAL;
 
48
        QTest::newRow("IPv4 address") << QUrl("http://192.168.1.1/config") << QString("192.168.1.1");
 
49
        QTest::newRow("IPv6 address") << QUrl("http://[2001:db8:85a3::8a2e:370:7334]/bleh") << QString("2001:db8:85a3::8a2e:370:7334");
 
50
        QTest::newRow("localhost") << QUrl("http://localhost:8080/foobar") << QString("localhost");
 
51
    }
 
52
 
 
53
    void shouldExtractTopLevelDomainName()
 
54
    {
 
55
        QFETCH(QUrl, url);
 
56
        QVERIFY(url.isValid());
 
57
        QFETCH(QString, domain);
 
58
        QCOMPARE(DomainUtils::extractTopLevelDomainName(url), domain);
 
59
    }
 
60
};
 
61
 
 
62
QTEST_MAIN(DomainUtilsTests)
 
63
#include "tst_DomainUtilsTests.moc"