Merge lp:~abreu-alexandre/unity-webapps-qml/improve-embedded-ui-params-passing into lp:unity-webapps-qml

Proposed by Alexandre Abreu
Status: Merged
Approved by: Alexandre Abreu
Approved revision: 153
Merged at revision: 151
Proposed branch: lp:~abreu-alexandre/unity-webapps-qml/improve-embedded-ui-params-passing
Merge into: lp:unity-webapps-qml
Diff against target: 800 lines (+593/-21)
16 files modified
src/Ubuntu/UnityWebApps/UnityWebApps.js (+21/-3)
src/Ubuntu/UnityWebApps/UnityWebApps.qml (+26/-2)
src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js (+14/-2)
src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js (+27/-0)
tests/unit/test_qml/embeddedUI.qml (+27/-0)
tests/unit/test_qml/empty.html (+6/-0)
tests/unit/test_qml/test_qml.pro (+9/-1)
tests/unit/test_qml/tst_api_contenthub.html (+42/-0)
tests/unit/test_qml/tst_api_contenthub.js (+28/-0)
tests/unit/test_qml/tst_api_contenthub.qml (+198/-0)
tests/unit/test_qml/tst_api_launchEmbeddedUI.html (+21/-0)
tests/unit/test_qml/tst_api_launchEmbeddedUI.js (+28/-0)
tests/unit/test_qml/tst_api_launchEmbeddedUI.qml (+91/-0)
tests/unit/test_qml/tst_cleanup.qml (+18/-0)
tests/unit/test_qml/tst_dispatch.qml (+19/-0)
tests/unit/test_qml/tst_init.qml (+18/-13)
To merge this branch: bzr merge lp:~abreu-alexandre/unity-webapps-qml/improve-embedded-ui-params-passing
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Ken VanDine Needs Information
Review via email: mp+250329@code.launchpad.net

Commit message

Improve paramater passing to launchEmbedded UI

Description of the change

Improve paramater passing to launchEmbedded UI

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Does this allow arbitrary key/value pairs for properties?

review: Needs Information
145. By Alberto Mardegan

Bindings for the OnlineAccounts.Client module Fixes: #1427649
Approved by: Justin McPherson, PS Jenkins bot

146. By CI Train Bot Account

Releasing 0.1+15.04.20150304-0ubuntu1

147. By Alexandre Abreu

Add tools API that exposed helpers to webaps
Approved by: PS Jenkins bot

148. By CI Train Bot Account

Releasing 0.1+15.04.20150319-0ubuntu1

149. By Daniel Holbach

Add ./update-docs script which generates API docs locally. We can't make this part of the build as not all node dependencies of yuidocsjs are packaged in the archive.
Approved by: PS Jenkins bot, David Barth

150. By CI Train Bot Account

Releasing 0.1+15.04.20150409-0ubuntu1

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
151. By Alexandre Abreu

Fix conteht hub missing api; fix tests

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
152. By Alexandre Abreu

fix tests

153. By Alexandre Abreu

nit

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 :

> Does this allow arbitrary key/value pairs for properties?

yes :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.js'
2--- src/Ubuntu/UnityWebApps/UnityWebApps.js 2015-03-18 15:34:27 +0000
3+++ src/Ubuntu/UnityWebApps/UnityWebApps.js 2015-04-17 18:58:01 +0000
4@@ -33,15 +33,22 @@
5 /**
6 * \param parentItem
7 * \param bindeeProxies
8- * \param backends
9- * \param userscriptContent
10+ * \param accessPolicy
11+ * \param injected_api_path
12+ * \param dispatched_callback
13 */
14- function _UnityWebApps(parentItem, bindeeProxies, accessPolicy, injected_api_path) {
15+ function _UnityWebApps(
16+ parentItem,
17+ bindeeProxies,
18+ accessPolicy,
19+ injected_api_path,
20+ dispatched_callback) {
21 this._injected_unity_api_path = injected_api_path;
22 this._bindeeProxies = bindeeProxies;
23 this._backends = null;
24 this._accessPolicy = accessPolicy;
25 this._callbackManager = UnityWebAppsUtils.makeCallbackManager();
26+ this._dispatchedCallback = dispatched_callback
27
28 this._bind();
29 };
30@@ -152,8 +159,14 @@
31 return;
32 }
33
34+
35 this._log ('WebApps API message being dispatch: ' + apiCallName);
36
37+ if (this._dispatchedCallback &&
38+ typeof(this._dispatchedCallback) === 'function') {
39+ this._dispatchedCallback({type: "dispatching", name: apiCallName})
40+ }
41+
42 this._dispatchApiCall (message.name, params);
43
44 } else if (target === UnityWebAppsUtils.UBUNTU_WEBAPPS_BINDING_OBJECT_METHOD_CALL_MESSAGE) {
45@@ -215,6 +228,11 @@
46 }, reducetarget);
47 t.apply (null, args);
48
49+ if (this._dispatchedCallback &&
50+ typeof(this._dispatchedCallback) === 'function') {
51+ this._dispatchedCallback({type: "called", name: name})
52+ }
53+
54 } catch (err) {
55 this._log('Error while dispatching call to ' + names.join('.') + ': ' + err);
56 }
57
58=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.qml'
59--- src/Ubuntu/UnityWebApps/UnityWebApps.qml 2015-03-19 14:06:48 +0000
60+++ src/Ubuntu/UnityWebApps/UnityWebApps.qml 2015-04-17 18:58:01 +0000
61@@ -178,6 +178,12 @@
62 */
63 signal userScriptsInjected()
64
65+ /*!
66+ \qmlsignal UnityWebApps::apiCallDispatched()
67+
68+ This signal is emitted when an api call is being dispatched to the backend.
69+ */
70+ signal apiCallDispatched(string type, string name)
71
72 Settings {
73 id: settings
74@@ -236,7 +242,10 @@
75 __getPolicyForContent(settings),
76 customClientApiFileUrl && customClientApiFileUrl.length !== 0
77 ? customClientApiFileUrl
78- : 'unity-webapps-api.js');
79+ : 'unity-webapps-api.js',
80+ function(info) {
81+ apiCallDispatched(info.type, info.name)
82+ });
83
84 internal.instance = instance;
85
86@@ -644,7 +653,22 @@
87
88 var uicomponent;
89 function onCreated() {
90- var uiobject = uicomponent.createObject(p, {"fileToShare": params.fileToShare.url, "visible": true});
91+ var args = {}
92+ for (var k in params) {
93+ if (params.hasOwnProperty(k)) {
94+ args[k] = params[k]
95+ }
96+ }
97+
98+ // For backward compatibility
99+ if (params.hasOwnProperty("fileToShare") &&
100+ typeof(params.fileToShare) === 'object' &&
101+ params.fileToShare.hasOwnProperty("url")) {
102+ args.fileToShare = params.fileToShare.url
103+ }
104+
105+ args.visible = true
106+ var uiobject = uicomponent.createObject(p, args);
107 if ( ! uiobject.onCompleted) {
108 console.error("launchEmbeddedUI: The local UI component to be launched does not expose a mandatory 'completed' signal");
109 uiobject.destroy();
110
111=== modified file 'src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js'
112--- src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js 2014-12-02 02:19:04 +0000
113+++ src/Ubuntu/UnityWebApps/bindings/content-hub/backend/content-hub.js 2015-04-17 18:58:01 +0000
114@@ -1,5 +1,5 @@
115 /*
116- * Copyright 2014 Canonical Ltd.
117+ * Copyright 2014-2015 Canonical Ltd.
118 *
119 * This file is part of unity-webapps-qml.
120 *
121@@ -239,7 +239,8 @@
122 store: self._object.store,
123 state: self._object.state,
124 selectionType: self._object.selectionType,
125- direction: self._object.direction,
126+ contentType: self._object.contentType,
127+ direction: self._object.direction
128 }
129 }
130 },
131@@ -285,6 +286,17 @@
132 });
133 },
134
135+ contentType: function(callback) {
136+ this._validate();
137+ callback(_contentTypeToName(this._object.contentType));
138+ },
139+ setContentType: function(contentType, callback) {
140+ this._validate();
141+ this._object.contentType = _nameToContentType(contentType);
142+ if (callback && typeof(callback) === 'function')
143+ callback();
144+ },
145+
146 selectionType: function(callback) {
147 this._validate();
148 callback(_contentTransferSelectionToName(this._object.selectionType));
149
150=== modified file 'src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js'
151--- src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js 2014-06-04 14:41:59 +0000
152+++ src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js 2015-04-17 18:58:01 +0000
153@@ -44,6 +44,8 @@
154 ? content.state : null;
155 this._selectionType = content && content.selectionType
156 ? content.selectionType : null;
157+ this._contentType = content && content.contentType
158+ ? content.contentType : null;
159 this._direction = content && content.direction
160 ? content.direction : null;
161 };
162@@ -148,6 +150,31 @@
163 },
164
165 /**
166+ * Retrieves the current content type.
167+ *
168+ * @method contentType
169+ * @param callback {Function(ContentTransfer.ContentType)}
170+ */
171+ contentType: function(callback) {
172+ if (callback && typeof(callback) === 'function') {
173+ this._proxy.call('contentType', [], callback);
174+ return;
175+ }
176+ return this._contentType;
177+ },
178+ /**
179+ * Sets the content type.
180+ *
181+ * @method setContentType
182+ * @param contentType {ContentTransfer.ContentType}
183+ * @param callback {Function()} called when the state has been updated
184+ */
185+ setContentType: function(contentType, callback) {
186+ this._contentType = contentType;
187+ this._proxy.call('setContentType', [contentType, callback]);
188+ },
189+
190+ /**
191 * Retrieves the current transfer direction.
192 *
193 * If the callback parameter is not set, the current "local" value is retrieved.
194
195=== added file 'tests/unit/test_qml/embeddedUI.qml'
196--- tests/unit/test_qml/embeddedUI.qml 1970-01-01 00:00:00 +0000
197+++ tests/unit/test_qml/embeddedUI.qml 2015-04-17 18:58:01 +0000
198@@ -0,0 +1,27 @@
199+/*
200+ * Copyright 2015 Canonical Ltd.
201+ *
202+ * This file is part of unity-webapps-qml.
203+ *
204+ * unity-webapps-qml is free software; you can redistribute it and/or modify
205+ * it under the terms of the GNU General Public License as published by
206+ * the Free Software Foundation; version 3.
207+ *
208+ * unity-webapps-qml is distributed in the hope that it will be useful,
209+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
210+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
211+ * GNU General Public License for more details.
212+ *
213+ * You should have received a copy of the GNU General Public License
214+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
215+ */
216+
217+import QtQuick 2.0
218+
219+Rectangle {
220+ property string fileToShare
221+ property string p
222+ property string q
223+
224+ color: Qt.red
225+}
226
227=== added file 'tests/unit/test_qml/empty.html'
228--- tests/unit/test_qml/empty.html 1970-01-01 00:00:00 +0000
229+++ tests/unit/test_qml/empty.html 2015-04-17 18:58:01 +0000
230@@ -0,0 +1,6 @@
231+<html>
232+<head>
233+</head>
234+<body>
235+</body>
236+</html>
237
238=== modified file 'tests/unit/test_qml/test_qml.pro'
239--- tests/unit/test_qml/test_qml.pro 2014-01-21 19:58:04 +0000
240+++ tests/unit/test_qml/test_qml.pro 2015-04-17 18:58:01 +0000
241@@ -19,7 +19,15 @@
242
243 OTHER_FILES += \
244 $$system(ls *.qml) \
245- $$system(ls *.sh)
246+ $$system(ls *.sh) \
247+ tst_api_contenthub.qml \
248+ tst_api_contenthub.html \
249+ tst_api_contenthub.js \
250+ tst_api_launchEmbeddedUI.qml \
251+ tst_api_launchEmbeddedUI.html \
252+ embeddedUI.qml \
253+ tst_api_launchEmbeddedUI.js \
254+ empty.html
255
256
257 # make check target
258
259=== added file 'tests/unit/test_qml/tst_api_contenthub.html'
260--- tests/unit/test_qml/tst_api_contenthub.html 1970-01-01 00:00:00 +0000
261+++ tests/unit/test_qml/tst_api_contenthub.html 2015-04-17 18:58:01 +0000
262@@ -0,0 +1,42 @@
263+<html>
264+
265+<head>
266+<script>
267+
268+var activeTransfer
269+
270+function _shareRequested(transfer) {
271+ activeTransfer = transfer;
272+
273+ var e = new CustomEvent("onsharerequest", { bubbles: true, detail: { } });
274+ document.documentElement.dispatchEvent(e);
275+
276+ activeTransfer.contentType(function(type) {
277+ var e = new CustomEvent("received-object-value",
278+ { bubbles: true, detail: { value: type } });
279+ document.documentElement.dispatchEvent(e);
280+ })
281+}
282+
283+function setup() {
284+ var api = external.getUnityObject('1.0');
285+ var hub = api.ContentHub;
286+ hub.onShareRequested(_shareRequested);
287+}
288+
289+window.onload = function () {
290+ if (window.external && window.external.getUnityObject) {
291+ setup()
292+ } else {
293+ document.addEventListener('ubuntu-webapps-api-ready', function() {
294+ setup()
295+ });
296+ }
297+}
298+</script>
299+</head>
300+
301+<body>
302+</body>
303+
304+</html>
305
306=== added file 'tests/unit/test_qml/tst_api_contenthub.js'
307--- tests/unit/test_qml/tst_api_contenthub.js 1970-01-01 00:00:00 +0000
308+++ tests/unit/test_qml/tst_api_contenthub.js 2015-04-17 18:58:01 +0000
309@@ -0,0 +1,28 @@
310+// vim:expandtab:shiftwidth=2:tabstop=2:
311+// Copyright (C) 2015 Canonical Ltd.
312+
313+// This library is free software; you can redistribute it and/or
314+// modify it under the terms of the GNU Lesser General Public
315+// License as published by the Free Software Foundation; either
316+// version 2.1 of the License, or (at your option) any later version.
317+
318+// This library is distributed in the hope that it will be useful,
319+// but WITHOUT ANY WARRANTY; without even the implied warranty of
320+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
321+// Lesser General Public License for more details.
322+
323+// You should have received a copy of the GNU Lesser General Public
324+// License along with this library; if not, write to the Free Software
325+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
326+
327+// ==UserScript==
328+// @run-at document-start
329+// ==/UserScript==
330+
331+oxide.addMessageHandler("evalcode", function(msg) {
332+ var code = msg.args.code;
333+ if (msg.args.wrap) {
334+ code = "(function() {" + code + "})()";
335+ }
336+ eval(code);
337+});
338
339=== added file 'tests/unit/test_qml/tst_api_contenthub.qml'
340--- tests/unit/test_qml/tst_api_contenthub.qml 1970-01-01 00:00:00 +0000
341+++ tests/unit/test_qml/tst_api_contenthub.qml 2015-04-17 18:58:01 +0000
342@@ -0,0 +1,198 @@
343+/*
344+ * Copyright 2015 Canonical Ltd.
345+ *
346+ * This file is part of unity-webapps-qml.
347+ *
348+ * unity-webapps-qml is free software; you can redistribute it and/or modify
349+ * it under the terms of the GNU General Public License as published by
350+ * the Free Software Foundation; version 3.
351+ *
352+ * unity-webapps-qml is distributed in the hope that it will be useful,
353+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
354+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
355+ * GNU General Public License for more details.
356+ *
357+ * You should have received a copy of the GNU General Public License
358+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
359+ */
360+
361+import QtQuick 2.0
362+import QtTest 1.0
363+import Ubuntu.Web 0.2
364+import com.canonical.Oxide 1.0 as Oxide
365+import Ubuntu.UnityWebApps 0.1
366+
367+
368+TestCase {
369+ id: testcase
370+
371+ name: "ContentHubApiTest"
372+
373+ signal messageReceived()
374+
375+ SignalSpy {
376+ id: spyMessageReceived
377+ target: testcase
378+ signalName: "messageReceived"
379+ }
380+
381+ function setup() {
382+ callbacks = []
383+ objects = {}
384+ lastReceivedMethod = ""
385+ webview.url = "empty.html"
386+ spyMessageReceived.clear()
387+ }
388+
389+ property var callbacks: []
390+ property var objects: null
391+ property var backends: getContentHubBackend()
392+ property string lastReceivedMethod
393+
394+ function serializeContentTransferObject(id, content, selection, handlerFuncs) {
395+ if (!objects) {
396+ objects = {}
397+ }
398+
399+ objects[id] = {
400+ content: content,
401+ selection: selection,
402+ handlerFuncs: handlerFuncs
403+ };
404+ return {
405+ type: 'object-proxy',
406+ apiid: 'ContentHub',
407+ objecttype: 'ContentTransfer',
408+ objectid: id,
409+
410+ content: {
411+ store: "store",
412+ state: "state",
413+ selectionType: selection,
414+ contentType: content,
415+ direction: "direction"
416+ }
417+ }
418+ }
419+
420+ function getContentHubBackend() {
421+ return {
422+ ContentHub: {
423+ onShareRequested: function(callback) {
424+ callbacks.push(callback)
425+ lastReceivedMethod = 'onShareRequested'
426+ testcase.messageReceived()
427+ },
428+ dispatchToObject: function(infos) {
429+ var args = infos.args;
430+ var callback = infos.callback;
431+ var method_name = infos.method_name;
432+
433+ verify(objects != null && objects[infos.objectid] != null)
434+
435+ verify(objects[infos.objectid].handlerFuncs[method_name] != null)
436+ testcase.messageReceived()
437+
438+ var r
439+ try {
440+ r = objects[infos.objectid].handlerFuncs[method_name].apply(objects[infos.objectid], args)
441+ } catch(e) {
442+ verify(0 && "Exception " + e.toString())
443+ }
444+
445+ if (callback) {
446+ verify (typeof(callback) === 'function')
447+ callback(r)
448+ }
449+ }
450+ }
451+ }
452+ }
453+
454+ function test_call_shareRequested() {
455+ setup();
456+
457+ webview.url = "tst_api_contenthub.html"
458+
459+ spyMessageReceived.wait()
460+ compare(spyMessageReceived.count, 1, "Should have had 1 apiCallDispatched signal");
461+ compare(lastReceivedMethod, 'onShareRequested', "Should have had 2 apiCallDispatched signal");
462+ compare(callbacks.length, 1, "Should have had 1 callback object");
463+ }
464+
465+ function test_invoke_shareRequestedCallback() {
466+ setup();
467+
468+ var transferObject = { contentType: function() { return "Pictures"; } }
469+
470+ webview.url = "tst_api_contenthub.html"
471+
472+ spyMessageReceived.wait()
473+ compare(spyMessageReceived.count, 1, "Should have had 2 apiCallDispatched signal");
474+ compare(lastReceivedMethod, 'onShareRequested', "Should have had 2 apiCallDispatched signal");
475+ compare(callbacks.length, 1, "Should have had 1 callback object");
476+
477+ evaluateCode("document.addEventListener('onsharerequest', function(e) { \
478+oxide.sendMessage('share-request-received', { type: e.detail.type }); \
479+})")
480+
481+ evaluateCode("document.addEventListener('received-object-value', function(e) { \
482+oxide.sendMessage('share-request-received', { type: e.detail.type }); \
483+})")
484+
485+ callbacks[0](
486+ serializeContentTransferObject(
487+ "1", "", "", transferObject))
488+
489+ spyMessageReceived.wait()
490+ compare(spyMessageReceived.count, 2, "Should have had 1 messageReceived signal");
491+ }
492+
493+ UnityWebApps {
494+ id: webapps
495+ bindee: webview
496+ injectExtraUbuntuApis: true
497+ injectExtraContentShareCapabilities: true
498+ customBackendProxies: backends
499+ }
500+
501+ function evaluateCode(code, wrap) {
502+ webview.rootFrame.sendMessageNoReply(
503+ "oxide://test-msg-handler/",
504+ "evalcode",
505+ { code: code,
506+ wrap: wrap === undefined ? false : wrap });
507+ }
508+
509+ WebView {
510+ id: webview
511+
512+ anchors.fill: parent
513+
514+ messageHandlers: [
515+ Oxide.ScriptMessageHandler {
516+ msgId: "share-request-received"
517+ contexts: [ "oxide://test-msg-handler/" ]
518+ callback: function(msg) {
519+ testcase.lastReceivedMethod = msg.args;
520+ testcase.messageReceived()
521+ }
522+ }
523+ ]
524+
525+ context: WebContext {
526+ userScripts: [
527+ Oxide.UserScript {
528+ context: "oxide://test-msg-handler/"
529+ url: Qt.resolvedUrl("tst_api_contenthub.js")
530+ incognitoEnabled: true
531+ matchAllFrames: true
532+ }
533+ ]
534+ }
535+
536+ function getUnityWebappsProxies() {
537+ return UnityWebAppsUtils.makeProxiesForWebViewBindee(webview);
538+ }
539+ }
540+}
541
542=== added file 'tests/unit/test_qml/tst_api_launchEmbeddedUI.html'
543--- tests/unit/test_qml/tst_api_launchEmbeddedUI.html 1970-01-01 00:00:00 +0000
544+++ tests/unit/test_qml/tst_api_launchEmbeddedUI.html 2015-04-17 18:58:01 +0000
545@@ -0,0 +1,21 @@
546+<html>
547+
548+<head>
549+<script>
550+
551+function callback() {}
552+
553+window.onload = function() {
554+ document.addEventListener('launchEmbeddedUI', function(e) {
555+ var api = external.getUnityObject('1.0');
556+ api.launchEmbeddedUI('embeddedUI', callback, { fileToShare: "me", p: "you", q: "them" })
557+ })
558+}
559+
560+</script>
561+</head>
562+
563+<body>
564+</body>
565+
566+</html>
567
568=== added file 'tests/unit/test_qml/tst_api_launchEmbeddedUI.js'
569--- tests/unit/test_qml/tst_api_launchEmbeddedUI.js 1970-01-01 00:00:00 +0000
570+++ tests/unit/test_qml/tst_api_launchEmbeddedUI.js 2015-04-17 18:58:01 +0000
571@@ -0,0 +1,28 @@
572+// vim:expandtab:shiftwidth=2:tabstop=2:
573+// Copyright (C) 2015 Canonical Ltd.
574+
575+// This library is free software; you can redistribute it and/or
576+// modify it under the terms of the GNU Lesser General Public
577+// License as published by the Free Software Foundation; either
578+// version 2.1 of the License, or (at your option) any later version.
579+
580+// This library is distributed in the hope that it will be useful,
581+// but WITHOUT ANY WARRANTY; without even the implied warranty of
582+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
583+// Lesser General Public License for more details.
584+
585+// You should have received a copy of the GNU Lesser General Public
586+// License along with this library; if not, write to the Free Software
587+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
588+
589+// ==UserScript==
590+// @run-at document-start
591+// ==/UserScript==
592+
593+oxide.addMessageHandler("evalcode", function(msg) {
594+ var code = msg.args.code;
595+ if (msg.args.wrap) {
596+ code = "(function() {" + code + "})()";
597+ }
598+ eval(code);
599+});
600
601=== added file 'tests/unit/test_qml/tst_api_launchEmbeddedUI.qml'
602--- tests/unit/test_qml/tst_api_launchEmbeddedUI.qml 1970-01-01 00:00:00 +0000
603+++ tests/unit/test_qml/tst_api_launchEmbeddedUI.qml 2015-04-17 18:58:01 +0000
604@@ -0,0 +1,91 @@
605+/*
606+ * Copyright 2015 Canonical Ltd.
607+ *
608+ * This file is part of unity-webapps-qml.
609+ *
610+ * unity-webapps-qml is free software; you can redistribute it and/or modify
611+ * it under the terms of the GNU General Public License as published by
612+ * the Free Software Foundation; version 3.
613+ *
614+ * unity-webapps-qml is distributed in the hope that it will be useful,
615+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
616+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
617+ * GNU General Public License for more details.
618+ *
619+ * You should have received a copy of the GNU General Public License
620+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
621+ */
622+
623+import QtQuick 2.0
624+import QtTest 1.0
625+import Ubuntu.Web 0.2
626+import com.canonical.Oxide 1.0 as Oxide
627+import Ubuntu.UnityWebApps 0.1
628+
629+
630+TestCase {
631+ id: testcase
632+
633+ name: "LaunchEmbeddedUIApiTest"
634+
635+ SignalSpy {
636+ id: spy
637+ target: webview
638+ signalName: "visibleChanged"
639+ }
640+
641+ function setup() {
642+ spy.clear()
643+ }
644+
645+ function test_invoke_shareRequestedCallback() {
646+ setup();
647+
648+ webview.url = "tst_api_launchEmbeddedUI.html"
649+
650+ evaluateCode("var e = new CustomEvent('launchEmbeddedUI', { bubbles: true }); document.dispatchEvent(e);")
651+
652+// spy.wait()
653+// compare(spy.count, 1, "Should have had 1 messageReceived signal");
654+ }
655+
656+ UnityWebApps {
657+ id: webapps
658+ bindee: webview
659+ injectExtraUbuntuApis: true
660+ injectExtraContentShareCapabilities: true
661+ }
662+
663+ function evaluateCode(code, wrap) {
664+ webview.rootFrame.sendMessageNoReply(
665+ "oxide://test-ui/",
666+ "evalcode",
667+ { code: code,
668+ wrap: wrap === undefined ? false : wrap });
669+ }
670+ visible: true
671+
672+ WebView {
673+ id: webview
674+
675+ width: 200
676+ height: 200
677+
678+ visible: true
679+
680+ context: WebContext {
681+ userScripts: [
682+ Oxide.UserScript {
683+ context: "oxide://test-ui/"
684+ url: Qt.resolvedUrl("tst_api_launchEmbeddedUI.js")
685+ incognitoEnabled: true
686+ matchAllFrames: true
687+ }
688+ ]
689+ }
690+
691+ function getUnityWebappsProxies() {
692+ return UnityWebAppsUtils.makeProxiesForWebViewBindee(webview);
693+ }
694+ }
695+}
696
697=== modified file 'tests/unit/test_qml/tst_cleanup.qml'
698--- tests/unit/test_qml/tst_cleanup.qml 2014-04-14 20:57:17 +0000
699+++ tests/unit/test_qml/tst_cleanup.qml 2015-04-17 18:58:01 +0000
700@@ -1,3 +1,21 @@
701+/*
702+ * Copyright 2013 Canonical Ltd.
703+ *
704+ * This file is part of unity-webapps-qml.
705+ *
706+ * unity-webapps-qml is free software; you can redistribute it and/or modify
707+ * it under the terms of the GNU General Public License as published by
708+ * the Free Software Foundation; version 3.
709+ *
710+ * unity-webapps-qml is distributed in the hope that it will be useful,
711+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
712+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
713+ * GNU General Public License for more details.
714+ *
715+ * You should have received a copy of the GNU General Public License
716+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
717+ */
718+
719 import QtQuick 2.0
720 import QtTest 1.0
721 import Ubuntu.UnityWebApps 0.1
722
723=== modified file 'tests/unit/test_qml/tst_dispatch.qml'
724--- tests/unit/test_qml/tst_dispatch.qml 2014-07-11 17:13:18 +0000
725+++ tests/unit/test_qml/tst_dispatch.qml 2015-04-17 18:58:01 +0000
726@@ -1,3 +1,21 @@
727+/*
728+ * Copyright 2013 Canonical Ltd.
729+ *
730+ * This file is part of unity-webapps-qml.
731+ *
732+ * unity-webapps-qml is free software; you can redistribute it and/or modify
733+ * it under the terms of the GNU General Public License as published by
734+ * the Free Software Foundation; version 3.
735+ *
736+ * unity-webapps-qml is distributed in the hope that it will be useful,
737+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
738+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
739+ * GNU General Public License for more details.
740+ *
741+ * You should have received a copy of the GNU General Public License
742+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
743+ */
744+
745 import QtQuick 2.0
746 import QtTest 1.0
747 import Ubuntu.UnityWebApps 0.1
748@@ -112,6 +130,7 @@
749 id: webapps
750 name: ""
751 bindee: null
752+ injectExtraUbuntuApis: true
753 }
754
755 // 'mocks' the 'bindee'
756
757=== modified file 'tests/unit/test_qml/tst_init.qml'
758--- tests/unit/test_qml/tst_init.qml 2014-04-14 20:57:17 +0000
759+++ tests/unit/test_qml/tst_init.qml 2015-04-17 18:58:01 +0000
760@@ -1,3 +1,21 @@
761+/*
762+ * Copyright 2013 Canonical Ltd.
763+ *
764+ * This file is part of unity-webapps-qml.
765+ *
766+ * unity-webapps-qml is free software; you can redistribute it and/or modify
767+ * it under the terms of the GNU General Public License as published by
768+ * the Free Software Foundation; version 3.
769+ *
770+ * unity-webapps-qml is distributed in the hope that it will be useful,
771+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
772+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
773+ * GNU General Public License for more details.
774+ *
775+ * You should have received a copy of the GNU General Public License
776+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
777+ */
778+
779 import QtQuick 2.0
780 import QtTest 1.0
781 import Ubuntu.UnityWebApps 0.1
782@@ -37,19 +55,6 @@
783 compare(spy.count, 1, "Script has been injected");
784 }
785
786- function test_initAndMessageHandlerAdded() {
787- setup();
788-
789- spy.clear();
790- spy.target = mockedWebView;
791- spy.signalName = "loadingStartedConnected";
792-
793- webapps.name = "test_initAndMessageHandlerAdded";
794- webapps.bindee = mockedWebView;
795-
796- compare(spy.count, 1, "WebApp message connected on load started");
797- }
798-
799 function test_initWithNoName() {
800 setup();
801

Subscribers

People subscribed via source and target branches

to all changes: