Merge lp:~abreu-alexandre/unity-webapps-qml/fix-autopilot-tests-and-handle-local-apps into lp:unity-webapps-qml

Proposed by Alexandre Abreu
Status: Merged
Approved by: Alexandre Abreu
Approved revision: 56
Merged at revision: 54
Proposed branch: lp:~abreu-alexandre/unity-webapps-qml/fix-autopilot-tests-and-handle-local-apps
Merge into: lp:unity-webapps-qml
Diff against target: 350 lines (+108/-44)
7 files modified
src/Ubuntu/UnityWebApps/UnityWebApps.qml (+2/-6)
src/Ubuntu/UnityWebApps/plugin/unity-webapps-api.cpp (+92/-33)
src/Ubuntu/UnityWebApps/plugin/unity-webapps-api.h (+3/-1)
tests/integration/autopilot/html/test_webapps_hud.html (+1/-1)
tests/integration/autopilot/html/test_webapps_launcher.html (+1/-2)
tests/integration/autopilot/html/test_webapps_messagingmenu.html (+1/-1)
tests/integration/autopilot/unity_webapps_qml/tests/test_injectedOnWebapp.py (+8/-0)
To merge this branch: bzr merge lp:~abreu-alexandre/unity-webapps-qml/fix-autopilot-tests-and-handle-local-apps
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
WebApps Pending
Review via email: mp+184189@code.launchpad.net

Commit message

Simplify/fix autopilot tests; Handle better local usage of webapps component (for local apps)

Description of the change

Simplify/fix autopilot tests; Handle better local usage of webapps component (for local apps)

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
David Barth (dbarth) wrote :

Just reacting to the following part:

//FIXME: think of a better way to handle desktop/phone specifics
if ! defined(Q_OS_LINUX) || ! defined(Q_PROCESSOR_X86)

that is spread across functions, you should define another macro and put the temporary detection logic above in that macro instead.

Note: it seems that the ARM build is already complaining about it

56. By Alexandre Abreu

Simplify/fix autopilot tests; Handle better local usage of webapps component (for local apps)

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/Ubuntu/UnityWebApps/UnityWebApps.qml'
2--- src/Ubuntu/UnityWebApps/UnityWebApps.qml 2013-08-31 14:20:57 +0000
3+++ src/Ubuntu/UnityWebApps/UnityWebApps.qml 2013-09-06 12:56:00 +0000
4@@ -380,9 +380,7 @@
5
6 return {
7 init: function (params) {
8- console.debug('initi called')
9 if (! isValidInitCall(params)) {
10- console.debug('Invalid init call');
11 return;
12 }
13
14@@ -410,18 +408,16 @@
15 base.initCompleted.disconnect(onInitCompleted);
16 if (success) {
17 initialized = true;
18-
19- console.debug(JSON.stringify(params));
20-
21 callOnInitScriptFunc();
22 }
23 };
24
25 base.initCompleted.connect(onInitCompleted);
26
27+ var isLocal = params.__unity_webapps_hidden && params.__unity_webapps_hidden.local;
28 var url = params.__unity_webapps_hidden && params.__unity_webapps_hidden.url
29 ? params.__unity_webapps_hidden.url : "";
30- base.init(webappName, url, params);
31+ base.init(webappName, url, isLocal, params);
32 });
33 }
34 else {
35
36=== modified file 'src/Ubuntu/UnityWebApps/plugin/unity-webapps-api.cpp'
37--- src/Ubuntu/UnityWebApps/plugin/unity-webapps-api.cpp 2013-08-31 15:24:23 +0000
38+++ src/Ubuntu/UnityWebApps/plugin/unity-webapps-api.cpp 2013-09-06 12:56:00 +0000
39@@ -63,6 +63,7 @@
40
41 void UnityWebapps::init(const QString& name,
42 const QString& url,
43+ bool isLocal,
44 const QVariant& args)
45 {
46 Q_UNUSED(name);
47@@ -70,53 +71,63 @@
48 if (_appInfos != NULL)
49 cleanup();
50
51- qDebug() << "init";
52-
53 if (QString(args.typeName()).compare("QVariantMap") != 0)
54 {
55 qDebug() << "Invalid init() parameter types: " << args.typeName();
56-
57 Q_EMIT initCompleted(false);
58-
59 return;
60 }
61
62+#define UNITY_WEBAPPS_IS_VALID(name,type) \
63+ ( initArgs.contains(name) && initArgs.value(name).canConvert<type>() )
64+
65 QVariantMap initArgs =
66 qvariant_cast<QVariantMap>(args);
67- if ( ! initArgs.contains("name") ||
68- ! initArgs.contains("domain") ||
69- ! initArgs.contains("iconUrl")
70- )
71- {
72- qDebug() << "Invalid init() parameter content (not found): name, domain and iconUrl are mandatory";
73-
74- Q_EMIT initCompleted(false);
75-
76- return;
77- }
78- if ( ! initArgs.value("name").canConvert<QString>() ||
79- ! initArgs.value("domain").canConvert<QString>() ||
80- ! initArgs.value("iconUrl").canConvert<QString>()
81- )
82- {
83- qDebug() << "Invalid init() parameter value types.";
84-
85- Q_EMIT initCompleted(false);
86-
87- return;
88- }
89-
90+ if ( ! UNITY_WEBAPPS_IS_VALID("name", QString))
91+ {
92+ qDebug() << "Invalid init() parameter content (not found or invalid): name is mandatory";
93+ Q_EMIT initCompleted(false);
94+ return;
95+ }
96 QString displayName = initArgs.value("name").toString();
97- QString iconUrl = initArgs.value("iconUrl").toString();
98- QString domain = initArgs.value("domain").toString();
99-
100- bool success = initInternal(name, displayName, domain, iconUrl, url);
101-
102+
103+ QString iconUrl =
104+ initArgs.contains("iconUrl")
105+ && UNITY_WEBAPPS_IS_VALID("iconUrl",QString)
106+ ? initArgs.value("iconUrl").toString() : "";
107+ QString domain =
108+ initArgs.contains("domain")
109+ && UNITY_WEBAPPS_IS_VALID("domain",QString)
110+ ? initArgs.value("domain").toString() : "";
111+
112+ if ( ! isLocal && (iconUrl.isEmpty() || domain.isEmpty()))
113+ {
114+ qDebug() << "Invalid init() parameter content "
115+ "(not found or invalid): domain and iconUrl are mandatory for nonlocal apps";
116+ Q_EMIT initCompleted(false);
117+ return;
118+ }
119+
120+ QString desktopId;
121+ if (qgetenv("APP_ID").isEmpty()) {
122+ desktopId = getDesktopFilenameFor(displayName, domain);
123+ }
124+ else {
125+ desktopId = qgetenv("APP_ID");
126+ }
127+
128+ qDebug() << "UnityWebapps initialized with desktop id: " << desktopId;
129+
130+ bool success = initInternal(name,
131+ displayName,
132+ domain,
133+ iconUrl,
134+ url);
135 if (success)
136 buildAppInfos(name,
137 displayName,
138 domain,
139- getDesktopFilenameFor(displayName, domain),
140+ desktopId,
141 iconUrl);
142
143 Q_EMIT initCompleted(success);
144@@ -139,6 +150,17 @@
145 _model = model;
146 }
147
148+bool UnityWebapps::isConfined() const
149+{
150+ //Cheap way to know if we work in a confined environment
151+ //FIXME: think of a better way to handle desktop/phone specifics
152+#if defined(Q_OS_LINUX) && ! defined(Q_PROCESSOR_X86)
153+ return true;
154+#else
155+ return false;
156+#endif
157+}
158+
159 void UnityWebapps::buildAppInfos(const QString & name,
160 const QString & displayName,
161 const QString & domain,
162@@ -244,6 +266,11 @@
163 const QString& domain,
164 const QString& iconName)
165 {
166+ // we bail out earlier (until we can do it w/ a builtin func) when
167+ // in a confined environment.
168+ if (isConfined ())
169+ return true;
170+
171 if ( ! handleDesktopFileUpdates())
172 return true;
173
174@@ -375,21 +402,38 @@
175
176 QString UnityWebapps::addLauncherAction(const QString& name)
177 {
178+ // we bail out earlier (until we can do it w/ a builtin func) when
179+ // in a confined environment.
180+ if (isConfined ())
181+ return QString();
182+
183 return addAction(name, LAUNCHER_ACTION);
184 }
185
186 QString UnityWebapps::addIndicatorAction (const QString& name)
187 {
188+ // we bail out earlier (until we can do it w/ a builtin func) when
189+ // in a confined environment.
190+ if (isConfined ())
191+ return QString();
192 return addAction(name, INDICATOR_ACTION);
193 }
194
195 QString UnityWebapps::addStaticAction (const QString& name, const QString& url)
196 {
197+ // we bail out earlier (until we can do it w/ a builtin func) when
198+ // in a confined environment.
199+ if (isConfined ())
200+ return QString();
201 return addAction(name, STATIC_ACTION, url);
202 }
203
204 void UnityWebapps::removeLauncherAction(const QString& name)
205 {
206+ // we bail out earlier (until we can do it w/ a builtin func) when
207+ // in a confined environment.
208+ if (isConfined ())
209+ return;
210 if (_actions.contains(name) && (_actions[name].type & LAUNCHER_ACTION))
211 {
212 _actions[name].type &= ~LAUNCHER_ACTION;
213@@ -400,6 +444,11 @@
214
215 void UnityWebapps::removeLauncherActions()
216 {
217+ // we bail out earlier (until we can do it w/ a builtin func) when
218+ // in a confined environment.
219+ if (isConfined ())
220+ return;
221+
222 bool found = false;
223 Q_FOREACH(const QString & actionName, _actions.keys())
224 {
225@@ -442,6 +491,11 @@
226
227 void UnityWebapps::updateDesktopFileContent ()
228 {
229+ // we bail out earlier (until we can do it w/ a builtin func) when
230+ // in a confined environment.
231+ if (isConfined ())
232+ return;
233+
234 if ( ! handleDesktopFileUpdates())
235 return;
236
237@@ -466,6 +520,11 @@
238
239 void UnityWebapps::ensureLocalApplicationsPathExists()
240 {
241+ // we bail out earlier (until we can do it w/ a builtin func) when
242+ // in a confined environment.
243+ if (isConfined ())
244+ return;
245+
246 QString shareDirPath (getUserSharePath());
247 if (shareDirPath.isEmpty())
248 {
249
250=== modified file 'src/Ubuntu/UnityWebApps/plugin/unity-webapps-api.h'
251--- src/Ubuntu/UnityWebApps/plugin/unity-webapps-api.h 2013-08-31 14:20:57 +0000
252+++ src/Ubuntu/UnityWebApps/plugin/unity-webapps-api.h 2013-09-06 12:56:00 +0000
253@@ -63,7 +63,7 @@
254 public Q_SLOTS:
255
256 // API functions
257- void init(const QString& name, const QString& url, const QVariant& args);
258+ void init(const QString& name, const QString& url, bool isLocal, const QVariant& args);
259
260 // class functions
261 UnityWebappsAppInfos *appInfos();
262@@ -122,6 +122,8 @@
263 const QString& url);
264 void cleanup();
265
266+ bool isConfined() const;
267+
268 void buildAppInfos(const QString & name,
269 const QString & displayName,
270 const QString & domain,
271
272=== modified file 'tests/integration/autopilot/html/test_webapps_hud.html'
273--- tests/integration/autopilot/html/test_webapps_hud.html 2013-08-27 17:03:21 +0000
274+++ tests/integration/autopilot/html/test_webapps_hud.html 2013-09-06 12:56:00 +0000
275@@ -20,7 +20,7 @@
276 console.log('ubuntu-webapps-api-ready received');
277
278 unity = window.external.getUnityObject('1.0');
279- unity.init({name: 'unity-webapps-qml-', domain: 'launcher', onInit: onInit, iconUrl: 'icon://myicon'});
280+ unity.init({name: 'unity-webapps-qml-launcher', onInit: onInit});
281 }, false);
282
283
284
285=== modified file 'tests/integration/autopilot/html/test_webapps_launcher.html'
286--- tests/integration/autopilot/html/test_webapps_launcher.html 2013-08-26 20:16:16 +0000
287+++ tests/integration/autopilot/html/test_webapps_launcher.html 2013-09-06 12:56:00 +0000
288@@ -17,8 +17,7 @@
289 console.log('ubuntu-webapps-api-ready received');
290
291 unity = window.external.getUnityObject('1.0');
292-
293- unity.init({name: 'unity-webapps-qml-', domain: 'launcher', onInit: onInit, iconUrl: 'icon://myicon'});
294+ unity.init({name: 'unity-webapps-qml-launcher', onInit: onInit});
295 }, false);
296
297 function dispatchApiCall (target, name, args) {
298
299=== modified file 'tests/integration/autopilot/html/test_webapps_messagingmenu.html'
300--- tests/integration/autopilot/html/test_webapps_messagingmenu.html 2013-07-31 18:33:44 +0000
301+++ tests/integration/autopilot/html/test_webapps_messagingmenu.html 2013-09-06 12:56:00 +0000
302@@ -23,7 +23,7 @@
303 console.log('ubuntu-webapps-api-ready received');
304
305 unity = window.external.getUnityObject('1.0');
306- unity.init({name: 'MessagingIndicator TEST', domain: 'localhost', onInit: onInit, iconUrl: 'icon://myicon'});
307+ unity.init({name: 'unity-webapps-qml-launcher', onInit: onInit});
308 }, false);
309
310
311
312=== modified file 'tests/integration/autopilot/unity_webapps_qml/tests/test_injectedOnWebapp.py'
313--- tests/integration/autopilot/unity_webapps_qml/tests/test_injectedOnWebapp.py 2013-07-31 18:33:44 +0000
314+++ tests/integration/autopilot/unity_webapps_qml/tests/test_injectedOnWebapp.py 2013-09-06 12:56:00 +0000
315@@ -33,6 +33,8 @@
316 self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject(1.0) != null;'), Eventually(NotEquals(None)))
317
318 def test_actionsApiFound(self):
319+ self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject(1.0) != null;'), Eventually(NotEquals(None)))
320+
321 expression = """
322 var unity = window.external.getUnityObject(1.0);
323 return unity.addAction != null && unity.clearAction && unity.clearActions != null;
324@@ -40,6 +42,8 @@
325 self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(NotEquals(None)))
326
327 def test_notificationApiFound(self):
328+ self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject(1.0) != null;'), Eventually(NotEquals(None)))
329+
330 expression = """
331 var unity = window.external.getUnityObject(1.0);
332 return unity.Notification != null && unity.Notification.showNotification != null;
333@@ -47,6 +51,8 @@
334 self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(NotEquals(None)))
335
336 def test_messagingIndicatorApiFound(self):
337+ self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject(1.0) != null;'), Eventually(NotEquals(None)))
338+
339 expression = """
340 var unity = window.external.getUnityObject(1.0);
341 return unity.MessagingIndicator != null &&
342@@ -58,6 +64,8 @@
343 self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(NotEquals(None)))
344
345 def test_ubuntuReadyEventSent(self):
346+ self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject(1.0) != null;'), Eventually(NotEquals(None)))
347+
348 expression = """
349 var api_ready_count = window.localStorage['ubuntu-webapps-api-ready-key'];
350 return api_ready_count != null && api_ready_count > 0;

Subscribers

People subscribed via source and target branches

to all changes: