Merge lp:~abreu-alexandre/webbrowser-app/fix-url-pattern-patching-overrides-and-google-patterns into lp:webbrowser-app

Proposed by Alexandre Abreu
Status: Merged
Merged at revision: 471
Proposed branch: lp:~abreu-alexandre/webbrowser-app/fix-url-pattern-patching-overrides-and-google-patterns
Merge into: lp:webbrowser-app
Diff against target: 450 lines (+306/-46)
8 files modified
src/app/webcontainer/CMakeLists.txt (+1/-1)
src/app/webcontainer/WebApp.qml (+23/-5)
src/app/webcontainer/url-pattern-utils.cpp (+129/-0)
src/app/webcontainer/url-pattern-utils.h (+32/-0)
src/app/webcontainer/webapp-container.cpp (+11/-40)
tests/unittests/CMakeLists.txt (+1/-0)
tests/unittests/container-url-patterns/CMakeLists.txt (+10/-0)
tests/unittests/container-url-patterns/tst_ContainerUrlPatterns.cpp (+99/-0)
To merge this branch: bzr merge lp:~abreu-alexandre/webbrowser-app/fix-url-pattern-patching-overrides-and-google-patterns
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Alberto Mardegan (community) Approve
David Barth Pending
Ubuntu Phablet Team Pending
Review via email: mp+209779@code.launchpad.net

Commit message

There are 2 ways for the webapp-container to receive a list of patterns to filter url browsing in a webapp container: through the manifest.json file that comes with a given (named) webapp, or through the command line.

At the moment, the 2 mechanisms are exclusive in the sense that from the webapp-container's perspective it only considers one or another when filtering navigation (the webapp manifest one being preferred) but they are NOT semantically equivalent. The list of url patterns in the manifest.json file is use as a mean to filter the urls that are being browsed to, but ALSO in the chromium & FF browsers to know if a webapp is to be installed/enabled when browsing in a given url.

For example, for Gmail, the hostname mail.google.com is used as a trigger to ask the user for an installation/enablement of a webapp in the browser. It is also implicitely used as a filter for browser once in the container.

The issue is that for applications like google services, the authentication mechanism is common. So when launched in the container, the user will be redirected to e.g. https://accounts.google.com or https://accounts.google.ca, etc.

So, the manifest.json cannot be modified to account for those, since we dont want to install a webapp from those URLs but we need a way to add extra navigation url patterns to allow google service webapps to be redirected to e.g. https://accounts.google.* etc.

We provide here 2 things:

- an way for the url patterns passed down from the command line to be also considered in the navigation filtering,
- a way to simplify url patterns for google apps

Description of the change

There are 2 ways for the webapp-container to receive a list of patterns to filter url browsing in a webapp container: through the manifest.json file that comes with a given (named) webapp, or through the command line.

At the moment, the 2 mechanisms are exclusive in the sense that from the webapp-container's perspective it only considers one or another when filtering navigation (the webapp manifest one being preferred) but they are NOT semantically equivalent. The list of url patterns in the manifest.json file is use as a mean to filter the urls that are being browsed to, but ALSO in the chromium & FF browsers to know if a webapp is to be installed/enabled when browsing in a given url.

For example, for Gmail, the hostname mail.google.com is used as a trigger to ask the user for an installation/enablement of a webapp in the browser. It is also implicitely used as a filter for browser once in the container.

The issue is that for applications like google services, the authentication mechanism is common. So when launched in the container, the user will be redirected to e.g. https://accounts.google.com or https://accounts.google.ca, etc.

So, the manifest.json cannot be modified to account for those, since we dont want to install a webapp from those URLs but we need a way to add extra navigation url patterns to allow google service webapps to be redirected to e.g. https://accounts.google.* etc.

We provide here 2 things:

- an way for the url patterns passed down from the command line to be also considered in the navigation filtering,
- a way to simplify url patterns for google apps

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
456. By Launchpad Translations on behalf of phablet-team

Launchpad automatic translations update.

Revision history for this message
Alberto Mardegan (mardy) wrote :

L9: semicolon :-p

L36, L45: you could avoid the ugly "action === WebView.IgnoreRequest" check if you return on line 36.

L90: what about google.co.uk and similar ones?

review: Needs Information
Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> L9: semicolon :-p
>

done

> L36, L45: you could avoid the ugly "action === WebView.IgnoreRequest" check if
> you return on line 36.
>

right, done

> L90: what about google.co.uk and similar ones?

those will have to be handled manually, which is IMO fine since they are a
substantially smaller subset. I dont want them explicitely listed
here, and I dont want to allow an extra '.' (or something like that)
in the TLD position since it is a mega-security issue.

Revision history for this message
Alberto Mardegan (mardy) wrote :

Looks good to me. Could you please tell me the steps to reproduce the existing bug, or should I simply limit myself to verify that Google+ (for example) works as a webapp after visiting the site with Firefox?

review: Needs Information
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

Testing:

- the non exclusive pattern filtering:

1. Make sure that you have a webapp installed. e.g. (Twitter).
Launch the webapp from the command line

./webapp-container --webapp='VHdpdHRlcg==' --enable-addressbar

You then should be allowed to only browse to twitter but not to any other website.
You have access to the address bar which then allows you to test browsing to various
websites. You can make sure that browsing to non twitter websites opens the url
in the default webbrowser e.g.

webapp-container --webapp='VHdpdHRlcg==' --enable-addressbar --webappUrlPatterns=https?://*.facebook.com/*

- The google pattern special case.

1. Make sure that the wrong patterns are not allowed, e.g. http://*.google.*/* (you should see a stdout message like "Ignoring empty or invalid webapp URL pattern: "https?://*.google.*/*""), or http://*.go?ogle.*/*,

2. Launch

webapp-container --webapp='VHdpdHRlcg==' --enable-addressbar --webappUrlPatterns=https?://www.google.*/*

Make sure you can browse to: https://www.google.it, https://www.google.fr, https://www.google.ca, etc.

but not to e.g. https://mail.google.com

Revision history for this message
Alberto Mardegan (mardy) wrote :

> Testing:
>
> - the non exclusive pattern filtering:
>
> 1. Make sure that you have a webapp installed. e.g. (Twitter).
> Launch the webapp from the command line
[...]

Tested, works fine (both with the --webappUrlPatterns parameter and without).

> - The google pattern special case.
>
> 1. Make sure that the wrong patterns are not allowed, e.g. http://*.google.*/*
> (you should see a stdout message like "Ignoring empty or invalid webapp URL
> pattern: "https?://*.google.*/*""), or http://*.go?ogle.*/*,

Tested, works fine.

> 2. Launch
>
> webapp-container --webapp='VHdpdHRlcg==' --enable-addressbar
> --webappUrlPatterns=https?://www.google.*/*
>
> Make sure you can browse to: https://www.google.it, https://www.google.fr,
> https://www.google.ca, etc.
>
> but not to e.g. https://mail.google.com

I can visit all of the sites, including mail.google.com and apple.com. I don't see the message about the URL pattern being invalid, so I wonder why it lets me visit those...

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> > but not to e.g. https://mail.google.com
>
> I can visit all of the sites, including mail.google.com and apple.com. I don't
> see the message about the URL pattern being invalid, so I wonder why it lets
> me visit those...

you need https://code.launchpad.net/~abreu-alexandre/webbrowser-app/fix-broken-webapp-patterns

Revision history for this message
Alberto Mardegan (mardy) wrote :

> you need https://code.launchpad.net/~abreu-alexandre/webbrowser-app/fix-
> broken-webapp-patterns

Indeed. With that branch, everything works fine.

review: Approve
457. By Launchpad Translations on behalf of phablet-team

Launchpad automatic translations update.

458. By Launchpad Translations on behalf of phablet-team

Launchpad automatic translations update.

Revision history for this message
Olivier Tilloy (osomon) wrote :

How about adding some unit tests for isValidGoogleUrlPattern()?

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> How about adding some unit tests for isValidGoogleUrlPattern()?

yup, its in the works already, ...

459. By Timo Jyrinki

Apply the revert that is in archives now, and rebuild against Qt 5.2.1

460. By PS Jenkins bot

Releasing 0.23+14.04.20140313-0ubuntu1

461. By Olivier Tilloy

Do not register private types in the public plugin.
Register them in the webbrowser application scope instead.

I have made sure that private types that were previously public are currently not being used by any application in the store, so this refactoring is safe.

462. By Leo Arias

Updated the copyright header on all the python files.

463. By Adnane Belmadiaf

Fix to open URL that start with / (local files)

464. By Olivier Tilloy

Refactor the test HTTP server to use a random port at startup.

465. By PS Jenkins bot

Releasing 0.23+14.04.20140317-0ubuntu1

466. By Colin Watson

Add multiarch annotations.

467. By PS Jenkins bot

Releasing 0.23+14.04.20140317.1-0ubuntu1

468. By Olivier Tilloy

Use the renderer only once when rendering a thumbnail.
This seems to fix the crash that was happening at destruction time. Fixes: 1294219

469. By PS Jenkins bot

Releasing 0.23+14.04.20140319-0ubuntu1

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

Updated w/ some unit tests

470. By Alexandre Abreu

Merge trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/webcontainer/CMakeLists.txt'
2--- src/app/webcontainer/CMakeLists.txt 2014-03-14 14:51:22 +0000
3+++ src/app/webcontainer/CMakeLists.txt 2014-03-20 18:17:38 +0000
4@@ -10,6 +10,7 @@
5
6 set(WEBAPP_CONTAINER_SRC
7 webapp-container.cpp
8+ url-pattern-utils.cpp
9 )
10
11 add_executable(${WEBAPP_CONTAINER} ${WEBAPP_CONTAINER_SRC})
12@@ -25,4 +26,3 @@
13 install(FILES ${QML_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/webbrowser-app/webcontainer)
14 install(DIRECTORY actions DESTINATION ${CMAKE_INSTALL_DATADIR}/webbrowser-app/webcontainer
15 FILES_MATCHING PATTERN *.qml)
16-
17
18=== modified file 'src/app/webcontainer/WebApp.qml'
19--- src/app/webcontainer/WebApp.qml 2014-03-12 11:40:03 +0000
20+++ src/app/webcontainer/WebApp.qml 2014-03-20 18:17:38 +0000
21@@ -84,23 +84,40 @@
22 }
23 }
24
25+ function haveValidUrlPatterns() {
26+ return webappUrlPatterns && webappUrlPatterns.length !== 0
27+ }
28+
29 function navigationRequestedDelegate(request) {
30 if (!request.isMainFrame) {
31 request.action = WebView.AcceptRequest
32 return
33 }
34
35- var action = WebView.AcceptRequest
36+ // Pass-through if we are not running as a named webapp (--webapp='Gmail')
37+ // or if we dont have a list of url patterns specified to filter the
38+ // browsing actions
39+ if ( ! haveValidUrlPatterns() && ! isRunningAsANamedWebapp()) {
40+ request.action = WebView.AcceptRequest
41+ return
42+ }
43+
44+ var action = WebView.IgnoreRequest
45 var url = request.url.toString()
46
47 // The list of url patterns defined by the webapp takes precedence over command line
48 if (isRunningAsANamedWebapp()) {
49 if (unityWebapps.model.exists(unityWebapps.name) &&
50- !unityWebapps.model.doesUrlMatchesWebapp(unityWebapps.name, url)) {
51- action = WebView.IgnoreRequest
52+ unityWebapps.model.doesUrlMatchesWebapp(unityWebapps.name, url)) {
53+ request.action = WebView.AcceptRequest
54+ return;
55 }
56- } else if (webappUrlPatterns && webappUrlPatterns.length !== 0) {
57- action = WebView.IgnoreRequest
58+ }
59+
60+ // We still take the possible additional patterns specified in the command line
61+ // (the in the case of finer grained ones specifically for the container and not
62+ // as an 'install source' for the webapp).
63+ if (webappUrlPatterns && webappUrlPatterns.length !== 0) {
64 for (var i = 0; i < webappUrlPatterns.length; ++i) {
65 var pattern = webappUrlPatterns[i]
66 if (url.match(pattern)) {
67@@ -112,6 +129,7 @@
68
69 request.action = action
70 if (action === WebView.IgnoreRequest) {
71+ console.debug('Opening: ' + url + ' in the browser window.')
72 Qt.openUrlExternally(url)
73 }
74 }
75
76=== added file 'src/app/webcontainer/url-pattern-utils.cpp'
77--- src/app/webcontainer/url-pattern-utils.cpp 1970-01-01 00:00:00 +0000
78+++ src/app/webcontainer/url-pattern-utils.cpp 2014-03-20 18:17:38 +0000
79@@ -0,0 +1,129 @@
80+/*
81+ * Copyright 2014 Canonical Ltd.
82+ *
83+ * This file is part of webbrowser-app.
84+ *
85+ * webbrowser-app is free software; you can redistribute it and/or modify
86+ * it under the terms of the GNU General Public License as published by
87+ * the Free Software Foundation; version 3.
88+ *
89+ * webbrowser-app is distributed in the hope that it will be useful,
90+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
91+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
92+ * GNU General Public License for more details.
93+ *
94+ * You should have received a copy of the GNU General Public License
95+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
96+ */
97+
98+#include "url-pattern-utils.h"
99+
100+#include <QtCore/QRegularExpression>
101+
102+
103+/**
104+ * Tests for the validity of a given webapp url pattern. It follows
105+ * the following grammar:
106+ *
107+ * <url-pattern> := <scheme>://<host><path>
108+ * <scheme> := 'http' | 'https'
109+ * <host> := '*' <any char except '/' and '.'>+ <hostpart> <hostpart>+
110+ * <hostpart> := '.' <any char except '/', '*', '?' and '.'>+
111+ * <path> := '/' <any chars>
112+ *
113+ * @param pattern pattern that is to be tested for validity
114+ * @return true if the url is valid, false otherwise
115+ */
116+static bool isValidWebappUrlPattern(const QString& pattern)
117+{
118+ static QRegularExpression grammar("^http(s|s\\?)?://[^\\.]+\\.[^\\.\\*\\?]+\\.[^\\.\\*\\?]+(\\.[^\\.\\*\\?/]+)*/.*$");
119+ return grammar.match(pattern).hasMatch();
120+}
121+
122+/**
123+ * A Google related webapp is treated very specifically. The issue
124+ * with those Google service related webapps is that the all rely
125+ * on a common authentication mechanism and one endup being redirected
126+ * to the auth urls automatically when needed.
127+ * Most of the redirections can be match against discrete url patterns
128+ * but there is always a country dependant step in the auth patterns, e.g.
129+ * https://accounts.google.com/* or https://accounts.google.ca/* etc.
130+ *
131+ * Since by default we dont allow a wildcard in the TLD position, the only
132+ * solution then is to manually enter the list of top level country related
133+ * domains.
134+ * In this context, we isolate the Google case, with a more restricted set of patterns
135+ * that should adhere to the following grammar:
136+ *
137+ * <url-pattern> := <scheme>://<host><path>
138+ * <scheme> := 'http' | 'https'
139+ * <host> := <any char except '/', '*', '?' and '.'>+ '.google' <hostpart>
140+ * <hostpart> := '.' <any char except '/', '?' and '.'>+
141+ * <path> := '/' <any chars>
142+ *
143+ * So for example we allow 'https://accounts.google.* /' but not 'https://*.google.* /'
144+ * (the spaces are there to avoid the confusion w/ a end of comment token.
145+ *
146+ * IMPORTAN NOTE: the '*' wildcard in the TLD position is not a REAL wildcard in the
147+ * sense that it corresponds to [^\\./], so it wont match ('google.com.evildomain') as usual.
148+ *
149+ * @param pattern pattern that is to be tested for validity
150+ * @return true if the url is valid, false otherwise
151+ */
152+static bool isValidGoogleUrlPattern(const QString& pattern)
153+{
154+ static QRegularExpression grammar("^http(s|s\\?)?://[^\\.\\?\\*]+\\.google\\.[^\\.\\?]+/.*$");
155+ return grammar.match(pattern).hasMatch();
156+}
157+
158+
159+QString UrlPatternUtils::transformWebappSearchPatternToSafePattern(const QString& pattern)
160+{
161+ QString transformedPattern;
162+
163+ if (isValidWebappUrlPattern(pattern)) {
164+
165+ QRegularExpression urlRe("(.+://)([^/]+)(.+)");
166+ QRegularExpressionMatch match = urlRe.match(pattern);
167+
168+ if (match.hasMatch())
169+ {
170+ // We make a distinction between the wildcard found in the
171+ // hostname part and the one found later. The former being more
172+ // restricted and should not be replaced by the same regexp pattern
173+ // as the latter.
174+ // A less restrictive hostname pattern might lead to the following
175+ // situation where e.g.
176+ // http://bady.guy.com/phishing.ebay.com/
177+ // matches
178+ // https?://*.ebay.com/*
179+ QString scheme = match.captured(1);
180+ QString hostname = match.captured(2).replace("*", "[^\\./]*");
181+ QString tail = match.captured(3).replace("*", "[^\\s]*");
182+
183+ // reconstruct
184+ transformedPattern = QString("%1%2%3").arg(scheme).arg(hostname).arg(tail);
185+ }
186+ } else if (isValidGoogleUrlPattern(pattern)) {
187+
188+ QRegularExpression urlRe("(.+://)([^\\./]+\\.google\\.)([^/]+)(.+)");
189+ QRegularExpressionMatch match = urlRe.match(pattern);
190+
191+ if (match.hasMatch())
192+ {
193+ QString scheme = match.captured(1);
194+ QString hostname = match.captured(2);
195+ QString tld = match.captured(3).replace("*", "[^\\./]*");
196+ QString tail = match.captured(4).replace("*", "[^\\s]*");
197+
198+ // reconstruct
199+ transformedPattern = QString("%1%2%3%4")
200+ .arg(scheme)
201+ .arg(hostname)
202+ .arg(tld)
203+ .arg(tail);
204+ }
205+ }
206+
207+ return transformedPattern;
208+}
209
210=== added file 'src/app/webcontainer/url-pattern-utils.h'
211--- src/app/webcontainer/url-pattern-utils.h 1970-01-01 00:00:00 +0000
212+++ src/app/webcontainer/url-pattern-utils.h 2014-03-20 18:17:38 +0000
213@@ -0,0 +1,32 @@
214+/*
215+ * Copyright 2014 Canonical Ltd.
216+ *
217+ * This file is part of webbrowser-app.
218+ *
219+ * webbrowser-app is free software; you can redistribute it and/or modify
220+ * it under the terms of the GNU General Public License as published by
221+ * the Free Software Foundation; version 3.
222+ *
223+ * webbrowser-app is distributed in the hope that it will be useful,
224+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
225+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
226+ * GNU General Public License for more details.
227+ *
228+ * You should have received a copy of the GNU General Public License
229+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
230+ */
231+
232+#ifndef URLPATTERNUTILS_H
233+#define URLPATTERNUTILS_H
234+
235+#include <QtCore/QString>
236+
237+
238+namespace UrlPatternUtils {
239+
240+QString transformWebappSearchPatternToSafePattern(const QString&);
241+
242+}
243+
244+
245+#endif // URLPATTERNUTILS_H
246
247=== modified file 'src/app/webcontainer/webapp-container.cpp'
248--- src/app/webcontainer/webapp-container.cpp 2014-03-06 13:32:21 +0000
249+++ src/app/webcontainer/webapp-container.cpp 2014-03-20 18:17:38 +0000
250@@ -19,6 +19,8 @@
251 #include "config.h"
252 #include "webapp-container.h"
253
254+#include "url-pattern-utils.h"
255+
256 // Qt
257 #include <QtCore/QCoreApplication>
258 #include <QtCore/QDebug>
259@@ -105,25 +107,6 @@
260 return QString();
261 }
262
263-/**
264- * Tests for the validity of a given webapp url pattern. It follows
265- * the following grammar:
266- *
267- * <url-pattern> := <scheme>://<host><path>
268- * <scheme> := 'http' | 'https'
269- * <host> := '*' <any char except '/' and '.'>+ <hostpart> <hostpart>+
270- * <hostpart> := '.' <any char except '/', '*', '?' and '.'>+
271- * <path> := '/' <any chars>
272- *
273- * @param pattern pattern that is to be tested for validity
274- * @return true if the url is valid, false otherwise
275- */
276-static bool isValidWebappUrlPattern(const QString& pattern)
277-{
278- static QRegularExpression grammar("^http(s|s\\?)?://[^\\.]+\\.[^\\.\\*\\?]+\\.[^\\.\\*\\?]+(\\.[^\\.\\*\\?/]+)*/.*$");
279- return grammar.match(pattern).hasMatch();
280-}
281-
282
283 QStringList WebappContainer::webappUrlPatterns() const
284 {
285@@ -135,27 +118,15 @@
286 QStringList includePatterns = tail.split(",");
287 Q_FOREACH(const QString& includePattern, includePatterns) {
288 QString pattern = includePattern.trimmed();
289- if (!pattern.isEmpty() && isValidWebappUrlPattern(pattern)) {
290- QRegularExpression urlRe("(.+://)([^/]+)(.+)");
291- QRegularExpressionMatch match = urlRe.match(pattern);
292- if (match.hasMatch())
293- {
294- // We make a distinction between the wildcard found in the
295- // hostname part and the one found later. The former being more
296- // restricted and should not be replaced by the same regexp pattern
297- // as the latter.
298- // A less restrictive hostname pattern might lead to the following
299- // situation where e.g.
300- // http://bady.guy.com/phishing.ebay.com/
301- // matches
302- // https?://*.ebay.com/*
303- QString scheme = match.captured(1);
304- QString hostname = match.captured(2).replace("*", "[^\\./]*");
305- QString tail = match.captured(3).replace("*", "[^\\s]*");
306-
307- // reconstruct
308- patterns.append(QString("%1%2%3").arg(scheme).arg(hostname).arg(tail));
309- }
310+
311+ if (pattern.isEmpty())
312+ continue;
313+
314+ QString safePattern =
315+ UrlPatternUtils::transformWebappSearchPatternToSafePattern(pattern);
316+
317+ if ( ! safePattern.isEmpty()) {
318+ patterns.append(safePattern);
319 } else {
320 qDebug() << "Ignoring empty or invalid webapp URL pattern:" << pattern;
321 }
322
323=== modified file 'tests/unittests/CMakeLists.txt'
324--- tests/unittests/CMakeLists.txt 2013-11-12 22:18:49 +0000
325+++ tests/unittests/CMakeLists.txt 2014-03-20 18:17:38 +0000
326@@ -8,3 +8,4 @@
327 add_subdirectory(history-domainlist-chronological-model)
328 add_subdirectory(tabs-model)
329 add_subdirectory(bookmarks-model)
330+add_subdirectory(container-url-patterns)
331
332=== added directory 'tests/unittests/container-url-patterns'
333=== added file 'tests/unittests/container-url-patterns/CMakeLists.txt'
334--- tests/unittests/container-url-patterns/CMakeLists.txt 1970-01-01 00:00:00 +0000
335+++ tests/unittests/container-url-patterns/CMakeLists.txt 2014-03-20 18:17:38 +0000
336@@ -0,0 +1,10 @@
337+set(TEST tst_ContainerUrlPatterns)
338+set(SOURCES
339+ ${webapp-container_SOURCE_DIR}/url-pattern-utils.cpp
340+ tst_ContainerUrlPatterns.cpp
341+)
342+add_executable(${TEST} ${SOURCES})
343+include_directories(${webapp-container_SOURCE_DIR})
344+qt5_use_modules(${TEST} Core Quick Test)
345+add_test(${TEST} ${CMAKE_CURRENT_BINARY_DIR}/${TEST} -xunitxml -o ${TEST}.xml)
346+set_tests_properties(${TEST} PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal")
347
348=== added file 'tests/unittests/container-url-patterns/tst_ContainerUrlPatterns.cpp'
349--- tests/unittests/container-url-patterns/tst_ContainerUrlPatterns.cpp 1970-01-01 00:00:00 +0000
350+++ tests/unittests/container-url-patterns/tst_ContainerUrlPatterns.cpp 2014-03-20 18:17:38 +0000
351@@ -0,0 +1,99 @@
352+/*
353+ * Copyright 2014 Canonical Ltd.
354+ *
355+ * This file is part of webbrowser-app.
356+ *
357+ * webbrowser-app is free software; you can redistribute it and/or modify
358+ * it under the terms of the GNU General Public License as published by
359+ * the Free Software Foundation; version 3.
360+ *
361+ * webbrowser-app is distributed in the hope that it will be useful,
362+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
363+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
364+ * GNU General Public License for more details.
365+ *
366+ * You should have received a copy of the GNU General Public License
367+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
368+ */
369+
370+// Qt
371+#include <QtCore/QString>
372+#include <QtTest/QtTest>
373+
374+// local
375+#include "url-pattern-utils.h"
376+
377+class ContainerUrlPatternsTests : public QObject
378+{
379+ Q_OBJECT
380+
381+private Q_SLOTS:
382+
383+ void transformedUrlPatterns_data()
384+ {
385+ QTest::addColumn<QString>("pattern");
386+ QTest::addColumn<QString>("transformedPattern");
387+
388+ // regular patterns
389+
390+ QTest::newRow("Valid pattern")
391+ << "https?://*.mydomain.com/*"
392+ << "https?://[^\\./]*.mydomain.com/[^\\s]*";
393+
394+#define WEBAPP_INVALID_URL_PATTERN_TEST(id,invalid_url_pattern) \
395+ QTest::newRow("Invalid pattern " #id) \
396+ << invalid_url_pattern \
397+ << QString()
398+
399+ WEBAPP_INVALID_URL_PATTERN_TEST(1, "http");
400+ WEBAPP_INVALID_URL_PATTERN_TEST(2, "://");
401+ WEBAPP_INVALID_URL_PATTERN_TEST(3, "file://");
402+ WEBAPP_INVALID_URL_PATTERN_TEST(4, "https?://");
403+ WEBAPP_INVALID_URL_PATTERN_TEST(5, "https?://*");
404+ WEBAPP_INVALID_URL_PATTERN_TEST(6, "https?://foo.*");
405+ WEBAPP_INVALID_URL_PATTERN_TEST(7, "https?://foo.ba*r.com");
406+ WEBAPP_INVALID_URL_PATTERN_TEST(8, "https?://foo.*.com/");
407+ WEBAPP_INVALID_URL_PATTERN_TEST(9, "https?://foo.bar.*/");
408+ WEBAPP_INVALID_URL_PATTERN_TEST(10, "https?://*.bar.*");
409+ WEBAPP_INVALID_URL_PATTERN_TEST(11, "https?://*.bar.*/");
410+ WEBAPP_INVALID_URL_PATTERN_TEST(12, "https?://*.bar.*/");
411+ WEBAPP_INVALID_URL_PATTERN_TEST(13, "httpsfoo?://*.bar.com/");
412+ WEBAPP_INVALID_URL_PATTERN_TEST(14, "httppoo://*.bar.com/");
413+
414+#undef WEBAPP_INVALID_URL_PATTERN_TEST
415+
416+ // Google patterns
417+
418+ QTest::newRow("Valid Google pattern")
419+ << "https?://mail.google.*/*"
420+ << "https?://mail.google.[^\\./]*/[^\\s]*";
421+
422+ QTest::newRow("Valid non Google pattern")
423+ << "https://*.google.com/*"
424+ << "https://[^\\./]*.google.com/[^\\s]*";
425+
426+#define WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(id,invalid_google_url_pattern) \
427+ QTest::newRow("Invalid Google App pattern " #id) \
428+ << invalid_google_url_pattern \
429+ << QString()
430+
431+ WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(1, "https://*.google.*/*");
432+ WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(2, "https://service.gooo*gle.com/*");
433+ WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(3, "https://service.gooo?gle.com/*");
434+ WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(4, "https://service.goo*gle.com/*");
435+ WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(5, "https://serv?ice.goo*gle.com/*");
436+ WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(6, "https://se*rv?ice.goo*gle.com/*");
437+ WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(7, "https://se*rvice.goo*gle.com/*");
438+ WEBAPP_INVALID_GOOGLE_URL_PATTERN_TEST(8, "https://se*rvice.goo*gle.*/*");
439+ }
440+
441+ void transformedUrlPatterns()
442+ {
443+ QFETCH(QString, pattern);
444+ QFETCH(QString, transformedPattern);
445+ QCOMPARE(UrlPatternUtils::transformWebappSearchPatternToSafePattern(pattern), transformedPattern);
446+ }
447+};
448+
449+QTEST_MAIN(ContainerUrlPatternsTests)
450+#include "tst_ContainerUrlPatterns.moc"

Subscribers

People subscribed via source and target branches

to status/vote changes: