2
* Copyright 2013 Canonical Ltd.
4
* This file is part of webbrowser-app.
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.
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.
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/>.
20
#include <QtTest/QtTest>
23
#include "domain-utils.h"
25
class DomainUtilsTests : public QObject
30
void shouldExtractTopLevelDomainName_data()
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");
53
void shouldExtractTopLevelDomainName()
56
QVERIFY(url.isValid());
57
QFETCH(QString, domain);
58
QCOMPARE(DomainUtils::extractTopLevelDomainName(url), domain);
62
QTEST_MAIN(DomainUtilsTests)
63
#include "tst_DomainUtilsTests.moc"