Merge lp:~abreu-alexandre/unity-webapps-qml/rtm-tools-api into lp:unity-webapps-qml/rtm-14.09

Proposed by Alexandre Abreu
Status: Merged
Approved by: David Barth
Approved revision: 145
Merged at revision: 142
Proposed branch: lp:~abreu-alexandre/unity-webapps-qml/rtm-tools-api
Merge into: lp:unity-webapps-qml/rtm-14.09
Diff against target: 1438 lines (+700/-363)
20 files modified
src/Ubuntu/UnityWebApps/UnityWebApps.js (+2/-2)
src/Ubuntu/UnityWebApps/UnityWebApps.pro (+5/-2)
src/Ubuntu/UnityWebApps/UnityWebApps.qml (+5/-0)
src/Ubuntu/UnityWebApps/bindings/tools/backend/tools.js (+95/-0)
src/Ubuntu/UnityWebApps/bindings/tools/client/tools.js (+106/-0)
src/Ubuntu/UnityWebApps/plugin/plugin.pro (+2/-0)
src/Ubuntu/UnityWebApps/plugin/qml-plugin.cpp (+13/-2)
src/Ubuntu/UnityWebApps/plugin/tools-api.cpp (+120/-0)
src/Ubuntu/UnityWebApps/plugin/tools-api.h (+51/-0)
src/Ubuntu/UnityWebApps/unity-webapps-api.js.in (+2/-0)
tests/autopilot/html/test_webapps_api_injected.html (+3/-0)
tests/autopilot/setup.py (+6/-7)
tests/autopilot/unity_webapps_qml/tests/__init__.py (+43/-22)
tests/autopilot/unity_webapps_qml/tests/test_api_tools.py (+116/-0)
tests/autopilot/unity_webapps_qml/tests/test_callbackDispatch.py (+25/-13)
tests/autopilot/unity_webapps_qml/tests/test_hud.py (+0/-81)
tests/autopilot/unity_webapps_qml/tests/test_injectedOnWebapp.py (+55/-23)
tests/autopilot/unity_webapps_qml/tests/test_installedWebapp.py (+51/-17)
tests/autopilot/unity_webapps_qml/tests/test_launcher.py (+0/-83)
tests/autopilot/unity_webapps_qml/tests/test_mediaplayer.py (+0/-111)
To merge this branch: bzr merge lp:~abreu-alexandre/unity-webapps-qml/rtm-tools-api
Reviewer Review Type Date Requested Status
WebApps Pending
Review via email: mp+253530@code.launchpad.net

Commit message

Backport RTM changed to add a tools api

Description of the change

Backport RTM changed to add a tools api

To post a comment you must log in.
144. By Alexandre Abreu

tweaks

145. By Alexandre Abreu

Backport tests

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.js'
--- src/Ubuntu/UnityWebApps/UnityWebApps.js 2015-01-16 16:12:44 +0000
+++ src/Ubuntu/UnityWebApps/UnityWebApps.js 2015-03-27 19:32:46 +0000
@@ -115,8 +115,6 @@
115 return;115 return;
116 }116 }
117117
118 this._log ('WebApps API message received: ' + json.stringify(msg));
119
120 var self = this;118 var self = this;
121 var args = json.parse(msg.args);119 var args = json.parse(msg.args);
122 args = args.map (function (arg) {120 args = args.map (function (arg) {
@@ -154,6 +152,8 @@
154 return;152 return;
155 }153 }
156154
155 this._log ('WebApps API message being dispatch: ' + apiCallName);
156
157 this._dispatchApiCall (message.name, params);157 this._dispatchApiCall (message.name, params);
158158
159 } else if (target === UnityWebAppsUtils.UBUNTU_WEBAPPS_BINDING_OBJECT_METHOD_CALL_MESSAGE) {159 } else if (target === UnityWebAppsUtils.UBUNTU_WEBAPPS_BINDING_OBJECT_METHOD_CALL_MESSAGE) {
160160
=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.pro'
--- src/Ubuntu/UnityWebApps/UnityWebApps.pro 2015-03-06 15:15:15 +0000
+++ src/Ubuntu/UnityWebApps/UnityWebApps.pro 2015-03-27 19:32:46 +0000
@@ -70,6 +70,9 @@
70download_api_binding_backend_js_files.path = $$installPath/bindings/download-manager/backend/70download_api_binding_backend_js_files.path = $$installPath/bindings/download-manager/backend/
71download_api_binding_backend_js_files.files = ./bindings/download-manager/backend/download-api.js71download_api_binding_backend_js_files.files = ./bindings/download-manager/backend/download-api.js
7272
73tools_api_binding_backend_js_files.path = $$installPath/bindings/tools/backend/
74tools_api_binding_backend_js_files.files = ./bindings/tools/backend/tools.js
75
73INSTALLS += qmldir_file \76INSTALLS += qmldir_file \
74 qml_files \77 qml_files \
75 js_files \78 js_files \
@@ -77,5 +80,5 @@
77 alarm_binding_backend_js_files \80 alarm_binding_backend_js_files \
78 online_accounts_binding_backend_js_files \81 online_accounts_binding_backend_js_files \
79 runtime_api_binding_backend_js_files \82 runtime_api_binding_backend_js_files \
80 download_api_binding_backend_js_files83 download_api_binding_backend_js_files \
8184 tools_api_binding_backend_js_files
8285
=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.qml'
--- src/Ubuntu/UnityWebApps/UnityWebApps.qml 2015-03-06 15:15:15 +0000
+++ src/Ubuntu/UnityWebApps/UnityWebApps.qml 2015-03-27 19:32:46 +0000
@@ -28,6 +28,7 @@
28import "./bindings/online-accounts/backend/online-accounts.js" as OnlineAccountsApiBackend28import "./bindings/online-accounts/backend/online-accounts.js" as OnlineAccountsApiBackend
29import "./bindings/online-accounts/backend/online-accounts-client.js" as OnlineAccountsClientApiBackend29import "./bindings/online-accounts/backend/online-accounts-client.js" as OnlineAccountsClientApiBackend
30import "./bindings/download-manager/backend/download-api.js" as DownloadApiBackend30import "./bindings/download-manager/backend/download-api.js" as DownloadApiBackend
31import "./bindings/tools/backend/tools.js" as ToolsApiBackend
3132
32/*!33/*!
33 \qmltype UnityWebApps34 \qmltype UnityWebApps
@@ -493,6 +494,8 @@
493 if (settings.injectExtraContentShareCapabilities) {494 if (settings.injectExtraContentShareCapabilities) {
494 policy.add("launchEmbeddedUI");495 policy.add("launchEmbeddedUI");
495 policy.add("ContentHub.onShareRequested");496 policy.add("ContentHub.onShareRequested");
497 policy.add("ToolsApi.getHmacHash");
498 policy.add("ToolsApi.sendHttpRequest");
496 }499 }
497 return policy;500 return policy;
498 }501 }
@@ -786,6 +789,8 @@
786 return DownloadApiBackend.createDownloadApi(UnityBackends.backendDelegate)789 return DownloadApiBackend.createDownloadApi(UnityBackends.backendDelegate)
787 }),790 }),
788791
792 ToolsApi: ToolsApiBackend.createToolsApi(UnityBackends.backendDelegate),
793
789 Launcher: {794 Launcher: {
790 setCount: function (count) {795 setCount: function (count) {
791 if (!initialized)796 if (!initialized)
792797
=== added directory 'src/Ubuntu/UnityWebApps/bindings/tools'
=== added directory 'src/Ubuntu/UnityWebApps/bindings/tools/backend'
=== added file 'src/Ubuntu/UnityWebApps/bindings/tools/backend/tools.js'
--- src/Ubuntu/UnityWebApps/bindings/tools/backend/tools.js 1970-01-01 00:00:00 +0000
+++ src/Ubuntu/UnityWebApps/bindings/tools/backend/tools.js 2015-03-27 19:32:46 +0000
@@ -0,0 +1,95 @@
1/*
2 * Copyright 20145 Canonical Ltd.
3 *
4 * This file is part of unity-webapps-qml.
5 *
6 * unity-webapps-qml 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.
9 *
10 * unity-webapps-qml 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.
14 *
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/>.
17 */
18
19.import Ubuntu.UnityWebApps 0.2 as UnityWebAppsBridge
20
21
22/**
23 *
24 * Tools API backend binding
25 *
26 */
27function createToolsApi(backendDelegate) {
28 var PLUGIN_URI = 'Ubuntu.UnityWebApps';
29 var VERSION = 0.2;
30
31 var toolsApiInstance = UnityWebAppsBridge.ToolsApi;
32
33 function isValidAlgorithm(algorithm) {
34 var algos = ["MD5", "SHA1", "SHA256", "SHA512"]
35 return algos.some(function(e) { return e === algorithm; })
36 };
37
38 function stringToCryptoAlgorithm(algorithm) {
39 var assoc = {
40 "MD5": toolsApiInstance.MD5
41 , "SHA1": toolsApiInstance.SHA1
42 , "SHA256": toolsApiInstance.SHA256
43 , "SHA512": toolsApiInstance.SHA512
44 };
45 return assoc[algorithm]
46 };
47
48 return {
49 getHmacHash: function(message, algorithm, key, callback) {
50 if ( ! isValidAlgorithm(algorithm)) {
51 callback({errorMsg: "Invalid algorithm",
52 result: null});
53 return;
54 }
55 callback({errorMsg: "",
56 result: toolsApiInstance.getHmacHash(
57 message, stringToCryptoAlgorithm(algorithm), key)});
58 },
59 sendHttpRequest: function(url, location, request, payload, callback) {
60 if ( ! toolsApiInstance.areCompatibleCorsUrl(url, location)) {
61 console.error('sendHttpRequest: incompatible CORS request urls')
62 return;
63 }
64
65 var xmlrequest = new XMLHttpRequest();
66
67 var verb = payload && payload.length !== 0
68 ? "POST" : "GET"
69
70 xmlrequest.open(verb, url, true);
71
72 xmlrequest.onreadystatechange = function() {
73 if (xmlrequest.readyState === XMLHttpRequest.DONE) {
74 callback({
75 errorMsg: xmlrequest.statusText,
76 success: xmlrequest.status == 200,
77 response: xmlrequest.responseText
78 });
79 }
80 };
81
82 for (var header in request.headers) {
83 if (request.headers.hasOwnProperty(header)) {
84 xmlrequest.setRequestHeader(header, request.headers[header])
85 }
86 }
87
88 xmlrequest.setRequestHeader(
89 "Content-Length",
90 String(payload.length));
91
92 xmlrequest.send(payload);
93 }
94 };
95}
096
=== added directory 'src/Ubuntu/UnityWebApps/bindings/tools/client'
=== added file 'src/Ubuntu/UnityWebApps/bindings/tools/client/tools.js'
--- src/Ubuntu/UnityWebApps/bindings/tools/client/tools.js 1970-01-01 00:00:00 +0000
+++ src/Ubuntu/UnityWebApps/bindings/tools/client/tools.js 2015-03-27 19:32:46 +0000
@@ -0,0 +1,106 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This file is part of unity-webapps-qml.
5 *
6 * unity-webapps-qml 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.
9 *
10 * unity-webapps-qml 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.
14 *
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/>.
17 */
18
19
20/**
21 * Tools gives access to various helpers/tools.
22
23 * @module Tools
24 */
25function createToolsApi(backendBridge) {
26 var PLUGIN_URI = 'Tools';
27
28/**
29 * The Tools object
30
31 * @class Tools
32 * @constructor
33 * @example
34
35 var api = external.getUnityObject('1.0');
36 api.Tools.getHmacHash(hmac, algorithm, key, function(result) {
37 console.log('Application name: ' + result);
38 });
39 */
40 return {
41 /**
42 Enumeration of the available types of CryptographicAlgorithm.
43
44 Values:
45
46 MD5: MD5 hash function
47
48 SHA1: SHA1 hash function
49
50 SHA256: SHA-256 hash function
51
52 SHA512: SHA-512 hash function
53
54 @static
55 @property CryptographicAlgorithm {Object}
56
57 @example
58
59 var api = external.getUnityObject('1.0');
60 var algorithm = api.Tools.CryptographicAlgorithm;
61 // use algorithm.MD5, algorithm.SHA-1, ...
62 */
63 CryptographicAlgorithm: {
64 MD5: "MD5",
65
66 SHA1: "SHA1",
67
68 SHA256: "SHA256",
69
70 SHA512: "SHA512"
71 },
72
73 /**
74 * Generates a .
75 *
76 * @method getHmacHash
77 * @param message {Function (Application)}
78 * @param algorithm {CryptographicAlgorithm}
79 * @param key {Function (Application)}
80 * @param callback {Function (Application)}
81 */
82 getHmacHash: function(message, algorithm, key, callback) {
83 if (! callback || typeof(callback) !== 'function') {
84 return;
85 }
86 backendBridge.call('ToolsApi.getHmacHash'
87 , [message, algorithm, key]
88 , callback);
89 },
90
91 /**
92 * @internal
93 */
94 __private__: {
95 sendHttpRequest: function(url, request, payload, callback) {
96 if (! callback || typeof(callback) !== 'function') {
97 return;
98 }
99 var location = window && window.location ? window.location.href : ""
100 backendBridge.call('ToolsApi.sendHttpRequest'
101 , [url, location, request, payload]
102 , callback);
103 }
104 }
105 };
106};
0107
=== modified file 'src/Ubuntu/UnityWebApps/plugin/plugin.pro'
--- src/Ubuntu/UnityWebApps/plugin/plugin.pro 2014-07-07 18:59:19 +0000
+++ src/Ubuntu/UnityWebApps/plugin/plugin.pro 2015-03-27 19:32:46 +0000
@@ -41,6 +41,7 @@
41 callback.cpp \41 callback.cpp \
42 abstract-item-model-adaptor.cpp \42 abstract-item-model-adaptor.cpp \
43 application-api.cpp \43 application-api.cpp \
44 tools-api.cpp \
44 application-signal-to-qt-bridge.cpp45 application-signal-to-qt-bridge.cpp
4546
46HEADERS += \47HEADERS += \
@@ -59,6 +60,7 @@
59 callback.h \60 callback.h \
60 abstract-item-model-adaptor.h \61 abstract-item-model-adaptor.h \
61 application-api.h \62 application-api.h \
63 tools-api.h \
62 application-signal-to-qt-bridge.h64 application-signal-to-qt-bridge.h
6365
64DEFINES += \66DEFINES += \
6567
=== modified file 'src/Ubuntu/UnityWebApps/plugin/qml-plugin.cpp'
--- src/Ubuntu/UnityWebApps/plugin/qml-plugin.cpp 2014-07-07 18:59:19 +0000
+++ src/Ubuntu/UnityWebApps/plugin/qml-plugin.cpp 2015-03-27 19:32:46 +0000
@@ -30,6 +30,7 @@
30#include "unity-webapps-app-infos.h"30#include "unity-webapps-app-infos.h"
3131
32#include "application-api.h"32#include "application-api.h"
33#include "tools-api.h"
33#include "abstract-item-model-adaptor.h"34#include "abstract-item-model-adaptor.h"
34#include "callback.h"35#include "callback.h"
3536
@@ -43,6 +44,14 @@
43 return new ApplicationApi();44 return new ApplicationApi();
44}45}
4546
47static QObject *createToolsApi(QQmlEngine *engine, QJSEngine *scriptEngine)
48{
49 Q_UNUSED(engine);
50 Q_UNUSED(scriptEngine);
51
52 return new ToolsApi();
53}
54
46void WebappsQmlPlugin::registerTypes(const char *uri)55void WebappsQmlPlugin::registerTypes(const char *uri)
47{56{
48 // bindings57 // bindings
@@ -60,7 +69,9 @@
60 // TODO bump version69 // TODO bump version
61 qmlRegisterType<AbstractItemModelAdaptor> (uri, 0, 1, "AbstractItemModelAdaptor");70 qmlRegisterType<AbstractItemModelAdaptor> (uri, 0, 1, "AbstractItemModelAdaptor");
6271
63 //72 // Application Api entry point
64 qmlRegisterSingletonType<ApplicationApi>(uri, 0, 1, "ApplicationApi", createApplicationApi);73 qmlRegisterSingletonType<ApplicationApi>(uri, 0, 1, "ApplicationApi", createApplicationApi);
74
75 // Tools Api entry point
76 qmlRegisterSingletonType<ToolsApi>(uri, 0, 2, "ToolsApi", createToolsApi);
65}77}
66
6778
=== added file 'src/Ubuntu/UnityWebApps/plugin/tools-api.cpp'
--- src/Ubuntu/UnityWebApps/plugin/tools-api.cpp 1970-01-01 00:00:00 +0000
+++ src/Ubuntu/UnityWebApps/plugin/tools-api.cpp 2015-03-27 19:32:46 +0000
@@ -0,0 +1,120 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This file is part of unity-webapps-qml.
5 *
6 * unity-webapps-qml 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.
9 *
10 * unity-webapps-qml 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.
14 *
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/>.
17 */
18
19#include "tools-api.h"
20
21#include <QCryptographicHash>
22#include <QDebug>
23#include <QMessageAuthenticationCode>
24#include <QUrl>
25#include <QString>
26#include <QFileInfo>
27#include <QFile>
28
29
30namespace {
31
32bool enumToQtCryptoAlgorithm(
33 ToolsApi::CryptographicAlgorithm algorithm,
34 QCryptographicHash::Algorithm & out)
35{
36 switch(algorithm)
37 {
38 case ToolsApi::MD5:
39 out = QCryptographicHash::Md5;
40 return true;
41 break;
42 case ToolsApi::SHA1:
43 out = QCryptographicHash::Sha1;
44 return true;
45 break;
46 case ToolsApi::SHA256:
47 out = QCryptographicHash::Sha256;
48 return true;
49 break;
50 case ToolsApi::SHA512:
51 out = QCryptographicHash::Sha512;
52 return true;
53 break;
54 }
55 return false;
56}
57
58QString getSecondLevelDomain(const QUrl& url)
59{
60 QString tld = url.topLevelDomain();
61 QString host = url.host().left(url.host().length() - tld.length());
62 QStringList s = host.split(".", QString::SkipEmptyParts);
63 return s.isEmpty() ? tld : (s.last() + tld);
64}
65
66}
67
68
69/**
70 * @brief ToolsApi::ToolsApi
71 * @param parent
72 */
73ToolsApi::ToolsApi(QObject *parent) :
74 QObject(parent)
75{}
76
77
78/**
79 * Compute a HMAC for a given message given a cryptographic key
80 * and specific crypto algorithm.
81 *
82 * @brief ToolsApi::getHmacHash
83 * @param message
84 * @param algorithm
85 * @param key
86 * @return HMAC of the message
87 */
88QString ToolsApi::getHmacHash(
89 const QString& message,
90 ToolsApi::CryptographicAlgorithm algorithm,
91 const QString& key) const
92{
93 QCryptographicHash::Algorithm
94 method = QCryptographicHash::Md5;
95 if ( ! enumToQtCryptoAlgorithm(algorithm, method))
96 {
97 qCritical() << "Invalid HMAC method algorithm";
98 return QString();
99 }
100 QMessageAuthenticationCode
101 code(method, key.toUtf8());
102 code.addData(message.toUtf8());
103 return QString::fromUtf8(code.result().toBase64());
104}
105
106
107/**
108 * @brief ToolsApi::isCompatibleCorsRequest
109 * @param requestUrl
110 * @param locationUrl
111 * @return
112 */
113bool ToolsApi::areCompatibleCorsUrl(
114 const QUrl& url1,
115 const QUrl& url2) const
116{
117 return url1.scheme() == url2.scheme()
118 && url1.topLevelDomain() == url2.topLevelDomain()
119 && getSecondLevelDomain(url1) == getSecondLevelDomain(url2);
120}
0121
=== added file 'src/Ubuntu/UnityWebApps/plugin/tools-api.h'
--- src/Ubuntu/UnityWebApps/plugin/tools-api.h 1970-01-01 00:00:00 +0000
+++ src/Ubuntu/UnityWebApps/plugin/tools-api.h 2015-03-27 19:32:46 +0000
@@ -0,0 +1,51 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This file is part of unity-webapps-qml.
5 *
6 * unity-webapps-qml 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.
9 *
10 * unity-webapps-qml 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.
14 *
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/>.
17 */
18
19#ifndef UNITY_WEBAPPS_TOOLSAPI_H
20#define UNITY_WEBAPPS_TOOLSAPI_H
21
22#include <QObject>
23
24
25class ToolsApi : public QObject
26{
27 Q_OBJECT
28 Q_ENUMS(CryptographicAlgorithm)
29
30public:
31 explicit ToolsApi(QObject *parent = 0);
32
33 enum CryptographicAlgorithm
34 {
35 MD5,
36 SHA1,
37 SHA256,
38 SHA512
39 };
40
41 Q_INVOKABLE QString getHmacHash(
42 const QString &hmac,
43 CryptographicAlgorithm algorithm,
44 const QString& key) const;
45
46 Q_INVOKABLE bool areCompatibleCorsUrl(
47 const QUrl& url1,
48 const QUrl& url2) const;
49};
50
51#endif // UNITY_WEBAPPS_TOOLSAPI_H
052
=== modified file 'src/Ubuntu/UnityWebApps/unity-webapps-api.js.in'
--- src/Ubuntu/UnityWebApps/unity-webapps-api.js.in 2014-06-04 21:17:00 +0000
+++ src/Ubuntu/UnityWebApps/unity-webapps-api.js.in 2015-03-27 19:32:46 +0000
@@ -35,6 +35,7 @@
35 //@include ./bindings/online-accounts/client/online-accounts.js35 //@include ./bindings/online-accounts/client/online-accounts.js
36 //@include ./bindings/runtime-api/client/runtime-api.js36 //@include ./bindings/runtime-api/client/runtime-api.js
37 //@include ./bindings/download-manager/client/download-api.js37 //@include ./bindings/download-manager/client/download-api.js
38 //@include ./bindings/tools/client/tools.js
38 //@include ./common/js/unity-backend-messaging-proxy.js39 //@include ./common/js/unity-backend-messaging-proxy.js
39 //@include ./common/js/unity-binding-proxy.js40 //@include ./common/js/unity-binding-proxy.js
40 //@include ./common/js/unity-binding-bridge.js41 //@include ./common/js/unity-binding-bridge.js
@@ -290,6 +291,7 @@
290 ContentHub: createContentHubApi(backend),291 ContentHub: createContentHubApi(backend),
291 RuntimeApi: createRuntimeApi(backend),292 RuntimeApi: createRuntimeApi(backend),
292 DownloadApi: createDownloadApi(backend),293 DownloadApi: createDownloadApi(backend),
294 ToolsApi: createToolsApi(backend)
293 };295 };
294296
295 return api;297 return api;
296298
=== modified file 'tests/autopilot/html/test_webapps_api_injected.html'
--- tests/autopilot/html/test_webapps_api_injected.html 2014-04-22 15:40:04 +0000
+++ tests/autopilot/html/test_webapps_api_injected.html 2015-03-27 19:32:46 +0000
@@ -32,6 +32,9 @@
32<div id="content">32<div id="content">
33</div>33</div>
3434
35<div id="results">
36</div>
37
35</body>38</body>
3639
37</html>40</html>
3841
=== modified file 'tests/autopilot/setup.py'
--- tests/autopilot/setup.py 2013-07-09 19:02:23 +0000
+++ tests/autopilot/setup.py 2015-03-27 19:32:46 +0000
@@ -6,15 +6,14 @@
6# under the terms of the GNU General Public License version 3, as published6# under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.7# by the Free Software Foundation.
88
9
10from distutils.core import setup9from distutils.core import setup
11from setuptools import find_packages10from setuptools import find_packages
1211
13setup(12setup(
14 name='unity-webapps-qml',13 name='unity-webapps-qml',
15 version='0.1',14 version='0.1',
16 description='Unity WebApps QML component autopilot tests.',15 description='Unity WebApps QML component autopilot tests.',
17 url='https://launchpad.net/unity-webapps-qml',16 url='https://launchpad.net/unity-webapps-qml',
18 license='GPLv3',17 license='GPLv3',
19 packages=find_packages(),18 packages=find_packages(),
20)19)
2120
=== modified file 'tests/autopilot/unity_webapps_qml/tests/__init__.py'
--- tests/autopilot/unity_webapps_qml/tests/__init__.py 2014-07-14 19:01:17 +0000
+++ tests/autopilot/unity_webapps_qml/tests/__init__.py 2015-03-27 19:32:46 +0000
@@ -9,27 +9,27 @@
99
10import os10import os
11import os.path11import os.path
12import shutil
13import tempfile
14import json12import json
1513
16from testtools.matchers import Contains, Equals, GreaterThan14from testtools.matchers import Equals, GreaterThan
17from autopilot.matchers import Eventually15from autopilot.matchers import Eventually
18from unity_webapps_qml.tests import fake_servers16from unity_webapps_qml.tests import fake_servers
1917
20from unity.emulators.unity import Unity
21
22from unity.tests import UnityTestCase18from unity.tests import UnityTestCase
2319
24LOCAL_QML_LAUNCHER_APP_PATH = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../../../tools/qml-launcher/unity-webapps-qml-launcher')20LOCAL_QML_LAUNCHER_APP_PATH = "%s/%s" % (
21 os.path.dirname(os.path.realpath(__file__)),
22 '../../../../tools/qml-launcher/unity-webapps-qml-launcher')
25INSTALLED_QML_LAUNCHER_APP_PATH = 'unity-webapps-qml-launcher'23INSTALLED_QML_LAUNCHER_APP_PATH = 'unity-webapps-qml-launcher'
2624LOCAL_BROWSER_CONTAINER_PATH = "%s/%s" % (
27# TODO create __init__.py.in25 os.path.dirname(os.path.realpath(__file__)),
28LOCAL_BROWSER_CONTAINER_PATH = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../qml/FullWebViewApp.qml')26 '../../qml/FullWebViewApp.qml')
29INSTALLED_BROWSER_CONTAINER_PATH = '/usr/share/unity-webapps-qml/autopilot-tests/qml/FullWebViewApp.qml'27INSTALLED_BROWSER_CONTAINER_PATH = '/usr/share \
28 /unity-webapps-qml/autopilot-tests/qml/FullWebViewApp.qml'
3029
31BASE_URL = ''30BASE_URL = ''
3231
32
33class UnityWebappsTestCaseBase(UnityTestCase):33class UnityWebappsTestCaseBase(UnityTestCase):
3434
35 def setUp(self):35 def setUp(self):
@@ -59,7 +59,8 @@
59 webapp_homepage="",59 webapp_homepage="",
60 use_oxide=False,60 use_oxide=False,
61 extra_params=[]):61 extra_params=[]):
62 base_params = ['--qml=' + self.get_qml_browser_container_path(),62 base_params = [
63 '--qml=' + self.get_qml_browser_container_path(),
63 '--app-id=' + webapp_name,64 '--app-id=' + webapp_name,
64 '--webappName=' + webapp_name,65 '--webappName=' + webapp_name,
65 '--webappSearchPath=' + webapp_search_path]66 '--webappSearchPath=' + webapp_search_path]
@@ -75,8 +76,10 @@
7576
76 if os.path.exists(LOCAL_QML_LAUNCHER_APP_PATH):77 if os.path.exists(LOCAL_QML_LAUNCHER_APP_PATH):
77 # we are local78 # we are local
78 base_params.append('--import=' + os.path.join (os.path.dirname(os.path.realpath(__file__)),79 base_params.append(
79 '../../../../src'))80 '--import=' + os.path.join(
81 os.path.dirname(os.path.realpath(__file__)),
82 '../../../../src'))
8083
81 base_params += extra_params84 base_params += extra_params
8285
@@ -86,18 +89,25 @@
86 self.assertThat(os.path.exists(html_filepath), Equals(True))89 self.assertThat(os.path.exists(html_filepath), Equals(True))
87 url = self.create_file_url(html_filepath)90 url = self.create_file_url(html_filepath)
8891
89 self.launch_application(self.get_launch_params(url, 'unitywebappsqmllauncher', '', '', False, extra_params))92 self.launch_application(
93 self.get_launch_params(
94 url,
95 'unitywebappsqmllauncher',
96 '',
97 '',
98 False,
99 extra_params))
90 self.assert_url_eventually_loaded(url)100 self.assert_url_eventually_loaded(url)
91101
92 def launch_application(self, args):102 def launch_application(self, args):
93 print 'Launching test with params:', args, "with", self.get_qml_launcher_path()103 self.app = self.launch_test_application(
94104 self.get_qml_launcher_path(),
95 self.app = self.launch_test_application(self.get_qml_launcher_path(),
96 *args,105 *args,
97 app_type='qt')106 app_type='qt')
98107
99 self.webviewContainer = self.get_webviewContainer()108 self.webviewContainer = self.get_webviewContainer()
100 self.watcher = self.webviewContainer.watch_signal('resultUpdated(QString)')109 self.watcher = self.webviewContainer.watch_signal(
110 'resultUpdated(QString)')
101111
102 def pick_app_launcher(self, app_path):112 def pick_app_launcher(self, app_path):
103 # force Qt app introspection:113 # force Qt app introspection:
@@ -123,9 +133,14 @@
123 webview = self.get_webviewContainer()133 webview = self.get_webviewContainer()
124 prev_emissions = self.watcher.num_emissions134 prev_emissions = self.watcher.num_emissions
125 webview.slots.evalInPageUnsafe(expr)135 webview.slots.evalInPageUnsafe(expr)
126 self.assertThat(lambda: self.watcher.num_emissions, Eventually(GreaterThan(prev_emissions)))136 self.assertThat(
127 results = json.loads(webview.get_signal_emissions('resultUpdated(QString)')[-1][0])137 lambda: self.watcher.num_emissions,
128 return results.has_key('result') and results['result'] or None138 Eventually(GreaterThan(prev_emissions)))
139 results = json.loads(
140 webview.get_signal_emissions(
141 'resultUpdated(QString)')[-1][0])
142 return 'result' in results and results['result'] or None
143
129144
130class WebappsTestCaseBaseWithLocalHttpContentBase(UnityWebappsTestCaseBase):145class WebappsTestCaseBaseWithLocalHttpContentBase(UnityWebappsTestCaseBase):
131 def setUp(self):146 def setUp(self):
@@ -136,5 +151,11 @@
136151
137 def launch_with_webapp(self, name, webapp_search_path, use_oxide=False):152 def launch_with_webapp(self, name, webapp_search_path, use_oxide=False):
138 self.use_oxide = use_oxide153 self.use_oxide = use_oxide
139 self.launch_application(self.get_launch_params("", name, webapp_search_path, self.base_url, use_oxide))154 self.launch_application(
155 self.get_launch_params(
156 "",
157 name,
158 webapp_search_path,
159 self.base_url,
160 use_oxide))
140 self.assert_url_eventually_loaded(self.base_url)161 self.assert_url_eventually_loaded(self.base_url)
141162
=== added file 'tests/autopilot/unity_webapps_qml/tests/test_api_tools.py'
--- tests/autopilot/unity_webapps_qml/tests/test_api_tools.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/unity_webapps_qml/tests/test_api_tools.py 2015-03-27 19:32:46 +0000
@@ -0,0 +1,116 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.
7
8from __future__ import absolute_import
9
10import os
11
12from testtools.matchers import Equals, NotEquals, Contains
13from autopilot.matchers import Eventually
14
15from unity_webapps_qml.tests import UnityWebappsTestCaseBase
16
17LOCAL_HTML_TEST_FILE = "%s/%s" % (
18 os.path.dirname(os.path.realpath(__file__)),
19 '../../html/test_webapps_api_injected.html')
20
21INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests\
22 /html/test_webapps_api_injected.html'
23
24
25class UnityWebappsApiToolsTestCaseBase(UnityWebappsTestCaseBase):
26
27 def get_html_test_file(self):
28 if os.path.exists(LOCAL_HTML_TEST_FILE):
29 return os.path.abspath(LOCAL_HTML_TEST_FILE)
30 return INSTALLED_HTML_TEST_FILE
31
32 def setUp(self):
33 super(UnityWebappsApiToolsTestCaseBase, self).setUp()
34 self.launch_with_html_filepath(self.get_html_test_file())
35
36 def test_apiFound(self):
37 self.assertThat(
38 lambda: self.eval_expression_in_page_unsafe(
39 'return window.external.getUnityObject("1.0") != null;'),
40 Eventually(Equals(True)))
41
42 expression = """
43 var api = window.external.getUnityObject("1.0");
44 return api.ToolsApi != null
45 && api.ToolsApi.getHmacHash != null
46 && api.ToolsApi.__private__.sendHttpRequest != null
47 """
48 self.assertThat(
49 lambda: self.eval_expression_in_page_unsafe(expression),
50 Eventually(Equals(True)))
51
52 def test_hmacCall(self):
53 self.assertThat(
54 lambda: self.eval_expression_in_page_unsafe(
55 'return window.external.getUnityObject("1.0") != null;'),
56 Eventually(Equals(True)))
57
58 expression = """
59 var api = window.external.getUnityObject("1.0");
60 api.ToolsApi.getHmacHash(
61 "hi",
62 api.ToolsApi.CryptographicAlgorithm.SHA1,
63 "all",
64 function(hmac) {
65 document.getElementById('results').innerHTML =
66 (hmac.errorMsg && hmac.errorMsg.length !== 0)
67 ? ("FAIL,"+hmac.errorMsg) : ("OK,"+hmac.result);
68 });
69 return true;
70 """
71 self.assertThat(
72 lambda: self.eval_expression_in_page_unsafe(expression),
73 Eventually(Equals(True)))
74
75 expression = """
76 return document.getElementById('results').innerHTML
77 """
78 self.assertThat(
79 lambda: self.eval_expression_in_page_unsafe(expression),
80 Eventually(Contains("OK,")))
81
82 result = self.eval_expression_in_page_unsafe(expression)
83 result = result.strip('OK,')
84 self.assertThat(
85 len(result),
86 NotEquals(0))
87
88 def test_invalidHmacCall(self):
89 self.assertThat(
90 lambda: self.eval_expression_in_page_unsafe(
91 'return window.external.getUnityObject("1.0") != null;'),
92 Eventually(Equals(True)))
93
94 expression = """
95 var api = window.external.getUnityObject("1.0");
96 api.ToolsApi.getHmacHash(
97 "hi",
98 "Invalid",
99 "all",
100 function(hmac) {
101 document.getElementById('results').innerHTML =
102 (hmac.errorMsg && hmac.errorMsg.length !== 0)
103 ? ("FAIL,"+hmac.errorMsg) : ("OK,"+hmac.result);
104 });
105 return true;
106 """
107 self.assertThat(
108 lambda: self.eval_expression_in_page_unsafe(expression),
109 Eventually(Equals(True)))
110
111 expression = """
112 return document.getElementById('results').innerHTML
113 """
114 self.assertThat(
115 lambda: self.eval_expression_in_page_unsafe(expression),
116 Eventually(Contains("FAIL,")))
0117
=== modified file 'tests/autopilot/unity_webapps_qml/tests/test_callbackDispatch.py'
--- tests/autopilot/unity_webapps_qml/tests/test_callbackDispatch.py 2014-07-11 17:13:18 +0000
+++ tests/autopilot/unity_webapps_qml/tests/test_callbackDispatch.py 2015-03-27 19:32:46 +0000
@@ -1,5 +1,5 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2014 Canonical2# Copyright 2014-2015 Canonical
3#3#
4# This program is free software: you can redistribute it and/or modify it4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published5# under the terms of the GNU General Public License version 3, as published
@@ -7,22 +7,34 @@
77
8from __future__ import absolute_import8from __future__ import absolute_import
99
10import time
11import os10import os
1211
13from testtools.matchers import Equals, GreaterThan, NotEquals12from testtools.matchers import Equals
14from autopilot.matchers import Eventually13from autopilot.matchers import Eventually
1514
16from unity_webapps_qml.tests import UnityWebappsTestCaseBase15from unity_webapps_qml.tests import UnityWebappsTestCaseBase
1716
18LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_callback_dispatch.html')17LOCAL_HTML_TEST_FILE = "%s/%s" % (
19INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_callback_dispatch.html'18 os.path.dirname(os.path.realpath(__file__)),
2019 '../../html/test_webapps_callback_dispatch.html')
21LOCAL_JS_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_callback_dispatch_api.js')20INSTALLED_HTML_TEST_FILE = '/usr/share\
22INSTALLED_JS_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_callback_dispatch_api.js'21 /unity-webapps-qml/autopilot-tests\
2322 /html/test_webapps_callback_dispatch.html'
24LOCAL_QML_BACKEND_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../qml/test_webapps_callback_dispatch_api.qml')23
25INSTALLED_QML_BACKEND_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/qml/test_webapps_callback_dispatch_api.qml'24LOCAL_JS_TEST_FILE = "%s/%s" % (
25 os.path.dirname(os.path.realpath(__file__)),
26 '../../html/test_webapps_callback_dispatch_api.js')
27INSTALLED_JS_TEST_FILE = '/usr/share\
28 /unity-webapps-qml/autopilot-tests/html\
29 /test_webapps_callback_dispatch_api.js'
30
31LOCAL_QML_BACKEND_TEST_FILE = "%s/%s" % (
32 os.path.dirname(os.path.realpath(__file__)),
33 '../../qml/test_webapps_callback_dispatch_api.qml')
34INSTALLED_QML_BACKEND_TEST_FILE = '/usr/share\
35 /unity-webapps-qml/autopilot-tests/qml\
36 /test_webapps_callback_dispatch_api.qml'
37
2638
27class WebappsCallbackDispatchTestCaseBase(UnityWebappsTestCaseBase):39class WebappsCallbackDispatchTestCaseBase(UnityWebappsTestCaseBase):
28 def setUp(self):40 def setUp(self):
@@ -55,6 +67,6 @@
55 Eventually(Equals(True)))67 Eventually(Equals(True)))
5668
57 self.assertThat(69 self.assertThat(
58 lambda: self.eval_expression_in_page_unsafe("return document.getElementById('content').innerHTML;"),70 lambda: self.eval_expression_in_page_unsafe(
71 "return document.getElementById('content').innerHTML;"),
59 Eventually(Equals('callback-loop-count-reached')))72 Eventually(Equals('callback-loop-count-reached')))
60
6173
=== removed file 'tests/autopilot/unity_webapps_qml/tests/test_hud.py'
--- tests/autopilot/unity_webapps_qml/tests/test_hud.py 2014-04-22 15:40:04 +0000
+++ tests/autopilot/unity_webapps_qml/tests/test_hud.py 1970-01-01 00:00:00 +0000
@@ -1,81 +0,0 @@
1#!/usr/bin/env python
2# Copyright 2013 Canonical
3#
4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.
7
8import os
9import time
10
11from testtools.matchers import Equals, GreaterThan, NotEquals
12from autopilot.matchers import Eventually
13
14from autopilot import platform
15
16from unity.emulators.icons import HudLauncherIcon
17from unity.emulators import ensure_unity_is_running
18
19from unity_webapps_qml.tests import UnityWebappsTestCaseBase
20
21class UnityWebappsHudTestCase(UnityWebappsTestCaseBase):
22 LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_hud.html')
23 INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_hud.html'
24
25 def get_html_test_file(self):
26 if os.path.exists(self.LOCAL_HTML_TEST_FILE):
27 return os.path.abspath(self.LOCAL_HTML_TEST_FILE)
28 return self.INSTALLED_HTML_TEST_FILE
29
30 def setUp(self):
31 super(UnityWebappsHudTestCase, self).setUp()
32 # On Touch the dbus unity if does is not exposed
33 if platform.model() == 'Desktop':
34 ensure_unity_is_running()
35 self.launch_with_html_filepath(self.get_html_test_file())
36
37 def test_addAction(self):
38 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('actionadded')))
39
40 self.unity.hud.ensure_visible()
41 self.addCleanup(self.unity.hud.ensure_hidden)
42
43 self.keyboard.type("Hello")
44 self.keyboard.press_and_release("Enter")
45
46 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('content').style.display;"), Eventually(Equals('none')))
47
48 def test_clearAction(self):
49 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('actionadded')))
50 expr = """
51 var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'clearAction', 'args': ['Hello']})});
52 document.dispatchEvent (e);
53 return true;
54 """
55 self.eval_expression_in_page_unsafe(expr)
56
57 self.unity.hud.ensure_visible()
58 self.addCleanup(self.unity.hud.ensure_hidden)
59
60 self.keyboard.type("Hello")
61 self.keyboard.press_and_release("Enter")
62 self.assertThat(self.eval_expression_in_page_unsafe("return document.getElementById('content').style.display;"), NotEquals('none'))
63
64 def test_clearActions(self):
65 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('actionadded')))
66 expr = """
67 var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'clearActions', 'args': []})});
68 document.dispatchEvent (e);
69 return true;
70 """
71
72 self.eval_expression_in_page_unsafe(expr)
73
74 actions = ['Hello', 'Another action']
75 for action in actions:
76 self.unity.hud.ensure_visible()
77 self.addCleanup(self.unity.hud.ensure_hidden)
78 self.keyboard.type(action)
79 self.keyboard.press_and_release("Enter")
80
81 self.assertThat(self.eval_expression_in_page_unsafe("return document.getElementById('content').style.display;"), NotEquals('none'))
820
=== modified file 'tests/autopilot/unity_webapps_qml/tests/test_injectedOnWebapp.py'
--- tests/autopilot/unity_webapps_qml/tests/test_injectedOnWebapp.py 2014-04-22 15:40:04 +0000
+++ tests/autopilot/unity_webapps_qml/tests/test_injectedOnWebapp.py 2015-03-27 19:32:46 +0000
@@ -1,5 +1,5 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2013 Canonical2# Copyright 2013-2015 Canonical
3#3#
4# This program is free software: you can redistribute it and/or modify it4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published5# under the terms of the GNU General Public License version 3, as published
@@ -7,51 +7,75 @@
77
8from __future__ import absolute_import8from __future__ import absolute_import
99
10import time
11import os10import os
1211
13from testtools.matchers import Equals, GreaterThan, NotEquals12from testtools.matchers import Equals
14from autopilot.matchers import Eventually13from autopilot.matchers import Eventually
1514
16from unity_webapps_qml.tests import UnityWebappsTestCaseBase15from unity_webapps_qml.tests import UnityWebappsTestCaseBase
1716
17LOCAL_HTML_TEST_FILE = "%s/%s" % (
18 os.path.dirname(os.path.realpath(__file__)),
19 '../../html/test_webapps_api_injected.html')
20INSTALLED_HTML_TEST_FILE = '/usr/share\
21 /unity-webapps-qml/autopilot-tests/html/test_webapps_api_injected.html'
22
23
18class UnityWebappsApiInjectedTestCaseBase(UnityWebappsTestCaseBase):24class UnityWebappsApiInjectedTestCaseBase(UnityWebappsTestCaseBase):
19 LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_api_injected.html')
20
21 INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_api_injected.html'
2225
23 def get_html_test_file(self):26 def get_html_test_file(self):
24 if os.path.exists(self.LOCAL_HTML_TEST_FILE):27 if os.path.exists(LOCAL_HTML_TEST_FILE):
25 return os.path.abspath(self.LOCAL_HTML_TEST_FILE)28 return os.path.abspath(LOCAL_HTML_TEST_FILE)
26 return self.INSTALLED_HTML_TEST_FILE29 return INSTALLED_HTML_TEST_FILE
2730
28 def setUp(self):31 def setUp(self):
29 super(UnityWebappsApiInjectedTestCaseBase, self).setUp()32 super(UnityWebappsApiInjectedTestCaseBase, self).setUp()
30 self.launch_with_html_filepath(self.get_html_test_file())33 self.launch_with_html_filepath(self.get_html_test_file())
3134
32 def test_getUnityObjectFound(self):35 def test_getUnityObjectFound(self):
33 self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null'), Eventually(Equals(True)))36 self.assertThat(
37 lambda: self.eval_expression_in_page_unsafe(
38 'return window.external.getUnityObject("1.0") != null'),
39 Eventually(Equals(True)))
3440
35 def test_actionsApiFound(self):41 def test_actionsApiFound(self):
36 self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))42 self.assertThat(
43 lambda: self.eval_expression_in_page_unsafe(
44 'return window.external.getUnityObject("1.0") != null;'),
45 Eventually(Equals(True)))
3746
38 expression = """47 expression = """
39 var unity = window.external.getUnityObject("1.0");48 var unity = window.external.getUnityObject("1.0");
40 return unity.addAction != null && unity.clearActions != null && unity.clearAction != null;49 return unity.addAction != null &&
50 unity.clearActions != null &&
51 unity.clearAction != null;
41 """52 """
42 self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals(True)))53 self.assertThat(
54 lambda: self.eval_expression_in_page_unsafe(
55 expression),
56 Eventually(Equals(True)))
4357
44 def test_notificationApiFound(self):58 def test_notificationApiFound(self):
45 self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))59 self.assertThat(
60 lambda: self.eval_expression_in_page_unsafe(
61 'return window.external.getUnityObject("1.0") != null;'),
62 Eventually(Equals(True)))
4663
47 expression = """64 expression = """
48 var unity = window.external.getUnityObject("1.0");65 var unity = window.external.getUnityObject("1.0");
49 return unity.Notification != null && unity.Notification.showNotification != null;66 return unity.Notification != null &&
67 unity.Notification.showNotification != null;
50 """68 """
51 self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals(True)))69 self.assertThat(
70 lambda: self.eval_expression_in_page_unsafe(
71 expression),
72 Eventually(Equals(True)))
5273
53 def test_messagingIndicatorApiFound(self):74 def test_messagingIndicatorApiFound(self):
54 self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))75 self.assertThat(
76 lambda: self.eval_expression_in_page_unsafe(
77 'return window.external.getUnityObject("1.0") != null;'),
78 Eventually(Equals(True)))
5579
56 expression = """80 expression = """
57 var unity = window.external.getUnityObject("1.0");81 var unity = window.external.getUnityObject("1.0");
@@ -61,15 +85,23 @@
61 unity.MessagingIndicator.clearIndicators != null &&85 unity.MessagingIndicator.clearIndicators != null &&
62 unity.MessagingIndicator.showIndicator != null;86 unity.MessagingIndicator.showIndicator != null;
63 """87 """
64 self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals(True)))88 self.assertThat(
89 lambda: self.eval_expression_in_page_unsafe(
90 expression),
91 Eventually(Equals(True)))
6592
66 def test_ubuntuReadyEventSent(self):93 def test_ubuntuReadyEventSent(self):
67 self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))94 self.assertThat(
95 lambda: self.eval_expression_in_page_unsafe(
96 'return window.external.getUnityObject("1.0") != null;'),
97 Eventually(Equals(True)))
6898
69 expression = """99 expression = """
70 var api_ready_count = window.localStorage['ubuntu-webapps-api-ready-key'];100 var api_ready_count =
101 window.localStorage['ubuntu-webapps-api-ready-key'];
71 return api_ready_count != null && api_ready_count > 0;102 return api_ready_count != null && api_ready_count > 0;
72 """103 """
73 self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals(True)))104 self.assertThat(
74105 lambda: self.eval_expression_in_page_unsafe(
75106 expression),
107 Eventually(Equals(True)))
76108
=== modified file 'tests/autopilot/unity_webapps_qml/tests/test_installedWebapp.py'
--- tests/autopilot/unity_webapps_qml/tests/test_installedWebapp.py 2014-07-16 20:15:17 +0000
+++ tests/autopilot/unity_webapps_qml/tests/test_installedWebapp.py 2015-03-27 19:32:46 +0000
@@ -1,5 +1,5 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2013 Canonical2# Copyright 2013-2015 Canonical
3#3#
4# This program is free software: you can redistribute it and/or modify it4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published5# under the terms of the GNU General Public License version 3, as published
@@ -7,18 +7,22 @@
77
8from __future__ import absolute_import8from __future__ import absolute_import
99
10import time
11import os10import os
11import unittest
1212
13from testtools.matchers import Equals, GreaterThan, NotEquals13from testtools.matchers import Equals
14from autopilot.matchers import Eventually14from autopilot.matchers import Eventually
1515
16from unity_webapps_qml.tests import WebappsTestCaseBaseWithLocalHttpContentBase16from unity_webapps_qml.tests import WebappsTestCaseBaseWithLocalHttpContentBase
1717
18LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../data')18LOCAL_HTML_TEST_FILE = "%s/%s" % (
19 os.path.dirname(os.path.realpath(__file__)),
20 '../../data')
19INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/data'21INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/data'
2022
21class InstalledWebappsTestCaseBase(WebappsTestCaseBaseWithLocalHttpContentBase):23
24class InstalledWebappsTestCaseBase(
25 WebappsTestCaseBaseWithLocalHttpContentBase):
22 def setUp(self):26 def setUp(self):
23 super(InstalledWebappsTestCaseBase, self).setUp()27 super(InstalledWebappsTestCaseBase, self).setUp()
2428
@@ -30,34 +34,64 @@
30 def test_normalWebappFound(self):34 def test_normalWebappFound(self):
31 self.launch_with_webapp('Normal', self.get_webapp_install_folder())35 self.launch_with_webapp('Normal', self.get_webapp_install_folder())
3236
33 self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))37 self.assertThat(
38 lambda: self.eval_expression_in_page_unsafe(
39 'return window.external.getUnityObject("1.0") != null;'),
40 Eventually(Equals(True)))
3441
35 expression = """42 expression = """
36 var contentElement = document.getElementById('content');43 var contentElement = document.getElementById('content');
37 return contentElement.innerHTML;44 return contentElement.innerHTML;
38 """45 """
39 self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals("WebApp Script Injected")))46 self.assertThat(
47 lambda: self.eval_expression_in_page_unsafe(
48 expression),
49 Eventually(Equals("WebApp Script Injected")))
4050
41 def test_webappWithUAOverrideFound(self):51 def test_webappWithUAOverrideFound(self):
42 self.launch_with_webapp('AlteredUAWebapp', self.get_webapp_install_folder(), True)52 self.launch_with_webapp(
43 self.assertThat(lambda: self.eval_expression_in_page_unsafe('return navigator.userAgent;'), Eventually(Equals("My Override")))53 'AlteredUAWebapp',
54 self.get_webapp_install_folder(),
55 True)
56 self.assertThat(
57 lambda: self.eval_expression_in_page_unsafe(
58 'return navigator.userAgent;'),
59 Eventually(Equals("My Override")))
4460
45 def test_webappFoundWithSpecialWebappPropertiesFile(self):61 def test_webappFoundWithSpecialWebappPropertiesFile(self):
46 self.launch_with_webapp('ExtendedWebappProperties', self.get_webapp_install_folder() + '/all-in-same-folder')62 self.launch_with_webapp(
63 'ExtendedWebappProperties',
64 self.get_webapp_install_folder() + '/all-in-same-folder')
4765
48 self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))66 self.assertThat(
67 lambda: self.eval_expression_in_page_unsafe(
68 'return window.external.getUnityObject("1.0") != null;'),
69 Eventually(Equals(True)))
4970
50 expression = """71 expression = """
51 var contentElement = document.getElementById('content');72 var contentElement = document.getElementById('content');
52 return contentElement.innerHTML;73 return contentElement.innerHTML;
53 """74 """
54 self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals("WebApp Script Injected")))75 self.assertThat(
76 lambda: self.eval_expression_in_page_unsafe(expression),
77 Eventually(Equals("WebApp Script Injected")))
5578
79 @unittest.skip("Demonstrates some flackiness")
56 def test_webappPropertiesFileWithUA(self):80 def test_webappPropertiesFileWithUA(self):
57 self.launch_with_webapp('ExtendedWebappProperties', self.get_webapp_install_folder() + '/all-in-same-folder', True)81 self.launch_with_webapp(
58 self.assertThat(lambda: self.eval_expression_in_page_unsafe('return navigator.userAgent;'), Eventually(Equals("My Override")))82 'ExtendedWebappProperties',
83 self.get_webapp_install_folder() + '/all-in-same-folder',
84 True)
85 self.assertThat(
86 lambda: self.eval_expression_in_page_unsafe(
87 'return navigator.userAgent;'),
88 Eventually(Equals("My Override")))
5989
60 def test_webappPropertiesNameUpdated(self):90 def test_webappPropertiesNameUpdated(self):
61 self.launch_with_webapp('', self.get_webapp_install_folder() + '/all-in-same-folder')91 self.launch_with_webapp(
62 self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True)))92 '',
6393 self.get_webapp_install_folder() + '/all-in-same-folder')
94 self.assertThat(
95 lambda: self.eval_expression_in_page_unsafe(
96 'return window.external.getUnityObject("1.0") != null;'),
97 Eventually(Equals(True)))
6498
=== removed file 'tests/autopilot/unity_webapps_qml/tests/test_launcher.py'
--- tests/autopilot/unity_webapps_qml/tests/test_launcher.py 2013-09-23 19:59:29 +0000
+++ tests/autopilot/unity_webapps_qml/tests/test_launcher.py 1970-01-01 00:00:00 +0000
@@ -1,83 +0,0 @@
1#!/usr/bin/env python
2# Copyright 2013 Canonical
3#
4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.
7
8import os
9import time
10
11from gi.repository import Unity, GObject
12
13from testtools.matchers import Equals, GreaterThan, NotEquals
14from testtools import skipUnless
15
16from autopilot import platform
17from autopilot.matchers import Eventually
18
19from unity.emulators.icons import HudLauncherIcon
20from unity.emulators import ensure_unity_is_running
21
22from unity_webapps_qml.tests import UnityWebappsTestCaseBase
23
24class UnityWebappsLauncherTestCase(UnityWebappsTestCaseBase):
25 LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_launcher.html')
26 INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_launcher.html'
27
28 def get_html_test_file(self):
29 if os.path.exists(self.LOCAL_HTML_TEST_FILE):
30 return os.path.abspath(self.LOCAL_HTML_TEST_FILE)
31 return self.INSTALLED_HTML_TEST_FILE
32
33 def setUp(self):
34 super(UnityWebappsLauncherTestCase, self).setUp()
35 # On Touch the dbus unity if does is not exposed
36 if platform.model() == 'Desktop':
37 ensure_unity_is_running()
38 self.launch_with_html_filepath(self.get_html_test_file())
39
40 @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop")
41 def test_checkCounts(self):
42 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('launcher-updated')))
43
44 launcher_icon = self.unity.launcher.model.get_icon(desktop_id='unitywebappsqmllauncher.desktop')
45 self.assertThat(launcher_icon, NotEquals(None))
46
47 expr = """
48 document.addEventListener('unity-webapps-do-call-response', function(e) {
49 var response = e.detail;
50 document.getElementById('status').innerHTML = '' + e.detail;
51 });
52
53 var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'Launcher.__get', 'with_callback': true, 'args': ['count']})});
54 document.dispatchEvent (e);
55 return true;
56 """
57 self.eval_expression_in_page_unsafe(expr)
58
59 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('42')))
60
61 # self.assertThat(launcher.get_property('progress'), Equals(0.09375))
62
63 @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop")
64 def test_checkProgress(self):
65 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('launcher-updated')))
66
67 launcher_icon = self.unity.launcher.model.get_icon(desktop_id='unitywebappsqmllauncher.desktop')
68 self.assertThat(launcher_icon, NotEquals(None))
69
70 expr = """
71 document.addEventListener('unity-webapps-do-call-response', function(e) {
72 var response = e.detail;
73 document.getElementById('status').innerHTML = '' + e.detail;
74 });
75
76 var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'Launcher.__get', 'with_callback': true, 'args': ['progress']})});
77 document.dispatchEvent (e);
78 return true;
79 """
80 self.eval_expression_in_page_unsafe(expr)
81
82 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('0.09375')))
83
840
=== removed file 'tests/autopilot/unity_webapps_qml/tests/test_mediaplayer.py'
--- tests/autopilot/unity_webapps_qml/tests/test_mediaplayer.py 2013-09-23 19:59:29 +0000
+++ tests/autopilot/unity_webapps_qml/tests/test_mediaplayer.py 1970-01-01 00:00:00 +0000
@@ -1,111 +0,0 @@
1#!/usr/bin/env python
2# Copyright 2013 Canonical
3#
4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.
7
8import os
9import time
10
11from gi.repository import Unity, GObject
12
13from testtools.matchers import Equals, GreaterThan, NotEquals
14from testtools import skipUnless
15
16from autopilot import platform
17from autopilot.matchers import Eventually
18
19from unity.emulators import ensure_unity_is_running
20
21from unity_webapps_qml.tests import UnityWebappsTestCaseBase
22
23
24class UnityWebappsMediaplayerTestCase(UnityWebappsTestCaseBase):
25 LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_mediaplayer.html')
26 INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_mediaplayer.html'
27
28 def get_html_test_file(self):
29 if os.path.exists(self.LOCAL_HTML_TEST_FILE):
30 return os.path.abspath(self.LOCAL_HTML_TEST_FILE)
31 return self.INSTALLED_HTML_TEST_FILE
32
33 def setUp(self):
34 super(UnityWebappsMediaplayerTestCase, self).setUp()
35 # On Touch the dbus unity if does is not exposed
36 if platform.model() == 'Desktop':
37 ensure_unity_is_running()
38 self.launch_with_html_filepath(self.get_html_test_file())
39
40 @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop")
41 def test_checkInitialSetTrack(self):
42 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('mediaplayer-updated')))
43
44 expr = """
45 document.addEventListener('unity-webapps-do-call-response', function(e) {
46 var response = e.detail;
47 document.getElementById('status').innerHTML = '' + e.detail;
48 });
49
50 var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['track']})});
51 document.dispatchEvent (e);
52 return true;
53 """
54 self.eval_expression_in_page_unsafe(expr)
55
56 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('TXlBcnRpc3Q=;TXlUaXRsZQ==;TXlBbGJ1bQ==')))
57
58 @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop")
59 def test_checkInitialSetCanGoNext(self):
60 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('mediaplayer-updated')))
61
62 expr = """
63 document.addEventListener('unity-webapps-do-call-response', function(e) {
64 var response = e.detail;
65 document.getElementById('status').innerHTML = '' + e.detail;
66 });
67
68 var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['can-go-next']})});
69 document.dispatchEvent (e);
70 return true;
71 """
72 self.eval_expression_in_page_unsafe(expr)
73
74 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('true')))
75
76 @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop")
77 def test_checkInitialSetCanGoPrevious(self):
78 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('mediaplayer-updated')))
79
80 expr = """
81 document.addEventListener('unity-webapps-do-call-response', function(e) {
82 var response = e.detail;
83 document.getElementById('status').innerHTML = '' + e.detail;
84 });
85
86 var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['can-go-previous']})});
87 document.dispatchEvent (e);
88 return true;
89 """
90 self.eval_expression_in_page_unsafe(expr)
91
92 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('true')))
93
94 @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop")
95 def test_checkInitialSetCanPlay(self):
96 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('mediaplayer-updated')))
97
98 expr = """
99 document.addEventListener('unity-webapps-do-call-response', function(e) {
100 var response = e.detail;
101 document.getElementById('status').innerHTML = '' + e.detail;
102 });
103
104 var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['can-play']})});
105 document.dispatchEvent (e);
106 return true;
107 """
108 self.eval_expression_in_page_unsafe(expr)
109
110 self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('true')))
111

Subscribers

People subscribed via source and target branches

to all changes: