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 "commandline-parser.h"
25
class CommandLineParserTests : public QObject
30
void shouldDisplayHelp_data()
32
QTest::addColumn<QStringList>("args");
33
QTest::addColumn<bool>("help");
34
QString BINARY("webbrowser-app");
35
QString URL("http://ubuntu.com");
36
QTest::newRow("no switch") << (QStringList() << BINARY) << false;
37
QTest::newRow("no switch with URL") << (QStringList() << BINARY << URL) << false;
38
QTest::newRow("short switch only") << (QStringList() << BINARY << "-h") << true;
39
QTest::newRow("long switch only") << (QStringList() << BINARY << "--help") << true;
40
QTest::newRow("short switch before URL") << (QStringList() << BINARY << "-h" << URL) << true;
41
QTest::newRow("long switch before URL") << (QStringList() << BINARY << "--help" << URL) << true;
42
QTest::newRow("short switch after URL") << (QStringList() << BINARY << URL << "-h") << true;
43
QTest::newRow("long switch after URL") << (QStringList() << BINARY << URL << "--help") << true;
44
QTest::newRow("short switch typo") << (QStringList() << BINARY << "-j") << false;
45
QTest::newRow("long switch typo") << (QStringList() << BINARY << "--helo") << false;
46
QTest::newRow("short switch long") << (QStringList() << BINARY << "--h") << false;
47
QTest::newRow("long switch short") << (QStringList() << BINARY << "-help") << false;
48
QTest::newRow("short switch uppercase") << (QStringList() << BINARY << "-H") << false;
49
QTest::newRow("long switch uppercase") << (QStringList() << BINARY << "--HELP") << false;
52
void shouldDisplayHelp()
54
QFETCH(QStringList, args);
56
QCOMPARE(CommandLineParser(args).help(), help);
59
void shouldBeChromeless_data()
61
QTest::addColumn<QStringList>("args");
62
QTest::addColumn<bool>("chromeless");
63
QString BINARY("webbrowser-app");
64
QString URL("http://ubuntu.com");
65
QTest::newRow("no switch") << (QStringList() << BINARY) << false;
66
QTest::newRow("switch only") << (QStringList() << BINARY << "--chromeless") << true;
67
QTest::newRow("switch before URL") << (QStringList() << BINARY << "--chromeless" << URL) << true;
68
QTest::newRow("switch after URL") << (QStringList() << BINARY << URL << "--chromeless") << true;
69
QTest::newRow("switch typo") << (QStringList() << BINARY << "--chromeles") << false;
70
QTest::newRow("switch uppercase") << (QStringList() << BINARY << "--CHROMELESS") << false;
71
QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "-h" << "--chromeless") << false;
72
QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "--help" << "--chromeless") << false;
75
void shouldBeChromeless()
77
QFETCH(QStringList, args);
78
QFETCH(bool, chromeless);
79
QCOMPARE(CommandLineParser(args).chromeless(), chromeless);
82
void shouldBeFullscreen_data()
84
QTest::addColumn<QStringList>("args");
85
QTest::addColumn<bool>("fullscreen");
86
QString BINARY("webbrowser-app");
87
QString URL("http://ubuntu.com");
88
QTest::newRow("no switch") << (QStringList() << BINARY) << false;
89
QTest::newRow("switch only") << (QStringList() << BINARY << "--fullscreen") << true;
90
QTest::newRow("switch before URL") << (QStringList() << BINARY << "--fullscreen" << URL) << true;
91
QTest::newRow("switch after URL") << (QStringList() << BINARY << URL << "--fullscreen") << true;
92
QTest::newRow("switch typo") << (QStringList() << BINARY << "--fulscreen") << false;
93
QTest::newRow("switch uppercase") << (QStringList() << BINARY << "--FULLSCREEN") << false;
94
QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "-h" << "--fullscreen") << false;
95
QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "--help" << "--fullscreen") << false;
98
void shouldBeFullscreen()
100
QFETCH(QStringList, args);
101
QFETCH(bool, fullscreen);
102
QCOMPARE(CommandLineParser(args).fullscreen(), fullscreen);
105
void shouldRecordURL_data()
107
QTest::addColumn<QStringList>("args");
108
QTest::addColumn<QUrl>("url");
109
QString BINARY("webbrowser-app");
110
QString DEFAULT("http://www.ubuntu.com");
111
QString URL1("http://example.org");
112
QString URL2("http://example.com");
113
QTest::newRow("no URL") << (QStringList() << BINARY) << QUrl(DEFAULT);
114
QTest::newRow("no URL with switches") << (QStringList() << BINARY << "--chromeless" << "--fullscreen") << QUrl(DEFAULT);
115
QTest::newRow("help precludes URL") << (QStringList() << BINARY << "-h" << URL1) << QUrl(DEFAULT);
116
QTest::newRow("help precludes URL") << (QStringList() << BINARY << "--help" << URL1) << QUrl(DEFAULT);
117
QTest::newRow("one URL") << (QStringList() << BINARY << URL1) << QUrl(URL1);
118
QTest::newRow("several URLs") << (QStringList() << BINARY << URL1 << URL2) << QUrl(URL1);
119
QTest::newRow("missing scheme") << (QStringList() << BINARY << "ubuntu.com") << QUrl("http://ubuntu.com");
120
QTest::newRow("malformed URL") << (QStringList() << BINARY << "@") << QUrl(DEFAULT);
121
QTest::newRow("malformed URL") << (QStringList() << BINARY << "@" << URL1) << QUrl(URL1);
122
QTest::newRow("homepage switch only") << (QStringList() << BINARY << "--homepage=http://example.com") << QUrl("http://example.com");
123
QTest::newRow("homepage switch overrides URL") << (QStringList() << BINARY << "--homepage=http://example.com" << "http://ubuntu.com") << QUrl("http://example.com");
124
QTest::newRow("empty homepage switch") << (QStringList() << BINARY << "--homepage=") << QUrl(DEFAULT);
125
QTest::newRow("homepage switch missing scheme") << (QStringList() << BINARY << "--homepage=example.com") << QUrl("http://example.com");
128
void shouldRecordURL()
130
QFETCH(QStringList, args);
132
QCOMPARE(CommandLineParser(args).url(), url);
135
void shouldHaveDesktopFileHint_data()
137
QTest::addColumn<QStringList>("args");
138
QTest::addColumn<QString>("hint");
139
QString BINARY("webbrowser-app");
141
QTest::newRow("no hint") << (QStringList() << BINARY) << "";
142
QTest::newRow("full path hint") << (QStringList() << BINARY << "--desktop_file_hint=/usr/share/applications/webbrowser-app.desktop") << "webbrowser-app";
143
QTest::newRow("only .desktop file") << (QStringList() << BINARY << "--desktop_file_hint=webbrowser-app.desktop") << "webbrowser-app";
144
QTest::newRow("webapp") << (QStringList() << BINARY << "--desktop_file_hint=/usr/share/applications/amazon-webapp.desktop") << "amazon-webapp";
147
void shouldHaveDesktopFileHint()
149
QFETCH(QStringList, args);
150
QFETCH(QString, hint);
151
QCOMPARE(CommandLineParser(args).desktopFileHint(), hint);
154
void shouldRunRemoteInspector_data()
156
QTest::addColumn<QStringList>("args");
157
QTest::addColumn<bool>("inspector");
158
QString BINARY("webbrowser-app");
159
QString URL("http://ubuntu.com");
160
QTest::newRow("no switch") << (QStringList() << BINARY) << false;
161
QTest::newRow("switch only") << (QStringList() << BINARY << "--inspector") << true;
162
QTest::newRow("switch before URL") << (QStringList() << BINARY << "--inspector" << URL) << true;
163
QTest::newRow("switch after URL") << (QStringList() << BINARY << URL << "--inspector") << true;
164
QTest::newRow("switch typo") << (QStringList() << BINARY << "--ispector") << false;
165
QTest::newRow("switch uppercase") << (QStringList() << BINARY << "--INSPECTOR") << false;
166
QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "-h" << "--inspector") << false;
167
QTest::newRow("help precludes other switches") << (QStringList() << BINARY << "--help" << "--inspector") << false;
170
void shouldRunRemoteInspector()
172
QFETCH(QStringList, args);
173
QFETCH(bool, inspector);
174
QCOMPARE(CommandLineParser(args).remoteInspector(), inspector);
178
QTEST_MAIN(CommandLineParserTests)
179
#include "tst_CommandLineParserTests.moc"