Merge lp:~abreu-alexandre/unity-webapps-qml/location-specific-homepage into lp:unity-webapps-qml

Proposed by Alexandre Abreu
Status: Work in progress
Proposed branch: lp:~abreu-alexandre/unity-webapps-qml/location-specific-homepage
Merge into: lp:unity-webapps-qml
Diff against target: 400 lines (+194/-39)
9 files modified
src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-manifest-parser.cpp (+49/-10)
src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-manifest-parser.h (+22/-6)
src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp (+14/-2)
tests/unit/test_plugin/data/installed-webapps/unity-webapps-valid/manifest.json (+29/-9)
tests/unit/test_plugin/data/installed-webapps/unity-webapps-with-requires-valid/manifest.json (+29/-9)
tests/unit/test_plugin/data/manifests/valid-manifest-per-country-homepage.json (+17/-0)
tests/unit/test_plugin/test_plugin.pro (+4/-0)
tests/unit/test_plugin/tst_webappsAppModel.cpp (+28/-2)
tests/unit/test_plugin/tst_webappsAppModel.h (+2/-1)
To merge this branch: bzr merge lp:~abreu-alexandre/unity-webapps-qml/location-specific-homepage
Reviewer Review Type Date Requested Status
WebApps Pending
Review via email: mp+284918@code.launchpad.net

Commit message

Homepage as a URL or a per-country url object

Description of the change

Homepage as a URL or a per-country url object

To post a comment you must log in.
Revision history for this message
David Barth (dbarth) wrote :
Download full text (14.6 KiB)

Hmm, I don't get where you choose between countries in that change

On Wed, Feb 3, 2016 at 4:37 PM, Alexandre Abreu <
<email address hidden>> wrote:

> Alexandre Abreu has proposed merging
> lp:~abreu-alexandre/unity-webapps-qml/location-specific-homepage into
> lp:unity-webapps-qml.
>
> Commit message:
> Homepage as a URL or a per-country url object
>
> Requested reviews:
> WebApps (webapps)
> Related bugs:
> Bug #1523464 in webapp-container: "Amazon web app on the launcher in
> 16.04 sends me to .COM instead of .co.uk"
> https://bugs.launchpad.net/webapp-container/+bug/1523464
>
> For more details, see:
>
> https://code.launchpad.net/~abreu-alexandre/unity-webapps-qml/location-specific-homepage/+merge/284918
>
> Homepage as a URL or a per-country url object
> --
> Your team WebApps is requested to review the proposed merge of
> lp:~abreu-alexandre/unity-webapps-qml/location-specific-homepage into
> lp:unity-webapps-qml.
>
> === modified file
> 'src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-manifest-parser.cpp'
> --- src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-manifest-parser.cpp
> 2014-05-14 01:41:14 +0000
> +++ src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-manifest-parser.cpp
> 2016-02-03 15:36:20 +0000
> @@ -1,5 +1,5 @@
> /*
> - * Copyright 2013 Canonical Ltd.
> + * Copyright 2013-2016 Canonical Ltd.
> *
> * This file is part of unity-webapps-qml.
> *
> @@ -16,12 +16,13 @@
> * along with this program. If not, see <http://www.gnu.org/licenses/>.
> */
>
> -#include <QTextStream>
> -#include <QJsonDocument>
> -#include <QJsonObject>
> -#include <QJsonArray>
> -#include <QJsonValue>
> -#include <QDebug>
> +#include <QtCore/QDebug>
> +#include <QtCore/QJsonDocument>
> +#include <QtCore/QJsonObject>
> +#include <QtCore/QJsonArray>
> +#include <QtCore/QJsonValue>
> +#include <QtCore/QTextStream>
> +#include <QtCore/QVariantMap>
>
> #include "unity-webapps-app-manifest-parser.h"
>
> @@ -62,6 +63,33 @@
> return ManifestFileInfoOption(infos);
> }
>
> +WebappHomepage UnityWebappsAppManifestParser::extractHomepage(
> + const QJsonValue& o)
> +{
> + WebappHomepage homepage;
> + if (o.isString())
> + {
> + homepage.homepageURI = QUrl::fromUserInput(o.toString());
> + return homepage;
> + }
> +
> + if (o.isObject())
> + {
> + QVariantMap vm = o.toVariant().toMap();
> + Q_FOREACH(const QString& k, vm.keys())
> + {
> + if (vm[k].canConvert(QVariant::String))
> + {
> + homepage.homepagePerCountry[k.toLower()] =
> + QUrl::fromUserInput(vm[k].toString());
> + }
> + }
> + return homepage;
> + }
> +
> + return homepage;
> +}
> +
> bool UnityWebappsAppManifestParser::parseWebappDeclaration(const
> QJsonObject& json,
>
> ManifestFileInfo * infos)
> {
> @@ -70,20 +98,31 @@
> if ( !json.contains(QLatin1String(property)) \
> || !json.value(QLatin1String(property)).predicate()) \
> { \
> - qDebug() << "Invalid webapp webapp definition:" << property
> << "not found or fails predicate" << #predicate; \
> + qDebu...

Unmerged revisions

155. By Alexandre Abreu

Homepage as a URL or a per-country url object

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-manifest-parser.cpp'
2--- src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-manifest-parser.cpp 2014-05-14 01:41:14 +0000
3+++ src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-manifest-parser.cpp 2016-02-03 15:36:20 +0000
4@@ -1,5 +1,5 @@
5 /*
6- * Copyright 2013 Canonical Ltd.
7+ * Copyright 2013-2016 Canonical Ltd.
8 *
9 * This file is part of unity-webapps-qml.
10 *
11@@ -16,12 +16,13 @@
12 * along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14
15-#include <QTextStream>
16-#include <QJsonDocument>
17-#include <QJsonObject>
18-#include <QJsonArray>
19-#include <QJsonValue>
20-#include <QDebug>
21+#include <QtCore/QDebug>
22+#include <QtCore/QJsonDocument>
23+#include <QtCore/QJsonObject>
24+#include <QtCore/QJsonArray>
25+#include <QtCore/QJsonValue>
26+#include <QtCore/QTextStream>
27+#include <QtCore/QVariantMap>
28
29 #include "unity-webapps-app-manifest-parser.h"
30
31@@ -62,6 +63,33 @@
32 return ManifestFileInfoOption(infos);
33 }
34
35+WebappHomepage UnityWebappsAppManifestParser::extractHomepage(
36+ const QJsonValue& o)
37+{
38+ WebappHomepage homepage;
39+ if (o.isString())
40+ {
41+ homepage.homepageURI = QUrl::fromUserInput(o.toString());
42+ return homepage;
43+ }
44+
45+ if (o.isObject())
46+ {
47+ QVariantMap vm = o.toVariant().toMap();
48+ Q_FOREACH(const QString& k, vm.keys())
49+ {
50+ if (vm[k].canConvert(QVariant::String))
51+ {
52+ homepage.homepagePerCountry[k.toLower()] =
53+ QUrl::fromUserInput(vm[k].toString());
54+ }
55+ }
56+ return homepage;
57+ }
58+
59+ return homepage;
60+}
61+
62 bool UnityWebappsAppManifestParser::parseWebappDeclaration(const QJsonObject& json,
63 ManifestFileInfo * infos)
64 {
65@@ -70,20 +98,31 @@
66 if ( !json.contains(QLatin1String(property)) \
67 || !json.value(QLatin1String(property)).predicate()) \
68 { \
69- qDebug() << "Invalid webapp webapp definition:" << property << "not found or fails predicate" << #predicate; \
70+ qDebug() << "Invalid webapp webapp definition:" \
71+ << property \
72+ << "not found or fails predicate" \
73+ << #predicate; \
74 return false; \
75 } \
76 } while(0)
77
78 VALIDATE_PROPERTY_TYPE("name",isString);
79 VALIDATE_PROPERTY_TYPE("domain",isString);
80- VALIDATE_PROPERTY_TYPE("homepage",isString);
81 VALIDATE_PROPERTY_TYPE("includes",isArray);
82 #undef VALIDATE_PROPERTY_TYPE
83
84+ if ( !json.contains(QLatin1String("homepage"))
85+ && ( !json.value(QLatin1String("homepage")).isString()
86+ || !json.value(QLatin1String("homepage")).isObject())
87+ )
88+ {
89+ qDebug() << "Invalid webapp webapp definition: homepage not found or not a string or object ";
90+ return false;
91+ }
92+
93 infos->name = json.value(QLatin1String("name")).toString();
94 infos->domain = json.value(QLatin1String("domain")).toString();
95- infos->homepage = json.value(QLatin1String("homepage")).toString();
96+ infos->homepage = extractHomepage(json.value(QLatin1String("homepage")));
97 infos->includes = parseArray(json, QLatin1String("includes"));
98
99 // Script & requires (script source dependancies found in common/)
100
101=== modified file 'src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-manifest-parser.h'
102--- src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-manifest-parser.h 2014-05-12 18:27:51 +0000
103+++ src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-manifest-parser.h 2016-02-03 15:36:20 +0000
104@@ -1,5 +1,5 @@
105 /*
106- * Copyright 2013 Canonical Ltd.
107+ * Copyright 2013-2016 Canonical Ltd.
108 *
109 * This file is part of unity-webapps-qml.
110 *
111@@ -19,12 +19,26 @@
112 #ifndef __UNITY_WEBAPPS_APP_MANIFEST_H__
113 #define __UNITY_WEBAPPS_APP_MANIFEST_H__
114
115-#include <QString>
116-#include <QStringList>
117-#include <QFileInfo>
118+#include <QtCore/QFileInfo>
119+#include <QtCore/QMap>
120+#include <QtCore/QString>
121+#include <QtCore/QStringList>
122+#include <QtCore/QUrl>
123
124 #include "unity-webapps-common-priv.h"
125
126+
127+/**
128+ * @brief Homepage for a webapp
129+ *
130+ * A homepage can either be a plain single string or
131+ * a per-country (geobased) URL.
132+ */
133+struct WebappHomepage {
134+ QUrl homepageURI;
135+ QMap<QString, QUrl> homepagePerCountry;
136+};
137+
138 /*!
139 * \brief Data view of a given WebApp manifest
140 *
141@@ -36,8 +50,8 @@
142 QString name;
143 // Domain associated with the WebApp (TLD)
144 QString domain;
145- // Homepage that should be used when the webapp is being launched
146- QString homepage;
147+ // that should be used when the webapp is being launched
148+ WebappHomepage homepage;
149 // List of urls for which the WebApp applies (wildcard are allowed)
150 QStringList includes;
151 // List of javascript files that correspond to script names for the WebApp
152@@ -109,6 +123,8 @@
153 */
154 bool parseWebappDeclaration(const QJsonObject& json,
155 ManifestFileInfo * infos);
156+
157+ WebappHomepage extractHomepage(const QJsonValue& value);
158 };
159
160 #endif // __UNITY_WEBAPPS_APP_MANIFEST_H__
161
162=== modified file 'src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp'
163--- src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp 2015-01-08 19:36:38 +0000
164+++ src/Ubuntu/UnityWebApps/plugin/unity-webapps-app-model.cpp 2016-02-03 15:36:20 +0000
165@@ -1,5 +1,5 @@
166 /*
167- * Copyright 2013 Canonical Ltd.
168+ * Copyright 2013-2016 Canonical Ltd.
169 *
170 * This file is part of unity-webapps-qml.
171 *
172@@ -545,8 +545,20 @@
173 return webapp.data.manifest.domain;
174
175 case Homepage:
176- return webapp.data.manifest.homepage;
177+ {
178+ if ( ! webapp.data.manifest.homepage.homepageURI.isEmpty())
179+ {
180+ return webapp.data.manifest.homepage.homepageURI;
181+ }
182
183+ QVariantMap vm;
184+ Q_FOREACH(const QString& k,
185+ webapp.data.manifest.homepage.homepagePerCountry.keys())
186+ {
187+ vm[k] = webapp.data.manifest.homepage.homepagePerCountry[k];
188+ }
189+ return vm;
190+ }
191 case Urls:
192 return webapp.data.manifest.includes;
193
194
195=== modified file 'tests/unit/test_plugin/data/installed-webapps/unity-webapps-valid/manifest.json'
196--- tests/unit/test_plugin/data/installed-webapps/unity-webapps-valid/manifest.json 2013-08-27 14:36:15 +0000
197+++ tests/unit/test_plugin/data/installed-webapps/unity-webapps-valid/manifest.json 2016-02-03 15:36:20 +0000
198@@ -1,14 +1,34 @@
199 {
200- "includes": ["http://www.bbc.co.uk/news", "http://www.bbc.*/news/*"],
201- "requires": ["utils.js"],
202- "name": "BBCNews-valid",
203- "scripts": ["valid.user.js"],
204+ "architecture": "all",
205+ "description": "description of myapp",
206+ "domain": "bbc.co.uk",
207+ "framework": "ubuntu-sdk-15.04",
208+ "homepage": "http://www.bbc.co.uk/news/",
209+ "hooks": {
210+ "myapp": {
211+ "apparmor": "myapp.apparmor",
212+ "desktop": "myapp.desktop"
213+ }
214+ },
215+ "icons": {
216+ "128": "128/unity-webapps-bbc.png"
217+ },
218+ "includes": [
219+ "http://www.bbc.co.uk/news",
220+ "http://www.bbc.*/news/*"
221+ ],
222+ "integration-version": "2.3",
223+ "license": "GPL-3",
224 "maintainer": "Webapps Team <webapps@lists.launchpad.net>",
225 "manifest-version": "1.0",
226- "integration-version": "2.3",
227+ "name": "bbcnews-valid",
228 "package-name": "BBCNews",
229- "icons": {"128":"128/unity-webapps-bbc.png"},
230- "domain":"bbc.co.uk",
231- "homepage":"http://www.bbc.co.uk/news/",
232- "license":"GPL-3"
233+ "requires": [
234+ "utils.js"
235+ ],
236+ "scripts": [
237+ "valid.user.js"
238+ ],
239+ "title": "myapp",
240+ "version": "0.1"
241 }
242
243=== modified file 'tests/unit/test_plugin/data/installed-webapps/unity-webapps-with-requires-valid/manifest.json'
244--- tests/unit/test_plugin/data/installed-webapps/unity-webapps-with-requires-valid/manifest.json 2013-06-05 14:24:44 +0000
245+++ tests/unit/test_plugin/data/installed-webapps/unity-webapps-with-requires-valid/manifest.json 2016-02-03 15:36:20 +0000
246@@ -1,14 +1,34 @@
247 {
248- "includes": ["http://www.bbc.co.uk/news/", "http://www.bbc.com/news/"],
249- "requires": ["utils.js"],
250- "name": "with-requires-valid",
251- "scripts": ["valid.user.js"],
252+ "architecture": "all",
253+ "description": "description of myapp",
254+ "domain": "bbc.co.uk",
255+ "framework": "ubuntu-sdk-15.04",
256+ "homepage": "http://www.bbc.co.uk/news/",
257+ "hooks": {
258+ "myapp": {
259+ "apparmor": "myapp.apparmor",
260+ "desktop": "myapp.desktop"
261+ }
262+ },
263+ "icons": {
264+ "128": "128/unity-webapps-bbc.png"
265+ },
266+ "includes": [
267+ "http://www.bbc.co.uk/news/",
268+ "http://www.bbc.com/news/"
269+ ],
270+ "integration-version": "2.3",
271+ "license": "GPL-3",
272 "maintainer": "Webapps Team <webapps@lists.launchpad.net>",
273 "manifest-version": "1.0",
274- "integration-version": "2.3",
275+ "name": "with-requires-valid",
276 "package-name": "BBCNews",
277- "icons": {"128":"128/unity-webapps-bbc.png"},
278- "domain":"bbc.co.uk",
279- "homepage":"http://www.bbc.co.uk/news/",
280- "license":"GPL-3"
281+ "requires": [
282+ "utils.js"
283+ ],
284+ "scripts": [
285+ "valid.user.js"
286+ ],
287+ "title": "myapp",
288+ "version": "0.1"
289 }
290
291=== added file 'tests/unit/test_plugin/data/manifests/valid-manifest-per-country-homepage.json'
292--- tests/unit/test_plugin/data/manifests/valid-manifest-per-country-homepage.json 1970-01-01 00:00:00 +0000
293+++ tests/unit/test_plugin/data/manifests/valid-manifest-per-country-homepage.json 2016-02-03 15:36:20 +0000
294@@ -0,0 +1,17 @@
295+{
296+ "includes": ["http://www.bbc.co.uk/news/", "http://www.bbc.com/news/"],
297+ "requires": ["utils.js"],
298+ "name": "BBCNews",
299+ "scripts": ["BBCNews.user.js"],
300+ "maintainer": "Webapps Team <webapps@lists.launchpad.net>",
301+ "manifest-version": "1.0",
302+ "integration-version": "2.3",
303+ "package-name": "BBCNews",
304+ "icons": {"128":"128/unity-webapps-bbc.png"},
305+ "domain":"bbc.co.uk",
306+ "homepage": {
307+ "Country": "http://www.bbc.co.uk/news/",
308+ "Country2": "http://www.bbc.co.uk/news/"
309+ },
310+ "license":"GPL-3"
311+}
312
313=== modified file 'tests/unit/test_plugin/test_plugin.pro'
314--- tests/unit/test_plugin/test_plugin.pro 2014-05-12 18:27:51 +0000
315+++ tests/unit/test_plugin/test_plugin.pro 2016-02-03 15:36:20 +0000
316@@ -53,4 +53,8 @@
317
318 QMAKE_EXTRA_TARGETS += check
319
320+DISTFILES += \
321+ data/manifests/valid-manifest-per-country-homepage.json \
322+ data/webapps-with-per-country-homepage-valid/manifest.json
323+
324
325
326=== modified file 'tests/unit/test_plugin/tst_webappsAppModel.cpp'
327--- tests/unit/test_plugin/tst_webappsAppModel.cpp 2014-07-17 13:41:45 +0000
328+++ tests/unit/test_plugin/tst_webappsAppModel.cpp 2016-02-03 15:36:20 +0000
329@@ -1,5 +1,5 @@
330 /*
331- * Copyright 2013 Canonical Ltd.
332+ * Copyright 2013-2016 Canonical Ltd.
333 *
334 * This file is part of unity-webapps-qml.
335 *
336@@ -25,6 +25,7 @@
337 #include <QSignalSpy>
338 #include <QJsonDocument>
339 #include <QTest>
340+#include <QVariantMap>
341 #include <QDir>
342
343 #include "plugin/unity-webapps-app-model.h"
344@@ -126,8 +127,9 @@
345 UnityWebappsAppModel
346 model;
347 model.setSearchPath(VALID_INSTALLED_WEBAPPS_SEARCH_PATH);
348-
349+qDebug() << VALID_INSTALLED_WEBAPPS_COUNT;
350 const int FOUND_COUNT = model.rowCount();
351+ qDebug() << FOUND_COUNT;
352 QCOMPARE(FOUND_COUNT, VALID_INSTALLED_WEBAPPS_COUNT);
353
354 int i = 0;
355@@ -188,3 +190,27 @@
356 QVERIFY(model.getSingleInlineWebappName() == "MyWebApp");
357 }
358 }
359+
360+void WebappsAppModelTest::testWebappPerCountryHomepage()
361+{
362+ const QFileInfoList VALID_INSTALLED_WEBAPPS_SEARCH_PATHS =
363+ QDir(VALID_INSTALLED_WEBAPPS_SEARCH_PATH)
364+ .entryInfoList (QStringList("*-per-country-homepage-valid")
365+ , QDir::Dirs);
366+
367+ QVERIFY(VALID_INSTALLED_WEBAPPS_SEARCH_PATHS.count() > 0);
368+
369+ Q_FOREACH(const QFileInfo & fileInfo, VALID_INSTALLED_WEBAPPS_SEARCH_PATHS)
370+ {
371+ UnityWebappsAppModel
372+ model;
373+ model.setSearchPath(fileInfo.absoluteFilePath());
374+
375+ QVERIFY(model.rowCount() > 0);
376+
377+ QVERIFY(model.data(0, UnityWebappsAppModel::Homepage).canConvert(QVariant::Map));
378+ QVariantMap vm = model.data(0, UnityWebappsAppModel::Homepage).toMap();
379+ QVERIFY(vm.find("country") != vm.end());
380+ QVERIFY(*vm.find("country") == "http://www.bbc.co.uk/news/");
381+ }
382+}
383
384=== modified file 'tests/unit/test_plugin/tst_webappsAppModel.h'
385--- tests/unit/test_plugin/tst_webappsAppModel.h 2014-05-08 15:32:17 +0000
386+++ tests/unit/test_plugin/tst_webappsAppModel.h 2016-02-03 15:36:20 +0000
387@@ -1,5 +1,5 @@
388 /*
389- * Copyright 2013 Canonical Ltd.
390+ * Copyright 2013-2016 Canonical Ltd.
391 *
392 * This file is part of unity-webapps-qml.
393 *
394@@ -40,6 +40,7 @@
395 void testWebappsContentWithRequiresModel();
396 void testWebappsModelUrlMatch();
397 void testSimplifiedManifestInstall();
398+ void testWebappPerCountryHomepage();
399
400 private:
401

Subscribers

People subscribed via source and target branches

to all changes: