Merge lp:~abreu-alexandre/unity-webapps-qml/rtm-tools-api into lp:unity-webapps-qml/rtm-14.09
- rtm-tools-api
- Merge into 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 |
Related bugs: |
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
1 | === modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.js' | |||
2 | --- src/Ubuntu/UnityWebApps/UnityWebApps.js 2015-01-16 16:12:44 +0000 | |||
3 | +++ src/Ubuntu/UnityWebApps/UnityWebApps.js 2015-03-27 19:32:46 +0000 | |||
4 | @@ -115,8 +115,6 @@ | |||
5 | 115 | return; | 115 | return; |
6 | 116 | } | 116 | } |
7 | 117 | 117 | ||
8 | 118 | this._log ('WebApps API message received: ' + json.stringify(msg)); | ||
9 | 119 | |||
10 | 120 | var self = this; | 118 | var self = this; |
11 | 121 | var args = json.parse(msg.args); | 119 | var args = json.parse(msg.args); |
12 | 122 | args = args.map (function (arg) { | 120 | args = args.map (function (arg) { |
13 | @@ -154,6 +152,8 @@ | |||
14 | 154 | return; | 152 | return; |
15 | 155 | } | 153 | } |
16 | 156 | 154 | ||
17 | 155 | this._log ('WebApps API message being dispatch: ' + apiCallName); | ||
18 | 156 | |||
19 | 157 | this._dispatchApiCall (message.name, params); | 157 | this._dispatchApiCall (message.name, params); |
20 | 158 | 158 | ||
21 | 159 | } else if (target === UnityWebAppsUtils.UBUNTU_WEBAPPS_BINDING_OBJECT_METHOD_CALL_MESSAGE) { | 159 | } else if (target === UnityWebAppsUtils.UBUNTU_WEBAPPS_BINDING_OBJECT_METHOD_CALL_MESSAGE) { |
22 | 160 | 160 | ||
23 | === modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.pro' | |||
24 | --- src/Ubuntu/UnityWebApps/UnityWebApps.pro 2015-03-06 15:15:15 +0000 | |||
25 | +++ src/Ubuntu/UnityWebApps/UnityWebApps.pro 2015-03-27 19:32:46 +0000 | |||
26 | @@ -70,6 +70,9 @@ | |||
27 | 70 | download_api_binding_backend_js_files.path = $$installPath/bindings/download-manager/backend/ | 70 | download_api_binding_backend_js_files.path = $$installPath/bindings/download-manager/backend/ |
28 | 71 | download_api_binding_backend_js_files.files = ./bindings/download-manager/backend/download-api.js | 71 | download_api_binding_backend_js_files.files = ./bindings/download-manager/backend/download-api.js |
29 | 72 | 72 | ||
30 | 73 | tools_api_binding_backend_js_files.path = $$installPath/bindings/tools/backend/ | ||
31 | 74 | tools_api_binding_backend_js_files.files = ./bindings/tools/backend/tools.js | ||
32 | 75 | |||
33 | 73 | INSTALLS += qmldir_file \ | 76 | INSTALLS += qmldir_file \ |
34 | 74 | qml_files \ | 77 | qml_files \ |
35 | 75 | js_files \ | 78 | js_files \ |
36 | @@ -77,5 +80,5 @@ | |||
37 | 77 | alarm_binding_backend_js_files \ | 80 | alarm_binding_backend_js_files \ |
38 | 78 | online_accounts_binding_backend_js_files \ | 81 | online_accounts_binding_backend_js_files \ |
39 | 79 | runtime_api_binding_backend_js_files \ | 82 | runtime_api_binding_backend_js_files \ |
42 | 80 | download_api_binding_backend_js_files | 83 | download_api_binding_backend_js_files \ |
43 | 81 | 84 | tools_api_binding_backend_js_files | |
44 | 82 | 85 | ||
45 | === modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.qml' | |||
46 | --- src/Ubuntu/UnityWebApps/UnityWebApps.qml 2015-03-06 15:15:15 +0000 | |||
47 | +++ src/Ubuntu/UnityWebApps/UnityWebApps.qml 2015-03-27 19:32:46 +0000 | |||
48 | @@ -28,6 +28,7 @@ | |||
49 | 28 | import "./bindings/online-accounts/backend/online-accounts.js" as OnlineAccountsApiBackend | 28 | import "./bindings/online-accounts/backend/online-accounts.js" as OnlineAccountsApiBackend |
50 | 29 | import "./bindings/online-accounts/backend/online-accounts-client.js" as OnlineAccountsClientApiBackend | 29 | import "./bindings/online-accounts/backend/online-accounts-client.js" as OnlineAccountsClientApiBackend |
51 | 30 | import "./bindings/download-manager/backend/download-api.js" as DownloadApiBackend | 30 | import "./bindings/download-manager/backend/download-api.js" as DownloadApiBackend |
52 | 31 | import "./bindings/tools/backend/tools.js" as ToolsApiBackend | ||
53 | 31 | 32 | ||
54 | 32 | /*! | 33 | /*! |
55 | 33 | \qmltype UnityWebApps | 34 | \qmltype UnityWebApps |
56 | @@ -493,6 +494,8 @@ | |||
57 | 493 | if (settings.injectExtraContentShareCapabilities) { | 494 | if (settings.injectExtraContentShareCapabilities) { |
58 | 494 | policy.add("launchEmbeddedUI"); | 495 | policy.add("launchEmbeddedUI"); |
59 | 495 | policy.add("ContentHub.onShareRequested"); | 496 | policy.add("ContentHub.onShareRequested"); |
60 | 497 | policy.add("ToolsApi.getHmacHash"); | ||
61 | 498 | policy.add("ToolsApi.sendHttpRequest"); | ||
62 | 496 | } | 499 | } |
63 | 497 | return policy; | 500 | return policy; |
64 | 498 | } | 501 | } |
65 | @@ -786,6 +789,8 @@ | |||
66 | 786 | return DownloadApiBackend.createDownloadApi(UnityBackends.backendDelegate) | 789 | return DownloadApiBackend.createDownloadApi(UnityBackends.backendDelegate) |
67 | 787 | }), | 790 | }), |
68 | 788 | 791 | ||
69 | 792 | ToolsApi: ToolsApiBackend.createToolsApi(UnityBackends.backendDelegate), | ||
70 | 793 | |||
71 | 789 | Launcher: { | 794 | Launcher: { |
72 | 790 | setCount: function (count) { | 795 | setCount: function (count) { |
73 | 791 | if (!initialized) | 796 | if (!initialized) |
74 | 792 | 797 | ||
75 | === added directory 'src/Ubuntu/UnityWebApps/bindings/tools' | |||
76 | === added directory 'src/Ubuntu/UnityWebApps/bindings/tools/backend' | |||
77 | === added file 'src/Ubuntu/UnityWebApps/bindings/tools/backend/tools.js' | |||
78 | --- src/Ubuntu/UnityWebApps/bindings/tools/backend/tools.js 1970-01-01 00:00:00 +0000 | |||
79 | +++ src/Ubuntu/UnityWebApps/bindings/tools/backend/tools.js 2015-03-27 19:32:46 +0000 | |||
80 | @@ -0,0 +1,95 @@ | |||
81 | 1 | /* | ||
82 | 2 | * Copyright 20145 Canonical Ltd. | ||
83 | 3 | * | ||
84 | 4 | * This file is part of unity-webapps-qml. | ||
85 | 5 | * | ||
86 | 6 | * unity-webapps-qml is free software; you can redistribute it and/or modify | ||
87 | 7 | * it under the terms of the GNU General Public License as published by | ||
88 | 8 | * the Free Software Foundation; version 3. | ||
89 | 9 | * | ||
90 | 10 | * unity-webapps-qml is distributed in the hope that it will be useful, | ||
91 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
92 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
93 | 13 | * GNU General Public License for more details. | ||
94 | 14 | * | ||
95 | 15 | * You should have received a copy of the GNU General Public License | ||
96 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
97 | 17 | */ | ||
98 | 18 | |||
99 | 19 | .import Ubuntu.UnityWebApps 0.2 as UnityWebAppsBridge | ||
100 | 20 | |||
101 | 21 | |||
102 | 22 | /** | ||
103 | 23 | * | ||
104 | 24 | * Tools API backend binding | ||
105 | 25 | * | ||
106 | 26 | */ | ||
107 | 27 | function createToolsApi(backendDelegate) { | ||
108 | 28 | var PLUGIN_URI = 'Ubuntu.UnityWebApps'; | ||
109 | 29 | var VERSION = 0.2; | ||
110 | 30 | |||
111 | 31 | var toolsApiInstance = UnityWebAppsBridge.ToolsApi; | ||
112 | 32 | |||
113 | 33 | function isValidAlgorithm(algorithm) { | ||
114 | 34 | var algos = ["MD5", "SHA1", "SHA256", "SHA512"] | ||
115 | 35 | return algos.some(function(e) { return e === algorithm; }) | ||
116 | 36 | }; | ||
117 | 37 | |||
118 | 38 | function stringToCryptoAlgorithm(algorithm) { | ||
119 | 39 | var assoc = { | ||
120 | 40 | "MD5": toolsApiInstance.MD5 | ||
121 | 41 | , "SHA1": toolsApiInstance.SHA1 | ||
122 | 42 | , "SHA256": toolsApiInstance.SHA256 | ||
123 | 43 | , "SHA512": toolsApiInstance.SHA512 | ||
124 | 44 | }; | ||
125 | 45 | return assoc[algorithm] | ||
126 | 46 | }; | ||
127 | 47 | |||
128 | 48 | return { | ||
129 | 49 | getHmacHash: function(message, algorithm, key, callback) { | ||
130 | 50 | if ( ! isValidAlgorithm(algorithm)) { | ||
131 | 51 | callback({errorMsg: "Invalid algorithm", | ||
132 | 52 | result: null}); | ||
133 | 53 | return; | ||
134 | 54 | } | ||
135 | 55 | callback({errorMsg: "", | ||
136 | 56 | result: toolsApiInstance.getHmacHash( | ||
137 | 57 | message, stringToCryptoAlgorithm(algorithm), key)}); | ||
138 | 58 | }, | ||
139 | 59 | sendHttpRequest: function(url, location, request, payload, callback) { | ||
140 | 60 | if ( ! toolsApiInstance.areCompatibleCorsUrl(url, location)) { | ||
141 | 61 | console.error('sendHttpRequest: incompatible CORS request urls') | ||
142 | 62 | return; | ||
143 | 63 | } | ||
144 | 64 | |||
145 | 65 | var xmlrequest = new XMLHttpRequest(); | ||
146 | 66 | |||
147 | 67 | var verb = payload && payload.length !== 0 | ||
148 | 68 | ? "POST" : "GET" | ||
149 | 69 | |||
150 | 70 | xmlrequest.open(verb, url, true); | ||
151 | 71 | |||
152 | 72 | xmlrequest.onreadystatechange = function() { | ||
153 | 73 | if (xmlrequest.readyState === XMLHttpRequest.DONE) { | ||
154 | 74 | callback({ | ||
155 | 75 | errorMsg: xmlrequest.statusText, | ||
156 | 76 | success: xmlrequest.status == 200, | ||
157 | 77 | response: xmlrequest.responseText | ||
158 | 78 | }); | ||
159 | 79 | } | ||
160 | 80 | }; | ||
161 | 81 | |||
162 | 82 | for (var header in request.headers) { | ||
163 | 83 | if (request.headers.hasOwnProperty(header)) { | ||
164 | 84 | xmlrequest.setRequestHeader(header, request.headers[header]) | ||
165 | 85 | } | ||
166 | 86 | } | ||
167 | 87 | |||
168 | 88 | xmlrequest.setRequestHeader( | ||
169 | 89 | "Content-Length", | ||
170 | 90 | String(payload.length)); | ||
171 | 91 | |||
172 | 92 | xmlrequest.send(payload); | ||
173 | 93 | } | ||
174 | 94 | }; | ||
175 | 95 | } | ||
176 | 0 | 96 | ||
177 | === added directory 'src/Ubuntu/UnityWebApps/bindings/tools/client' | |||
178 | === added file 'src/Ubuntu/UnityWebApps/bindings/tools/client/tools.js' | |||
179 | --- src/Ubuntu/UnityWebApps/bindings/tools/client/tools.js 1970-01-01 00:00:00 +0000 | |||
180 | +++ src/Ubuntu/UnityWebApps/bindings/tools/client/tools.js 2015-03-27 19:32:46 +0000 | |||
181 | @@ -0,0 +1,106 @@ | |||
182 | 1 | /* | ||
183 | 2 | * Copyright 2015 Canonical Ltd. | ||
184 | 3 | * | ||
185 | 4 | * This file is part of unity-webapps-qml. | ||
186 | 5 | * | ||
187 | 6 | * unity-webapps-qml is free software; you can redistribute it and/or modify | ||
188 | 7 | * it under the terms of the GNU General Public License as published by | ||
189 | 8 | * the Free Software Foundation; version 3. | ||
190 | 9 | * | ||
191 | 10 | * unity-webapps-qml is distributed in the hope that it will be useful, | ||
192 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
193 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
194 | 13 | * GNU General Public License for more details. | ||
195 | 14 | * | ||
196 | 15 | * You should have received a copy of the GNU General Public License | ||
197 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
198 | 17 | */ | ||
199 | 18 | |||
200 | 19 | |||
201 | 20 | /** | ||
202 | 21 | * Tools gives access to various helpers/tools. | ||
203 | 22 | |||
204 | 23 | * @module Tools | ||
205 | 24 | */ | ||
206 | 25 | function createToolsApi(backendBridge) { | ||
207 | 26 | var PLUGIN_URI = 'Tools'; | ||
208 | 27 | |||
209 | 28 | /** | ||
210 | 29 | * The Tools object | ||
211 | 30 | |||
212 | 31 | * @class Tools | ||
213 | 32 | * @constructor | ||
214 | 33 | * @example | ||
215 | 34 | |||
216 | 35 | var api = external.getUnityObject('1.0'); | ||
217 | 36 | api.Tools.getHmacHash(hmac, algorithm, key, function(result) { | ||
218 | 37 | console.log('Application name: ' + result); | ||
219 | 38 | }); | ||
220 | 39 | */ | ||
221 | 40 | return { | ||
222 | 41 | /** | ||
223 | 42 | Enumeration of the available types of CryptographicAlgorithm. | ||
224 | 43 | |||
225 | 44 | Values: | ||
226 | 45 | |||
227 | 46 | MD5: MD5 hash function | ||
228 | 47 | |||
229 | 48 | SHA1: SHA1 hash function | ||
230 | 49 | |||
231 | 50 | SHA256: SHA-256 hash function | ||
232 | 51 | |||
233 | 52 | SHA512: SHA-512 hash function | ||
234 | 53 | |||
235 | 54 | @static | ||
236 | 55 | @property CryptographicAlgorithm {Object} | ||
237 | 56 | |||
238 | 57 | @example | ||
239 | 58 | |||
240 | 59 | var api = external.getUnityObject('1.0'); | ||
241 | 60 | var algorithm = api.Tools.CryptographicAlgorithm; | ||
242 | 61 | // use algorithm.MD5, algorithm.SHA-1, ... | ||
243 | 62 | */ | ||
244 | 63 | CryptographicAlgorithm: { | ||
245 | 64 | MD5: "MD5", | ||
246 | 65 | |||
247 | 66 | SHA1: "SHA1", | ||
248 | 67 | |||
249 | 68 | SHA256: "SHA256", | ||
250 | 69 | |||
251 | 70 | SHA512: "SHA512" | ||
252 | 71 | }, | ||
253 | 72 | |||
254 | 73 | /** | ||
255 | 74 | * Generates a . | ||
256 | 75 | * | ||
257 | 76 | * @method getHmacHash | ||
258 | 77 | * @param message {Function (Application)} | ||
259 | 78 | * @param algorithm {CryptographicAlgorithm} | ||
260 | 79 | * @param key {Function (Application)} | ||
261 | 80 | * @param callback {Function (Application)} | ||
262 | 81 | */ | ||
263 | 82 | getHmacHash: function(message, algorithm, key, callback) { | ||
264 | 83 | if (! callback || typeof(callback) !== 'function') { | ||
265 | 84 | return; | ||
266 | 85 | } | ||
267 | 86 | backendBridge.call('ToolsApi.getHmacHash' | ||
268 | 87 | , [message, algorithm, key] | ||
269 | 88 | , callback); | ||
270 | 89 | }, | ||
271 | 90 | |||
272 | 91 | /** | ||
273 | 92 | * @internal | ||
274 | 93 | */ | ||
275 | 94 | __private__: { | ||
276 | 95 | sendHttpRequest: function(url, request, payload, callback) { | ||
277 | 96 | if (! callback || typeof(callback) !== 'function') { | ||
278 | 97 | return; | ||
279 | 98 | } | ||
280 | 99 | var location = window && window.location ? window.location.href : "" | ||
281 | 100 | backendBridge.call('ToolsApi.sendHttpRequest' | ||
282 | 101 | , [url, location, request, payload] | ||
283 | 102 | , callback); | ||
284 | 103 | } | ||
285 | 104 | } | ||
286 | 105 | }; | ||
287 | 106 | }; | ||
288 | 0 | 107 | ||
289 | === modified file 'src/Ubuntu/UnityWebApps/plugin/plugin.pro' | |||
290 | --- src/Ubuntu/UnityWebApps/plugin/plugin.pro 2014-07-07 18:59:19 +0000 | |||
291 | +++ src/Ubuntu/UnityWebApps/plugin/plugin.pro 2015-03-27 19:32:46 +0000 | |||
292 | @@ -41,6 +41,7 @@ | |||
293 | 41 | callback.cpp \ | 41 | callback.cpp \ |
294 | 42 | abstract-item-model-adaptor.cpp \ | 42 | abstract-item-model-adaptor.cpp \ |
295 | 43 | application-api.cpp \ | 43 | application-api.cpp \ |
296 | 44 | tools-api.cpp \ | ||
297 | 44 | application-signal-to-qt-bridge.cpp | 45 | application-signal-to-qt-bridge.cpp |
298 | 45 | 46 | ||
299 | 46 | HEADERS += \ | 47 | HEADERS += \ |
300 | @@ -59,6 +60,7 @@ | |||
301 | 59 | callback.h \ | 60 | callback.h \ |
302 | 60 | abstract-item-model-adaptor.h \ | 61 | abstract-item-model-adaptor.h \ |
303 | 61 | application-api.h \ | 62 | application-api.h \ |
304 | 63 | tools-api.h \ | ||
305 | 62 | application-signal-to-qt-bridge.h | 64 | application-signal-to-qt-bridge.h |
306 | 63 | 65 | ||
307 | 64 | DEFINES += \ | 66 | DEFINES += \ |
308 | 65 | 67 | ||
309 | === modified file 'src/Ubuntu/UnityWebApps/plugin/qml-plugin.cpp' | |||
310 | --- src/Ubuntu/UnityWebApps/plugin/qml-plugin.cpp 2014-07-07 18:59:19 +0000 | |||
311 | +++ src/Ubuntu/UnityWebApps/plugin/qml-plugin.cpp 2015-03-27 19:32:46 +0000 | |||
312 | @@ -30,6 +30,7 @@ | |||
313 | 30 | #include "unity-webapps-app-infos.h" | 30 | #include "unity-webapps-app-infos.h" |
314 | 31 | 31 | ||
315 | 32 | #include "application-api.h" | 32 | #include "application-api.h" |
316 | 33 | #include "tools-api.h" | ||
317 | 33 | #include "abstract-item-model-adaptor.h" | 34 | #include "abstract-item-model-adaptor.h" |
318 | 34 | #include "callback.h" | 35 | #include "callback.h" |
319 | 35 | 36 | ||
320 | @@ -43,6 +44,14 @@ | |||
321 | 43 | return new ApplicationApi(); | 44 | return new ApplicationApi(); |
322 | 44 | } | 45 | } |
323 | 45 | 46 | ||
324 | 47 | static QObject *createToolsApi(QQmlEngine *engine, QJSEngine *scriptEngine) | ||
325 | 48 | { | ||
326 | 49 | Q_UNUSED(engine); | ||
327 | 50 | Q_UNUSED(scriptEngine); | ||
328 | 51 | |||
329 | 52 | return new ToolsApi(); | ||
330 | 53 | } | ||
331 | 54 | |||
332 | 46 | void WebappsQmlPlugin::registerTypes(const char *uri) | 55 | void WebappsQmlPlugin::registerTypes(const char *uri) |
333 | 47 | { | 56 | { |
334 | 48 | // bindings | 57 | // bindings |
335 | @@ -60,7 +69,9 @@ | |||
336 | 60 | // TODO bump version | 69 | // TODO bump version |
337 | 61 | qmlRegisterType<AbstractItemModelAdaptor> (uri, 0, 1, "AbstractItemModelAdaptor"); | 70 | qmlRegisterType<AbstractItemModelAdaptor> (uri, 0, 1, "AbstractItemModelAdaptor"); |
338 | 62 | 71 | ||
340 | 63 | // | 72 | // Application Api entry point |
341 | 64 | qmlRegisterSingletonType<ApplicationApi>(uri, 0, 1, "ApplicationApi", createApplicationApi); | 73 | qmlRegisterSingletonType<ApplicationApi>(uri, 0, 1, "ApplicationApi", createApplicationApi); |
342 | 74 | |||
343 | 75 | // Tools Api entry point | ||
344 | 76 | qmlRegisterSingletonType<ToolsApi>(uri, 0, 2, "ToolsApi", createToolsApi); | ||
345 | 65 | } | 77 | } |
346 | 66 | |||
347 | 67 | 78 | ||
348 | === added file 'src/Ubuntu/UnityWebApps/plugin/tools-api.cpp' | |||
349 | --- src/Ubuntu/UnityWebApps/plugin/tools-api.cpp 1970-01-01 00:00:00 +0000 | |||
350 | +++ src/Ubuntu/UnityWebApps/plugin/tools-api.cpp 2015-03-27 19:32:46 +0000 | |||
351 | @@ -0,0 +1,120 @@ | |||
352 | 1 | /* | ||
353 | 2 | * Copyright 2014 Canonical Ltd. | ||
354 | 3 | * | ||
355 | 4 | * This file is part of unity-webapps-qml. | ||
356 | 5 | * | ||
357 | 6 | * unity-webapps-qml is free software; you can redistribute it and/or modify | ||
358 | 7 | * it under the terms of the GNU General Public License as published by | ||
359 | 8 | * the Free Software Foundation; version 3. | ||
360 | 9 | * | ||
361 | 10 | * unity-webapps-qml is distributed in the hope that it will be useful, | ||
362 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
363 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
364 | 13 | * GNU General Public License for more details. | ||
365 | 14 | * | ||
366 | 15 | * You should have received a copy of the GNU General Public License | ||
367 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
368 | 17 | */ | ||
369 | 18 | |||
370 | 19 | #include "tools-api.h" | ||
371 | 20 | |||
372 | 21 | #include <QCryptographicHash> | ||
373 | 22 | #include <QDebug> | ||
374 | 23 | #include <QMessageAuthenticationCode> | ||
375 | 24 | #include <QUrl> | ||
376 | 25 | #include <QString> | ||
377 | 26 | #include <QFileInfo> | ||
378 | 27 | #include <QFile> | ||
379 | 28 | |||
380 | 29 | |||
381 | 30 | namespace { | ||
382 | 31 | |||
383 | 32 | bool enumToQtCryptoAlgorithm( | ||
384 | 33 | ToolsApi::CryptographicAlgorithm algorithm, | ||
385 | 34 | QCryptographicHash::Algorithm & out) | ||
386 | 35 | { | ||
387 | 36 | switch(algorithm) | ||
388 | 37 | { | ||
389 | 38 | case ToolsApi::MD5: | ||
390 | 39 | out = QCryptographicHash::Md5; | ||
391 | 40 | return true; | ||
392 | 41 | break; | ||
393 | 42 | case ToolsApi::SHA1: | ||
394 | 43 | out = QCryptographicHash::Sha1; | ||
395 | 44 | return true; | ||
396 | 45 | break; | ||
397 | 46 | case ToolsApi::SHA256: | ||
398 | 47 | out = QCryptographicHash::Sha256; | ||
399 | 48 | return true; | ||
400 | 49 | break; | ||
401 | 50 | case ToolsApi::SHA512: | ||
402 | 51 | out = QCryptographicHash::Sha512; | ||
403 | 52 | return true; | ||
404 | 53 | break; | ||
405 | 54 | } | ||
406 | 55 | return false; | ||
407 | 56 | } | ||
408 | 57 | |||
409 | 58 | QString getSecondLevelDomain(const QUrl& url) | ||
410 | 59 | { | ||
411 | 60 | QString tld = url.topLevelDomain(); | ||
412 | 61 | QString host = url.host().left(url.host().length() - tld.length()); | ||
413 | 62 | QStringList s = host.split(".", QString::SkipEmptyParts); | ||
414 | 63 | return s.isEmpty() ? tld : (s.last() + tld); | ||
415 | 64 | } | ||
416 | 65 | |||
417 | 66 | } | ||
418 | 67 | |||
419 | 68 | |||
420 | 69 | /** | ||
421 | 70 | * @brief ToolsApi::ToolsApi | ||
422 | 71 | * @param parent | ||
423 | 72 | */ | ||
424 | 73 | ToolsApi::ToolsApi(QObject *parent) : | ||
425 | 74 | QObject(parent) | ||
426 | 75 | {} | ||
427 | 76 | |||
428 | 77 | |||
429 | 78 | /** | ||
430 | 79 | * Compute a HMAC for a given message given a cryptographic key | ||
431 | 80 | * and specific crypto algorithm. | ||
432 | 81 | * | ||
433 | 82 | * @brief ToolsApi::getHmacHash | ||
434 | 83 | * @param message | ||
435 | 84 | * @param algorithm | ||
436 | 85 | * @param key | ||
437 | 86 | * @return HMAC of the message | ||
438 | 87 | */ | ||
439 | 88 | QString ToolsApi::getHmacHash( | ||
440 | 89 | const QString& message, | ||
441 | 90 | ToolsApi::CryptographicAlgorithm algorithm, | ||
442 | 91 | const QString& key) const | ||
443 | 92 | { | ||
444 | 93 | QCryptographicHash::Algorithm | ||
445 | 94 | method = QCryptographicHash::Md5; | ||
446 | 95 | if ( ! enumToQtCryptoAlgorithm(algorithm, method)) | ||
447 | 96 | { | ||
448 | 97 | qCritical() << "Invalid HMAC method algorithm"; | ||
449 | 98 | return QString(); | ||
450 | 99 | } | ||
451 | 100 | QMessageAuthenticationCode | ||
452 | 101 | code(method, key.toUtf8()); | ||
453 | 102 | code.addData(message.toUtf8()); | ||
454 | 103 | return QString::fromUtf8(code.result().toBase64()); | ||
455 | 104 | } | ||
456 | 105 | |||
457 | 106 | |||
458 | 107 | /** | ||
459 | 108 | * @brief ToolsApi::isCompatibleCorsRequest | ||
460 | 109 | * @param requestUrl | ||
461 | 110 | * @param locationUrl | ||
462 | 111 | * @return | ||
463 | 112 | */ | ||
464 | 113 | bool ToolsApi::areCompatibleCorsUrl( | ||
465 | 114 | const QUrl& url1, | ||
466 | 115 | const QUrl& url2) const | ||
467 | 116 | { | ||
468 | 117 | return url1.scheme() == url2.scheme() | ||
469 | 118 | && url1.topLevelDomain() == url2.topLevelDomain() | ||
470 | 119 | && getSecondLevelDomain(url1) == getSecondLevelDomain(url2); | ||
471 | 120 | } | ||
472 | 0 | 121 | ||
473 | === added file 'src/Ubuntu/UnityWebApps/plugin/tools-api.h' | |||
474 | --- src/Ubuntu/UnityWebApps/plugin/tools-api.h 1970-01-01 00:00:00 +0000 | |||
475 | +++ src/Ubuntu/UnityWebApps/plugin/tools-api.h 2015-03-27 19:32:46 +0000 | |||
476 | @@ -0,0 +1,51 @@ | |||
477 | 1 | /* | ||
478 | 2 | * Copyright 2015 Canonical Ltd. | ||
479 | 3 | * | ||
480 | 4 | * This file is part of unity-webapps-qml. | ||
481 | 5 | * | ||
482 | 6 | * unity-webapps-qml is free software; you can redistribute it and/or modify | ||
483 | 7 | * it under the terms of the GNU General Public License as published by | ||
484 | 8 | * the Free Software Foundation; version 3. | ||
485 | 9 | * | ||
486 | 10 | * unity-webapps-qml is distributed in the hope that it will be useful, | ||
487 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
488 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
489 | 13 | * GNU General Public License for more details. | ||
490 | 14 | * | ||
491 | 15 | * You should have received a copy of the GNU General Public License | ||
492 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
493 | 17 | */ | ||
494 | 18 | |||
495 | 19 | #ifndef UNITY_WEBAPPS_TOOLSAPI_H | ||
496 | 20 | #define UNITY_WEBAPPS_TOOLSAPI_H | ||
497 | 21 | |||
498 | 22 | #include <QObject> | ||
499 | 23 | |||
500 | 24 | |||
501 | 25 | class ToolsApi : public QObject | ||
502 | 26 | { | ||
503 | 27 | Q_OBJECT | ||
504 | 28 | Q_ENUMS(CryptographicAlgorithm) | ||
505 | 29 | |||
506 | 30 | public: | ||
507 | 31 | explicit ToolsApi(QObject *parent = 0); | ||
508 | 32 | |||
509 | 33 | enum CryptographicAlgorithm | ||
510 | 34 | { | ||
511 | 35 | MD5, | ||
512 | 36 | SHA1, | ||
513 | 37 | SHA256, | ||
514 | 38 | SHA512 | ||
515 | 39 | }; | ||
516 | 40 | |||
517 | 41 | Q_INVOKABLE QString getHmacHash( | ||
518 | 42 | const QString &hmac, | ||
519 | 43 | CryptographicAlgorithm algorithm, | ||
520 | 44 | const QString& key) const; | ||
521 | 45 | |||
522 | 46 | Q_INVOKABLE bool areCompatibleCorsUrl( | ||
523 | 47 | const QUrl& url1, | ||
524 | 48 | const QUrl& url2) const; | ||
525 | 49 | }; | ||
526 | 50 | |||
527 | 51 | #endif // UNITY_WEBAPPS_TOOLSAPI_H | ||
528 | 0 | 52 | ||
529 | === modified file 'src/Ubuntu/UnityWebApps/unity-webapps-api.js.in' | |||
530 | --- src/Ubuntu/UnityWebApps/unity-webapps-api.js.in 2014-06-04 21:17:00 +0000 | |||
531 | +++ src/Ubuntu/UnityWebApps/unity-webapps-api.js.in 2015-03-27 19:32:46 +0000 | |||
532 | @@ -35,6 +35,7 @@ | |||
533 | 35 | //@include ./bindings/online-accounts/client/online-accounts.js | 35 | //@include ./bindings/online-accounts/client/online-accounts.js |
534 | 36 | //@include ./bindings/runtime-api/client/runtime-api.js | 36 | //@include ./bindings/runtime-api/client/runtime-api.js |
535 | 37 | //@include ./bindings/download-manager/client/download-api.js | 37 | //@include ./bindings/download-manager/client/download-api.js |
536 | 38 | //@include ./bindings/tools/client/tools.js | ||
537 | 38 | //@include ./common/js/unity-backend-messaging-proxy.js | 39 | //@include ./common/js/unity-backend-messaging-proxy.js |
538 | 39 | //@include ./common/js/unity-binding-proxy.js | 40 | //@include ./common/js/unity-binding-proxy.js |
539 | 40 | //@include ./common/js/unity-binding-bridge.js | 41 | //@include ./common/js/unity-binding-bridge.js |
540 | @@ -290,6 +291,7 @@ | |||
541 | 290 | ContentHub: createContentHubApi(backend), | 291 | ContentHub: createContentHubApi(backend), |
542 | 291 | RuntimeApi: createRuntimeApi(backend), | 292 | RuntimeApi: createRuntimeApi(backend), |
543 | 292 | DownloadApi: createDownloadApi(backend), | 293 | DownloadApi: createDownloadApi(backend), |
544 | 294 | ToolsApi: createToolsApi(backend) | ||
545 | 293 | }; | 295 | }; |
546 | 294 | 296 | ||
547 | 295 | return api; | 297 | return api; |
548 | 296 | 298 | ||
549 | === modified file 'tests/autopilot/html/test_webapps_api_injected.html' | |||
550 | --- tests/autopilot/html/test_webapps_api_injected.html 2014-04-22 15:40:04 +0000 | |||
551 | +++ tests/autopilot/html/test_webapps_api_injected.html 2015-03-27 19:32:46 +0000 | |||
552 | @@ -32,6 +32,9 @@ | |||
553 | 32 | <div id="content"> | 32 | <div id="content"> |
554 | 33 | </div> | 33 | </div> |
555 | 34 | 34 | ||
556 | 35 | <div id="results"> | ||
557 | 36 | </div> | ||
558 | 37 | |||
559 | 35 | </body> | 38 | </body> |
560 | 36 | 39 | ||
561 | 37 | </html> | 40 | </html> |
562 | 38 | 41 | ||
563 | === modified file 'tests/autopilot/setup.py' | |||
564 | --- tests/autopilot/setup.py 2013-07-09 19:02:23 +0000 | |||
565 | +++ tests/autopilot/setup.py 2015-03-27 19:32:46 +0000 | |||
566 | @@ -6,15 +6,14 @@ | |||
567 | 6 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
568 | 7 | # by the Free Software Foundation. | 7 | # by the Free Software Foundation. |
569 | 8 | 8 | ||
570 | 9 | |||
571 | 10 | from distutils.core import setup | 9 | from distutils.core import setup |
572 | 11 | from setuptools import find_packages | 10 | from setuptools import find_packages |
573 | 12 | 11 | ||
574 | 13 | setup( | 12 | setup( |
581 | 14 | name='unity-webapps-qml', | 13 | name='unity-webapps-qml', |
582 | 15 | version='0.1', | 14 | version='0.1', |
583 | 16 | description='Unity WebApps QML component autopilot tests.', | 15 | description='Unity WebApps QML component autopilot tests.', |
584 | 17 | url='https://launchpad.net/unity-webapps-qml', | 16 | url='https://launchpad.net/unity-webapps-qml', |
585 | 18 | license='GPLv3', | 17 | license='GPLv3', |
586 | 19 | packages=find_packages(), | 18 | packages=find_packages(), |
587 | 20 | ) | 19 | ) |
588 | 21 | 20 | ||
589 | === modified file 'tests/autopilot/unity_webapps_qml/tests/__init__.py' | |||
590 | --- tests/autopilot/unity_webapps_qml/tests/__init__.py 2014-07-14 19:01:17 +0000 | |||
591 | +++ tests/autopilot/unity_webapps_qml/tests/__init__.py 2015-03-27 19:32:46 +0000 | |||
592 | @@ -9,27 +9,27 @@ | |||
593 | 9 | 9 | ||
594 | 10 | import os | 10 | import os |
595 | 11 | import os.path | 11 | import os.path |
596 | 12 | import shutil | ||
597 | 13 | import tempfile | ||
598 | 14 | import json | 12 | import json |
599 | 15 | 13 | ||
601 | 16 | from testtools.matchers import Contains, Equals, GreaterThan | 14 | from testtools.matchers import Equals, GreaterThan |
602 | 17 | from autopilot.matchers import Eventually | 15 | from autopilot.matchers import Eventually |
603 | 18 | from unity_webapps_qml.tests import fake_servers | 16 | from unity_webapps_qml.tests import fake_servers |
604 | 19 | 17 | ||
605 | 20 | from unity.emulators.unity import Unity | ||
606 | 21 | |||
607 | 22 | from unity.tests import UnityTestCase | 18 | from unity.tests import UnityTestCase |
608 | 23 | 19 | ||
610 | 24 | LOCAL_QML_LAUNCHER_APP_PATH = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../../../tools/qml-launcher/unity-webapps-qml-launcher') | 20 | LOCAL_QML_LAUNCHER_APP_PATH = "%s/%s" % ( |
611 | 21 | os.path.dirname(os.path.realpath(__file__)), | ||
612 | 22 | '../../../../tools/qml-launcher/unity-webapps-qml-launcher') | ||
613 | 25 | INSTALLED_QML_LAUNCHER_APP_PATH = 'unity-webapps-qml-launcher' | 23 | INSTALLED_QML_LAUNCHER_APP_PATH = 'unity-webapps-qml-launcher' |
618 | 26 | 24 | LOCAL_BROWSER_CONTAINER_PATH = "%s/%s" % ( | |
619 | 27 | # TODO create __init__.py.in | 25 | os.path.dirname(os.path.realpath(__file__)), |
620 | 28 | LOCAL_BROWSER_CONTAINER_PATH = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../qml/FullWebViewApp.qml') | 26 | '../../qml/FullWebViewApp.qml') |
621 | 29 | INSTALLED_BROWSER_CONTAINER_PATH = '/usr/share/unity-webapps-qml/autopilot-tests/qml/FullWebViewApp.qml' | 27 | INSTALLED_BROWSER_CONTAINER_PATH = '/usr/share \ |
622 | 28 | /unity-webapps-qml/autopilot-tests/qml/FullWebViewApp.qml' | ||
623 | 30 | 29 | ||
624 | 31 | BASE_URL = '' | 30 | BASE_URL = '' |
625 | 32 | 31 | ||
626 | 32 | |||
627 | 33 | class UnityWebappsTestCaseBase(UnityTestCase): | 33 | class UnityWebappsTestCaseBase(UnityTestCase): |
628 | 34 | 34 | ||
629 | 35 | def setUp(self): | 35 | def setUp(self): |
630 | @@ -59,7 +59,8 @@ | |||
631 | 59 | webapp_homepage="", | 59 | webapp_homepage="", |
632 | 60 | use_oxide=False, | 60 | use_oxide=False, |
633 | 61 | extra_params=[]): | 61 | extra_params=[]): |
635 | 62 | base_params = ['--qml=' + self.get_qml_browser_container_path(), | 62 | base_params = [ |
636 | 63 | '--qml=' + self.get_qml_browser_container_path(), | ||
637 | 63 | '--app-id=' + webapp_name, | 64 | '--app-id=' + webapp_name, |
638 | 64 | '--webappName=' + webapp_name, | 65 | '--webappName=' + webapp_name, |
639 | 65 | '--webappSearchPath=' + webapp_search_path] | 66 | '--webappSearchPath=' + webapp_search_path] |
640 | @@ -75,8 +76,10 @@ | |||
641 | 75 | 76 | ||
642 | 76 | if os.path.exists(LOCAL_QML_LAUNCHER_APP_PATH): | 77 | if os.path.exists(LOCAL_QML_LAUNCHER_APP_PATH): |
643 | 77 | # we are local | 78 | # we are local |
646 | 78 | base_params.append('--import=' + os.path.join (os.path.dirname(os.path.realpath(__file__)), | 79 | base_params.append( |
647 | 79 | '../../../../src')) | 80 | '--import=' + os.path.join( |
648 | 81 | os.path.dirname(os.path.realpath(__file__)), | ||
649 | 82 | '../../../../src')) | ||
650 | 80 | 83 | ||
651 | 81 | base_params += extra_params | 84 | base_params += extra_params |
652 | 82 | 85 | ||
653 | @@ -86,18 +89,25 @@ | |||
654 | 86 | self.assertThat(os.path.exists(html_filepath), Equals(True)) | 89 | self.assertThat(os.path.exists(html_filepath), Equals(True)) |
655 | 87 | url = self.create_file_url(html_filepath) | 90 | url = self.create_file_url(html_filepath) |
656 | 88 | 91 | ||
658 | 89 | self.launch_application(self.get_launch_params(url, 'unitywebappsqmllauncher', '', '', False, extra_params)) | 92 | self.launch_application( |
659 | 93 | self.get_launch_params( | ||
660 | 94 | url, | ||
661 | 95 | 'unitywebappsqmllauncher', | ||
662 | 96 | '', | ||
663 | 97 | '', | ||
664 | 98 | False, | ||
665 | 99 | extra_params)) | ||
666 | 90 | self.assert_url_eventually_loaded(url) | 100 | self.assert_url_eventually_loaded(url) |
667 | 91 | 101 | ||
668 | 92 | def launch_application(self, args): | 102 | def launch_application(self, args): |
672 | 93 | print 'Launching test with params:', args, "with", self.get_qml_launcher_path() | 103 | self.app = self.launch_test_application( |
673 | 94 | 104 | self.get_qml_launcher_path(), | |
671 | 95 | self.app = self.launch_test_application(self.get_qml_launcher_path(), | ||
674 | 96 | *args, | 105 | *args, |
675 | 97 | app_type='qt') | 106 | app_type='qt') |
676 | 98 | 107 | ||
677 | 99 | self.webviewContainer = self.get_webviewContainer() | 108 | self.webviewContainer = self.get_webviewContainer() |
679 | 100 | self.watcher = self.webviewContainer.watch_signal('resultUpdated(QString)') | 109 | self.watcher = self.webviewContainer.watch_signal( |
680 | 110 | 'resultUpdated(QString)') | ||
681 | 101 | 111 | ||
682 | 102 | def pick_app_launcher(self, app_path): | 112 | def pick_app_launcher(self, app_path): |
683 | 103 | # force Qt app introspection: | 113 | # force Qt app introspection: |
684 | @@ -123,9 +133,14 @@ | |||
685 | 123 | webview = self.get_webviewContainer() | 133 | webview = self.get_webviewContainer() |
686 | 124 | prev_emissions = self.watcher.num_emissions | 134 | prev_emissions = self.watcher.num_emissions |
687 | 125 | webview.slots.evalInPageUnsafe(expr) | 135 | webview.slots.evalInPageUnsafe(expr) |
691 | 126 | self.assertThat(lambda: self.watcher.num_emissions, Eventually(GreaterThan(prev_emissions))) | 136 | self.assertThat( |
692 | 127 | results = json.loads(webview.get_signal_emissions('resultUpdated(QString)')[-1][0]) | 137 | lambda: self.watcher.num_emissions, |
693 | 128 | return results.has_key('result') and results['result'] or None | 138 | Eventually(GreaterThan(prev_emissions))) |
694 | 139 | results = json.loads( | ||
695 | 140 | webview.get_signal_emissions( | ||
696 | 141 | 'resultUpdated(QString)')[-1][0]) | ||
697 | 142 | return 'result' in results and results['result'] or None | ||
698 | 143 | |||
699 | 129 | 144 | ||
700 | 130 | class WebappsTestCaseBaseWithLocalHttpContentBase(UnityWebappsTestCaseBase): | 145 | class WebappsTestCaseBaseWithLocalHttpContentBase(UnityWebappsTestCaseBase): |
701 | 131 | def setUp(self): | 146 | def setUp(self): |
702 | @@ -136,5 +151,11 @@ | |||
703 | 136 | 151 | ||
704 | 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): |
705 | 138 | self.use_oxide = use_oxide | 153 | self.use_oxide = use_oxide |
707 | 139 | self.launch_application(self.get_launch_params("", name, webapp_search_path, self.base_url, use_oxide)) | 154 | self.launch_application( |
708 | 155 | self.get_launch_params( | ||
709 | 156 | "", | ||
710 | 157 | name, | ||
711 | 158 | webapp_search_path, | ||
712 | 159 | self.base_url, | ||
713 | 160 | use_oxide)) | ||
714 | 140 | self.assert_url_eventually_loaded(self.base_url) | 161 | self.assert_url_eventually_loaded(self.base_url) |
715 | 141 | 162 | ||
716 | === added file 'tests/autopilot/unity_webapps_qml/tests/test_api_tools.py' | |||
717 | --- tests/autopilot/unity_webapps_qml/tests/test_api_tools.py 1970-01-01 00:00:00 +0000 | |||
718 | +++ tests/autopilot/unity_webapps_qml/tests/test_api_tools.py 2015-03-27 19:32:46 +0000 | |||
719 | @@ -0,0 +1,116 @@ | |||
720 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
721 | 2 | # Copyright 2015 Canonical | ||
722 | 3 | # | ||
723 | 4 | # This program is free software: you can redistribute it and/or modify it | ||
724 | 5 | # under the terms of the GNU General Public License version 3, as published | ||
725 | 6 | # by the Free Software Foundation. | ||
726 | 7 | |||
727 | 8 | from __future__ import absolute_import | ||
728 | 9 | |||
729 | 10 | import os | ||
730 | 11 | |||
731 | 12 | from testtools.matchers import Equals, NotEquals, Contains | ||
732 | 13 | from autopilot.matchers import Eventually | ||
733 | 14 | |||
734 | 15 | from unity_webapps_qml.tests import UnityWebappsTestCaseBase | ||
735 | 16 | |||
736 | 17 | LOCAL_HTML_TEST_FILE = "%s/%s" % ( | ||
737 | 18 | os.path.dirname(os.path.realpath(__file__)), | ||
738 | 19 | '../../html/test_webapps_api_injected.html') | ||
739 | 20 | |||
740 | 21 | INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests\ | ||
741 | 22 | /html/test_webapps_api_injected.html' | ||
742 | 23 | |||
743 | 24 | |||
744 | 25 | class UnityWebappsApiToolsTestCaseBase(UnityWebappsTestCaseBase): | ||
745 | 26 | |||
746 | 27 | def get_html_test_file(self): | ||
747 | 28 | if os.path.exists(LOCAL_HTML_TEST_FILE): | ||
748 | 29 | return os.path.abspath(LOCAL_HTML_TEST_FILE) | ||
749 | 30 | return INSTALLED_HTML_TEST_FILE | ||
750 | 31 | |||
751 | 32 | def setUp(self): | ||
752 | 33 | super(UnityWebappsApiToolsTestCaseBase, self).setUp() | ||
753 | 34 | self.launch_with_html_filepath(self.get_html_test_file()) | ||
754 | 35 | |||
755 | 36 | def test_apiFound(self): | ||
756 | 37 | self.assertThat( | ||
757 | 38 | lambda: self.eval_expression_in_page_unsafe( | ||
758 | 39 | 'return window.external.getUnityObject("1.0") != null;'), | ||
759 | 40 | Eventually(Equals(True))) | ||
760 | 41 | |||
761 | 42 | expression = """ | ||
762 | 43 | var api = window.external.getUnityObject("1.0"); | ||
763 | 44 | return api.ToolsApi != null | ||
764 | 45 | && api.ToolsApi.getHmacHash != null | ||
765 | 46 | && api.ToolsApi.__private__.sendHttpRequest != null | ||
766 | 47 | """ | ||
767 | 48 | self.assertThat( | ||
768 | 49 | lambda: self.eval_expression_in_page_unsafe(expression), | ||
769 | 50 | Eventually(Equals(True))) | ||
770 | 51 | |||
771 | 52 | def test_hmacCall(self): | ||
772 | 53 | self.assertThat( | ||
773 | 54 | lambda: self.eval_expression_in_page_unsafe( | ||
774 | 55 | 'return window.external.getUnityObject("1.0") != null;'), | ||
775 | 56 | Eventually(Equals(True))) | ||
776 | 57 | |||
777 | 58 | expression = """ | ||
778 | 59 | var api = window.external.getUnityObject("1.0"); | ||
779 | 60 | api.ToolsApi.getHmacHash( | ||
780 | 61 | "hi", | ||
781 | 62 | api.ToolsApi.CryptographicAlgorithm.SHA1, | ||
782 | 63 | "all", | ||
783 | 64 | function(hmac) { | ||
784 | 65 | document.getElementById('results').innerHTML = | ||
785 | 66 | (hmac.errorMsg && hmac.errorMsg.length !== 0) | ||
786 | 67 | ? ("FAIL,"+hmac.errorMsg) : ("OK,"+hmac.result); | ||
787 | 68 | }); | ||
788 | 69 | return true; | ||
789 | 70 | """ | ||
790 | 71 | self.assertThat( | ||
791 | 72 | lambda: self.eval_expression_in_page_unsafe(expression), | ||
792 | 73 | Eventually(Equals(True))) | ||
793 | 74 | |||
794 | 75 | expression = """ | ||
795 | 76 | return document.getElementById('results').innerHTML | ||
796 | 77 | """ | ||
797 | 78 | self.assertThat( | ||
798 | 79 | lambda: self.eval_expression_in_page_unsafe(expression), | ||
799 | 80 | Eventually(Contains("OK,"))) | ||
800 | 81 | |||
801 | 82 | result = self.eval_expression_in_page_unsafe(expression) | ||
802 | 83 | result = result.strip('OK,') | ||
803 | 84 | self.assertThat( | ||
804 | 85 | len(result), | ||
805 | 86 | NotEquals(0)) | ||
806 | 87 | |||
807 | 88 | def test_invalidHmacCall(self): | ||
808 | 89 | self.assertThat( | ||
809 | 90 | lambda: self.eval_expression_in_page_unsafe( | ||
810 | 91 | 'return window.external.getUnityObject("1.0") != null;'), | ||
811 | 92 | Eventually(Equals(True))) | ||
812 | 93 | |||
813 | 94 | expression = """ | ||
814 | 95 | var api = window.external.getUnityObject("1.0"); | ||
815 | 96 | api.ToolsApi.getHmacHash( | ||
816 | 97 | "hi", | ||
817 | 98 | "Invalid", | ||
818 | 99 | "all", | ||
819 | 100 | function(hmac) { | ||
820 | 101 | document.getElementById('results').innerHTML = | ||
821 | 102 | (hmac.errorMsg && hmac.errorMsg.length !== 0) | ||
822 | 103 | ? ("FAIL,"+hmac.errorMsg) : ("OK,"+hmac.result); | ||
823 | 104 | }); | ||
824 | 105 | return true; | ||
825 | 106 | """ | ||
826 | 107 | self.assertThat( | ||
827 | 108 | lambda: self.eval_expression_in_page_unsafe(expression), | ||
828 | 109 | Eventually(Equals(True))) | ||
829 | 110 | |||
830 | 111 | expression = """ | ||
831 | 112 | return document.getElementById('results').innerHTML | ||
832 | 113 | """ | ||
833 | 114 | self.assertThat( | ||
834 | 115 | lambda: self.eval_expression_in_page_unsafe(expression), | ||
835 | 116 | Eventually(Contains("FAIL,"))) | ||
836 | 0 | 117 | ||
837 | === modified file 'tests/autopilot/unity_webapps_qml/tests/test_callbackDispatch.py' | |||
838 | --- tests/autopilot/unity_webapps_qml/tests/test_callbackDispatch.py 2014-07-11 17:13:18 +0000 | |||
839 | +++ tests/autopilot/unity_webapps_qml/tests/test_callbackDispatch.py 2015-03-27 19:32:46 +0000 | |||
840 | @@ -1,5 +1,5 @@ | |||
841 | 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 -*- |
843 | 2 | # Copyright 2014 Canonical | 2 | # Copyright 2014-2015 Canonical |
844 | 3 | # | 3 | # |
845 | 4 | # This program is free software: you can redistribute it and/or modify it | 4 | # This program is free software: you can redistribute it and/or modify it |
846 | 5 | # under the terms of the GNU General Public License version 3, as published | 5 | # under the terms of the GNU General Public License version 3, as published |
847 | @@ -7,22 +7,34 @@ | |||
848 | 7 | 7 | ||
849 | 8 | from __future__ import absolute_import | 8 | from __future__ import absolute_import |
850 | 9 | 9 | ||
851 | 10 | import time | ||
852 | 11 | import os | 10 | import os |
853 | 12 | 11 | ||
855 | 13 | from testtools.matchers import Equals, GreaterThan, NotEquals | 12 | from testtools.matchers import Equals |
856 | 14 | from autopilot.matchers import Eventually | 13 | from autopilot.matchers import Eventually |
857 | 15 | 14 | ||
858 | 16 | from unity_webapps_qml.tests import UnityWebappsTestCaseBase | 15 | from unity_webapps_qml.tests import UnityWebappsTestCaseBase |
859 | 17 | 16 | ||
868 | 18 | LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_callback_dispatch.html') | 17 | LOCAL_HTML_TEST_FILE = "%s/%s" % ( |
869 | 19 | INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_callback_dispatch.html' | 18 | os.path.dirname(os.path.realpath(__file__)), |
870 | 20 | 19 | '../../html/test_webapps_callback_dispatch.html') | |
871 | 21 | LOCAL_JS_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_callback_dispatch_api.js') | 20 | INSTALLED_HTML_TEST_FILE = '/usr/share\ |
872 | 22 | INSTALLED_JS_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_callback_dispatch_api.js' | 21 | /unity-webapps-qml/autopilot-tests\ |
873 | 23 | 22 | /html/test_webapps_callback_dispatch.html' | |
874 | 24 | LOCAL_QML_BACKEND_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../qml/test_webapps_callback_dispatch_api.qml') | 23 | |
875 | 25 | INSTALLED_QML_BACKEND_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/qml/test_webapps_callback_dispatch_api.qml' | 24 | LOCAL_JS_TEST_FILE = "%s/%s" % ( |
876 | 25 | os.path.dirname(os.path.realpath(__file__)), | ||
877 | 26 | '../../html/test_webapps_callback_dispatch_api.js') | ||
878 | 27 | INSTALLED_JS_TEST_FILE = '/usr/share\ | ||
879 | 28 | /unity-webapps-qml/autopilot-tests/html\ | ||
880 | 29 | /test_webapps_callback_dispatch_api.js' | ||
881 | 30 | |||
882 | 31 | LOCAL_QML_BACKEND_TEST_FILE = "%s/%s" % ( | ||
883 | 32 | os.path.dirname(os.path.realpath(__file__)), | ||
884 | 33 | '../../qml/test_webapps_callback_dispatch_api.qml') | ||
885 | 34 | INSTALLED_QML_BACKEND_TEST_FILE = '/usr/share\ | ||
886 | 35 | /unity-webapps-qml/autopilot-tests/qml\ | ||
887 | 36 | /test_webapps_callback_dispatch_api.qml' | ||
888 | 37 | |||
889 | 26 | 38 | ||
890 | 27 | class WebappsCallbackDispatchTestCaseBase(UnityWebappsTestCaseBase): | 39 | class WebappsCallbackDispatchTestCaseBase(UnityWebappsTestCaseBase): |
891 | 28 | def setUp(self): | 40 | def setUp(self): |
892 | @@ -55,6 +67,6 @@ | |||
893 | 55 | Eventually(Equals(True))) | 67 | Eventually(Equals(True))) |
894 | 56 | 68 | ||
895 | 57 | self.assertThat( | 69 | self.assertThat( |
897 | 58 | lambda: self.eval_expression_in_page_unsafe("return document.getElementById('content').innerHTML;"), | 70 | lambda: self.eval_expression_in_page_unsafe( |
898 | 71 | "return document.getElementById('content').innerHTML;"), | ||
899 | 59 | Eventually(Equals('callback-loop-count-reached'))) | 72 | Eventually(Equals('callback-loop-count-reached'))) |
900 | 60 | |||
901 | 61 | 73 | ||
902 | === removed file 'tests/autopilot/unity_webapps_qml/tests/test_hud.py' | |||
903 | --- tests/autopilot/unity_webapps_qml/tests/test_hud.py 2014-04-22 15:40:04 +0000 | |||
904 | +++ tests/autopilot/unity_webapps_qml/tests/test_hud.py 1970-01-01 00:00:00 +0000 | |||
905 | @@ -1,81 +0,0 @@ | |||
906 | 1 | #!/usr/bin/env python | ||
907 | 2 | # Copyright 2013 Canonical | ||
908 | 3 | # | ||
909 | 4 | # This program is free software: you can redistribute it and/or modify it | ||
910 | 5 | # under the terms of the GNU General Public License version 3, as published | ||
911 | 6 | # by the Free Software Foundation. | ||
912 | 7 | |||
913 | 8 | import os | ||
914 | 9 | import time | ||
915 | 10 | |||
916 | 11 | from testtools.matchers import Equals, GreaterThan, NotEquals | ||
917 | 12 | from autopilot.matchers import Eventually | ||
918 | 13 | |||
919 | 14 | from autopilot import platform | ||
920 | 15 | |||
921 | 16 | from unity.emulators.icons import HudLauncherIcon | ||
922 | 17 | from unity.emulators import ensure_unity_is_running | ||
923 | 18 | |||
924 | 19 | from unity_webapps_qml.tests import UnityWebappsTestCaseBase | ||
925 | 20 | |||
926 | 21 | class UnityWebappsHudTestCase(UnityWebappsTestCaseBase): | ||
927 | 22 | LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_hud.html') | ||
928 | 23 | INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_hud.html' | ||
929 | 24 | |||
930 | 25 | def get_html_test_file(self): | ||
931 | 26 | if os.path.exists(self.LOCAL_HTML_TEST_FILE): | ||
932 | 27 | return os.path.abspath(self.LOCAL_HTML_TEST_FILE) | ||
933 | 28 | return self.INSTALLED_HTML_TEST_FILE | ||
934 | 29 | |||
935 | 30 | def setUp(self): | ||
936 | 31 | super(UnityWebappsHudTestCase, self).setUp() | ||
937 | 32 | # On Touch the dbus unity if does is not exposed | ||
938 | 33 | if platform.model() == 'Desktop': | ||
939 | 34 | ensure_unity_is_running() | ||
940 | 35 | self.launch_with_html_filepath(self.get_html_test_file()) | ||
941 | 36 | |||
942 | 37 | def test_addAction(self): | ||
943 | 38 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('actionadded'))) | ||
944 | 39 | |||
945 | 40 | self.unity.hud.ensure_visible() | ||
946 | 41 | self.addCleanup(self.unity.hud.ensure_hidden) | ||
947 | 42 | |||
948 | 43 | self.keyboard.type("Hello") | ||
949 | 44 | self.keyboard.press_and_release("Enter") | ||
950 | 45 | |||
951 | 46 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('content').style.display;"), Eventually(Equals('none'))) | ||
952 | 47 | |||
953 | 48 | def test_clearAction(self): | ||
954 | 49 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('actionadded'))) | ||
955 | 50 | expr = """ | ||
956 | 51 | var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'clearAction', 'args': ['Hello']})}); | ||
957 | 52 | document.dispatchEvent (e); | ||
958 | 53 | return true; | ||
959 | 54 | """ | ||
960 | 55 | self.eval_expression_in_page_unsafe(expr) | ||
961 | 56 | |||
962 | 57 | self.unity.hud.ensure_visible() | ||
963 | 58 | self.addCleanup(self.unity.hud.ensure_hidden) | ||
964 | 59 | |||
965 | 60 | self.keyboard.type("Hello") | ||
966 | 61 | self.keyboard.press_and_release("Enter") | ||
967 | 62 | self.assertThat(self.eval_expression_in_page_unsafe("return document.getElementById('content').style.display;"), NotEquals('none')) | ||
968 | 63 | |||
969 | 64 | def test_clearActions(self): | ||
970 | 65 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('actionadded'))) | ||
971 | 66 | expr = """ | ||
972 | 67 | var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'clearActions', 'args': []})}); | ||
973 | 68 | document.dispatchEvent (e); | ||
974 | 69 | return true; | ||
975 | 70 | """ | ||
976 | 71 | |||
977 | 72 | self.eval_expression_in_page_unsafe(expr) | ||
978 | 73 | |||
979 | 74 | actions = ['Hello', 'Another action'] | ||
980 | 75 | for action in actions: | ||
981 | 76 | self.unity.hud.ensure_visible() | ||
982 | 77 | self.addCleanup(self.unity.hud.ensure_hidden) | ||
983 | 78 | self.keyboard.type(action) | ||
984 | 79 | self.keyboard.press_and_release("Enter") | ||
985 | 80 | |||
986 | 81 | self.assertThat(self.eval_expression_in_page_unsafe("return document.getElementById('content').style.display;"), NotEquals('none')) | ||
987 | 82 | 0 | ||
988 | === modified file 'tests/autopilot/unity_webapps_qml/tests/test_injectedOnWebapp.py' | |||
989 | --- tests/autopilot/unity_webapps_qml/tests/test_injectedOnWebapp.py 2014-04-22 15:40:04 +0000 | |||
990 | +++ tests/autopilot/unity_webapps_qml/tests/test_injectedOnWebapp.py 2015-03-27 19:32:46 +0000 | |||
991 | @@ -1,5 +1,5 @@ | |||
992 | 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 -*- |
994 | 2 | # Copyright 2013 Canonical | 2 | # Copyright 2013-2015 Canonical |
995 | 3 | # | 3 | # |
996 | 4 | # This program is free software: you can redistribute it and/or modify it | 4 | # This program is free software: you can redistribute it and/or modify it |
997 | 5 | # under the terms of the GNU General Public License version 3, as published | 5 | # under the terms of the GNU General Public License version 3, as published |
998 | @@ -7,51 +7,75 @@ | |||
999 | 7 | 7 | ||
1000 | 8 | from __future__ import absolute_import | 8 | from __future__ import absolute_import |
1001 | 9 | 9 | ||
1002 | 10 | import time | ||
1003 | 11 | import os | 10 | import os |
1004 | 12 | 11 | ||
1006 | 13 | from testtools.matchers import Equals, GreaterThan, NotEquals | 12 | from testtools.matchers import Equals |
1007 | 14 | from autopilot.matchers import Eventually | 13 | from autopilot.matchers import Eventually |
1008 | 15 | 14 | ||
1009 | 16 | from unity_webapps_qml.tests import UnityWebappsTestCaseBase | 15 | from unity_webapps_qml.tests import UnityWebappsTestCaseBase |
1010 | 17 | 16 | ||
1011 | 17 | LOCAL_HTML_TEST_FILE = "%s/%s" % ( | ||
1012 | 18 | os.path.dirname(os.path.realpath(__file__)), | ||
1013 | 19 | '../../html/test_webapps_api_injected.html') | ||
1014 | 20 | INSTALLED_HTML_TEST_FILE = '/usr/share\ | ||
1015 | 21 | /unity-webapps-qml/autopilot-tests/html/test_webapps_api_injected.html' | ||
1016 | 22 | |||
1017 | 23 | |||
1018 | 18 | class UnityWebappsApiInjectedTestCaseBase(UnityWebappsTestCaseBase): | 24 | class UnityWebappsApiInjectedTestCaseBase(UnityWebappsTestCaseBase): |
1019 | 19 | LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_api_injected.html') | ||
1020 | 20 | |||
1021 | 21 | INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_api_injected.html' | ||
1022 | 22 | 25 | ||
1023 | 23 | def get_html_test_file(self): | 26 | def get_html_test_file(self): |
1027 | 24 | if os.path.exists(self.LOCAL_HTML_TEST_FILE): | 27 | if os.path.exists(LOCAL_HTML_TEST_FILE): |
1028 | 25 | return os.path.abspath(self.LOCAL_HTML_TEST_FILE) | 28 | return os.path.abspath(LOCAL_HTML_TEST_FILE) |
1029 | 26 | return self.INSTALLED_HTML_TEST_FILE | 29 | return INSTALLED_HTML_TEST_FILE |
1030 | 27 | 30 | ||
1031 | 28 | def setUp(self): | 31 | def setUp(self): |
1032 | 29 | super(UnityWebappsApiInjectedTestCaseBase, self).setUp() | 32 | super(UnityWebappsApiInjectedTestCaseBase, self).setUp() |
1033 | 30 | self.launch_with_html_filepath(self.get_html_test_file()) | 33 | self.launch_with_html_filepath(self.get_html_test_file()) |
1034 | 31 | 34 | ||
1035 | 32 | def test_getUnityObjectFound(self): | 35 | def test_getUnityObjectFound(self): |
1037 | 33 | self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null'), Eventually(Equals(True))) | 36 | self.assertThat( |
1038 | 37 | lambda: self.eval_expression_in_page_unsafe( | ||
1039 | 38 | 'return window.external.getUnityObject("1.0") != null'), | ||
1040 | 39 | Eventually(Equals(True))) | ||
1041 | 34 | 40 | ||
1042 | 35 | def test_actionsApiFound(self): | 41 | def test_actionsApiFound(self): |
1044 | 36 | self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True))) | 42 | self.assertThat( |
1045 | 43 | lambda: self.eval_expression_in_page_unsafe( | ||
1046 | 44 | 'return window.external.getUnityObject("1.0") != null;'), | ||
1047 | 45 | Eventually(Equals(True))) | ||
1048 | 37 | 46 | ||
1049 | 38 | expression = """ | 47 | expression = """ |
1050 | 39 | var unity = window.external.getUnityObject("1.0"); | 48 | var unity = window.external.getUnityObject("1.0"); |
1052 | 40 | return unity.addAction != null && unity.clearActions != null && unity.clearAction != null; | 49 | return unity.addAction != null && |
1053 | 50 | unity.clearActions != null && | ||
1054 | 51 | unity.clearAction != null; | ||
1055 | 41 | """ | 52 | """ |
1057 | 42 | self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals(True))) | 53 | self.assertThat( |
1058 | 54 | lambda: self.eval_expression_in_page_unsafe( | ||
1059 | 55 | expression), | ||
1060 | 56 | Eventually(Equals(True))) | ||
1061 | 43 | 57 | ||
1062 | 44 | def test_notificationApiFound(self): | 58 | def test_notificationApiFound(self): |
1064 | 45 | self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True))) | 59 | self.assertThat( |
1065 | 60 | lambda: self.eval_expression_in_page_unsafe( | ||
1066 | 61 | 'return window.external.getUnityObject("1.0") != null;'), | ||
1067 | 62 | Eventually(Equals(True))) | ||
1068 | 46 | 63 | ||
1069 | 47 | expression = """ | 64 | expression = """ |
1070 | 48 | var unity = window.external.getUnityObject("1.0"); | 65 | var unity = window.external.getUnityObject("1.0"); |
1072 | 49 | return unity.Notification != null && unity.Notification.showNotification != null; | 66 | return unity.Notification != null && |
1073 | 67 | unity.Notification.showNotification != null; | ||
1074 | 50 | """ | 68 | """ |
1076 | 51 | self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals(True))) | 69 | self.assertThat( |
1077 | 70 | lambda: self.eval_expression_in_page_unsafe( | ||
1078 | 71 | expression), | ||
1079 | 72 | Eventually(Equals(True))) | ||
1080 | 52 | 73 | ||
1081 | 53 | def test_messagingIndicatorApiFound(self): | 74 | def test_messagingIndicatorApiFound(self): |
1083 | 54 | self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True))) | 75 | self.assertThat( |
1084 | 76 | lambda: self.eval_expression_in_page_unsafe( | ||
1085 | 77 | 'return window.external.getUnityObject("1.0") != null;'), | ||
1086 | 78 | Eventually(Equals(True))) | ||
1087 | 55 | 79 | ||
1088 | 56 | expression = """ | 80 | expression = """ |
1089 | 57 | var unity = window.external.getUnityObject("1.0"); | 81 | var unity = window.external.getUnityObject("1.0"); |
1090 | @@ -61,15 +85,23 @@ | |||
1091 | 61 | unity.MessagingIndicator.clearIndicators != null && | 85 | unity.MessagingIndicator.clearIndicators != null && |
1092 | 62 | unity.MessagingIndicator.showIndicator != null; | 86 | unity.MessagingIndicator.showIndicator != null; |
1093 | 63 | """ | 87 | """ |
1095 | 64 | self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals(True))) | 88 | self.assertThat( |
1096 | 89 | lambda: self.eval_expression_in_page_unsafe( | ||
1097 | 90 | expression), | ||
1098 | 91 | Eventually(Equals(True))) | ||
1099 | 65 | 92 | ||
1100 | 66 | def test_ubuntuReadyEventSent(self): | 93 | def test_ubuntuReadyEventSent(self): |
1102 | 67 | self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True))) | 94 | self.assertThat( |
1103 | 95 | lambda: self.eval_expression_in_page_unsafe( | ||
1104 | 96 | 'return window.external.getUnityObject("1.0") != null;'), | ||
1105 | 97 | Eventually(Equals(True))) | ||
1106 | 68 | 98 | ||
1107 | 69 | expression = """ | 99 | expression = """ |
1109 | 70 | var api_ready_count = window.localStorage['ubuntu-webapps-api-ready-key']; | 100 | var api_ready_count = |
1110 | 101 | window.localStorage['ubuntu-webapps-api-ready-key']; | ||
1111 | 71 | return api_ready_count != null && api_ready_count > 0; | 102 | return api_ready_count != null && api_ready_count > 0; |
1112 | 72 | """ | 103 | """ |
1116 | 73 | self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals(True))) | 104 | self.assertThat( |
1117 | 74 | 105 | lambda: self.eval_expression_in_page_unsafe( | |
1118 | 75 | 106 | expression), | |
1119 | 107 | Eventually(Equals(True))) | ||
1120 | 76 | 108 | ||
1121 | === modified file 'tests/autopilot/unity_webapps_qml/tests/test_installedWebapp.py' | |||
1122 | --- tests/autopilot/unity_webapps_qml/tests/test_installedWebapp.py 2014-07-16 20:15:17 +0000 | |||
1123 | +++ tests/autopilot/unity_webapps_qml/tests/test_installedWebapp.py 2015-03-27 19:32:46 +0000 | |||
1124 | @@ -1,5 +1,5 @@ | |||
1125 | 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 -*- |
1127 | 2 | # Copyright 2013 Canonical | 2 | # Copyright 2013-2015 Canonical |
1128 | 3 | # | 3 | # |
1129 | 4 | # This program is free software: you can redistribute it and/or modify it | 4 | # This program is free software: you can redistribute it and/or modify it |
1130 | 5 | # under the terms of the GNU General Public License version 3, as published | 5 | # under the terms of the GNU General Public License version 3, as published |
1131 | @@ -7,18 +7,22 @@ | |||
1132 | 7 | 7 | ||
1133 | 8 | from __future__ import absolute_import | 8 | from __future__ import absolute_import |
1134 | 9 | 9 | ||
1135 | 10 | import time | ||
1136 | 11 | import os | 10 | import os |
1137 | 11 | import unittest | ||
1138 | 12 | 12 | ||
1140 | 13 | from testtools.matchers import Equals, GreaterThan, NotEquals | 13 | from testtools.matchers import Equals |
1141 | 14 | from autopilot.matchers import Eventually | 14 | from autopilot.matchers import Eventually |
1142 | 15 | 15 | ||
1143 | 16 | from unity_webapps_qml.tests import WebappsTestCaseBaseWithLocalHttpContentBase | 16 | from unity_webapps_qml.tests import WebappsTestCaseBaseWithLocalHttpContentBase |
1144 | 17 | 17 | ||
1146 | 18 | LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../data') | 18 | LOCAL_HTML_TEST_FILE = "%s/%s" % ( |
1147 | 19 | os.path.dirname(os.path.realpath(__file__)), | ||
1148 | 20 | '../../data') | ||
1149 | 19 | INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/data' | 21 | INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/data' |
1150 | 20 | 22 | ||
1152 | 21 | class InstalledWebappsTestCaseBase(WebappsTestCaseBaseWithLocalHttpContentBase): | 23 | |
1153 | 24 | class InstalledWebappsTestCaseBase( | ||
1154 | 25 | WebappsTestCaseBaseWithLocalHttpContentBase): | ||
1155 | 22 | def setUp(self): | 26 | def setUp(self): |
1156 | 23 | super(InstalledWebappsTestCaseBase, self).setUp() | 27 | super(InstalledWebappsTestCaseBase, self).setUp() |
1157 | 24 | 28 | ||
1158 | @@ -30,34 +34,64 @@ | |||
1159 | 30 | def test_normalWebappFound(self): | 34 | def test_normalWebappFound(self): |
1160 | 31 | self.launch_with_webapp('Normal', self.get_webapp_install_folder()) | 35 | self.launch_with_webapp('Normal', self.get_webapp_install_folder()) |
1161 | 32 | 36 | ||
1163 | 33 | self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True))) | 37 | self.assertThat( |
1164 | 38 | lambda: self.eval_expression_in_page_unsafe( | ||
1165 | 39 | 'return window.external.getUnityObject("1.0") != null;'), | ||
1166 | 40 | Eventually(Equals(True))) | ||
1167 | 34 | 41 | ||
1168 | 35 | expression = """ | 42 | expression = """ |
1169 | 36 | var contentElement = document.getElementById('content'); | 43 | var contentElement = document.getElementById('content'); |
1170 | 37 | return contentElement.innerHTML; | 44 | return contentElement.innerHTML; |
1171 | 38 | """ | 45 | """ |
1173 | 39 | self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals("WebApp Script Injected"))) | 46 | self.assertThat( |
1174 | 47 | lambda: self.eval_expression_in_page_unsafe( | ||
1175 | 48 | expression), | ||
1176 | 49 | Eventually(Equals("WebApp Script Injected"))) | ||
1177 | 40 | 50 | ||
1178 | 41 | def test_webappWithUAOverrideFound(self): | 51 | def test_webappWithUAOverrideFound(self): |
1181 | 42 | self.launch_with_webapp('AlteredUAWebapp', self.get_webapp_install_folder(), True) | 52 | self.launch_with_webapp( |
1182 | 43 | self.assertThat(lambda: self.eval_expression_in_page_unsafe('return navigator.userAgent;'), Eventually(Equals("My Override"))) | 53 | 'AlteredUAWebapp', |
1183 | 54 | self.get_webapp_install_folder(), | ||
1184 | 55 | True) | ||
1185 | 56 | self.assertThat( | ||
1186 | 57 | lambda: self.eval_expression_in_page_unsafe( | ||
1187 | 58 | 'return navigator.userAgent;'), | ||
1188 | 59 | Eventually(Equals("My Override"))) | ||
1189 | 44 | 60 | ||
1190 | 45 | def test_webappFoundWithSpecialWebappPropertiesFile(self): | 61 | def test_webappFoundWithSpecialWebappPropertiesFile(self): |
1192 | 46 | self.launch_with_webapp('ExtendedWebappProperties', self.get_webapp_install_folder() + '/all-in-same-folder') | 62 | self.launch_with_webapp( |
1193 | 63 | 'ExtendedWebappProperties', | ||
1194 | 64 | self.get_webapp_install_folder() + '/all-in-same-folder') | ||
1195 | 47 | 65 | ||
1197 | 48 | self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True))) | 66 | self.assertThat( |
1198 | 67 | lambda: self.eval_expression_in_page_unsafe( | ||
1199 | 68 | 'return window.external.getUnityObject("1.0") != null;'), | ||
1200 | 69 | Eventually(Equals(True))) | ||
1201 | 49 | 70 | ||
1202 | 50 | expression = """ | 71 | expression = """ |
1203 | 51 | var contentElement = document.getElementById('content'); | 72 | var contentElement = document.getElementById('content'); |
1204 | 52 | return contentElement.innerHTML; | 73 | return contentElement.innerHTML; |
1205 | 53 | """ | 74 | """ |
1207 | 54 | self.assertThat(lambda: self.eval_expression_in_page_unsafe(expression), Eventually(Equals("WebApp Script Injected"))) | 75 | self.assertThat( |
1208 | 76 | lambda: self.eval_expression_in_page_unsafe(expression), | ||
1209 | 77 | Eventually(Equals("WebApp Script Injected"))) | ||
1210 | 55 | 78 | ||
1211 | 79 | @unittest.skip("Demonstrates some flackiness") | ||
1212 | 56 | def test_webappPropertiesFileWithUA(self): | 80 | def test_webappPropertiesFileWithUA(self): |
1215 | 57 | self.launch_with_webapp('ExtendedWebappProperties', self.get_webapp_install_folder() + '/all-in-same-folder', True) | 81 | self.launch_with_webapp( |
1216 | 58 | self.assertThat(lambda: self.eval_expression_in_page_unsafe('return navigator.userAgent;'), Eventually(Equals("My Override"))) | 82 | 'ExtendedWebappProperties', |
1217 | 83 | self.get_webapp_install_folder() + '/all-in-same-folder', | ||
1218 | 84 | True) | ||
1219 | 85 | self.assertThat( | ||
1220 | 86 | lambda: self.eval_expression_in_page_unsafe( | ||
1221 | 87 | 'return navigator.userAgent;'), | ||
1222 | 88 | Eventually(Equals("My Override"))) | ||
1223 | 59 | 89 | ||
1224 | 60 | def test_webappPropertiesNameUpdated(self): | 90 | def test_webappPropertiesNameUpdated(self): |
1228 | 61 | self.launch_with_webapp('', self.get_webapp_install_folder() + '/all-in-same-folder') | 91 | self.launch_with_webapp( |
1229 | 62 | self.assertThat(lambda: self.eval_expression_in_page_unsafe('return window.external.getUnityObject("1.0") != null;'), Eventually(Equals(True))) | 92 | '', |
1230 | 63 | 93 | self.get_webapp_install_folder() + '/all-in-same-folder') | |
1231 | 94 | self.assertThat( | ||
1232 | 95 | lambda: self.eval_expression_in_page_unsafe( | ||
1233 | 96 | 'return window.external.getUnityObject("1.0") != null;'), | ||
1234 | 97 | Eventually(Equals(True))) | ||
1235 | 64 | 98 | ||
1236 | === removed file 'tests/autopilot/unity_webapps_qml/tests/test_launcher.py' | |||
1237 | --- tests/autopilot/unity_webapps_qml/tests/test_launcher.py 2013-09-23 19:59:29 +0000 | |||
1238 | +++ tests/autopilot/unity_webapps_qml/tests/test_launcher.py 1970-01-01 00:00:00 +0000 | |||
1239 | @@ -1,83 +0,0 @@ | |||
1240 | 1 | #!/usr/bin/env python | ||
1241 | 2 | # Copyright 2013 Canonical | ||
1242 | 3 | # | ||
1243 | 4 | # This program is free software: you can redistribute it and/or modify it | ||
1244 | 5 | # under the terms of the GNU General Public License version 3, as published | ||
1245 | 6 | # by the Free Software Foundation. | ||
1246 | 7 | |||
1247 | 8 | import os | ||
1248 | 9 | import time | ||
1249 | 10 | |||
1250 | 11 | from gi.repository import Unity, GObject | ||
1251 | 12 | |||
1252 | 13 | from testtools.matchers import Equals, GreaterThan, NotEquals | ||
1253 | 14 | from testtools import skipUnless | ||
1254 | 15 | |||
1255 | 16 | from autopilot import platform | ||
1256 | 17 | from autopilot.matchers import Eventually | ||
1257 | 18 | |||
1258 | 19 | from unity.emulators.icons import HudLauncherIcon | ||
1259 | 20 | from unity.emulators import ensure_unity_is_running | ||
1260 | 21 | |||
1261 | 22 | from unity_webapps_qml.tests import UnityWebappsTestCaseBase | ||
1262 | 23 | |||
1263 | 24 | class UnityWebappsLauncherTestCase(UnityWebappsTestCaseBase): | ||
1264 | 25 | LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_launcher.html') | ||
1265 | 26 | INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_launcher.html' | ||
1266 | 27 | |||
1267 | 28 | def get_html_test_file(self): | ||
1268 | 29 | if os.path.exists(self.LOCAL_HTML_TEST_FILE): | ||
1269 | 30 | return os.path.abspath(self.LOCAL_HTML_TEST_FILE) | ||
1270 | 31 | return self.INSTALLED_HTML_TEST_FILE | ||
1271 | 32 | |||
1272 | 33 | def setUp(self): | ||
1273 | 34 | super(UnityWebappsLauncherTestCase, self).setUp() | ||
1274 | 35 | # On Touch the dbus unity if does is not exposed | ||
1275 | 36 | if platform.model() == 'Desktop': | ||
1276 | 37 | ensure_unity_is_running() | ||
1277 | 38 | self.launch_with_html_filepath(self.get_html_test_file()) | ||
1278 | 39 | |||
1279 | 40 | @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop") | ||
1280 | 41 | def test_checkCounts(self): | ||
1281 | 42 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('launcher-updated'))) | ||
1282 | 43 | |||
1283 | 44 | launcher_icon = self.unity.launcher.model.get_icon(desktop_id='unitywebappsqmllauncher.desktop') | ||
1284 | 45 | self.assertThat(launcher_icon, NotEquals(None)) | ||
1285 | 46 | |||
1286 | 47 | expr = """ | ||
1287 | 48 | document.addEventListener('unity-webapps-do-call-response', function(e) { | ||
1288 | 49 | var response = e.detail; | ||
1289 | 50 | document.getElementById('status').innerHTML = '' + e.detail; | ||
1290 | 51 | }); | ||
1291 | 52 | |||
1292 | 53 | var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'Launcher.__get', 'with_callback': true, 'args': ['count']})}); | ||
1293 | 54 | document.dispatchEvent (e); | ||
1294 | 55 | return true; | ||
1295 | 56 | """ | ||
1296 | 57 | self.eval_expression_in_page_unsafe(expr) | ||
1297 | 58 | |||
1298 | 59 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('42'))) | ||
1299 | 60 | |||
1300 | 61 | # self.assertThat(launcher.get_property('progress'), Equals(0.09375)) | ||
1301 | 62 | |||
1302 | 63 | @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop") | ||
1303 | 64 | def test_checkProgress(self): | ||
1304 | 65 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('launcher-updated'))) | ||
1305 | 66 | |||
1306 | 67 | launcher_icon = self.unity.launcher.model.get_icon(desktop_id='unitywebappsqmllauncher.desktop') | ||
1307 | 68 | self.assertThat(launcher_icon, NotEquals(None)) | ||
1308 | 69 | |||
1309 | 70 | expr = """ | ||
1310 | 71 | document.addEventListener('unity-webapps-do-call-response', function(e) { | ||
1311 | 72 | var response = e.detail; | ||
1312 | 73 | document.getElementById('status').innerHTML = '' + e.detail; | ||
1313 | 74 | }); | ||
1314 | 75 | |||
1315 | 76 | var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'Launcher.__get', 'with_callback': true, 'args': ['progress']})}); | ||
1316 | 77 | document.dispatchEvent (e); | ||
1317 | 78 | return true; | ||
1318 | 79 | """ | ||
1319 | 80 | self.eval_expression_in_page_unsafe(expr) | ||
1320 | 81 | |||
1321 | 82 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('0.09375'))) | ||
1322 | 83 | |||
1323 | 84 | 0 | ||
1324 | === removed file 'tests/autopilot/unity_webapps_qml/tests/test_mediaplayer.py' | |||
1325 | --- tests/autopilot/unity_webapps_qml/tests/test_mediaplayer.py 2013-09-23 19:59:29 +0000 | |||
1326 | +++ tests/autopilot/unity_webapps_qml/tests/test_mediaplayer.py 1970-01-01 00:00:00 +0000 | |||
1327 | @@ -1,111 +0,0 @@ | |||
1328 | 1 | #!/usr/bin/env python | ||
1329 | 2 | # Copyright 2013 Canonical | ||
1330 | 3 | # | ||
1331 | 4 | # This program is free software: you can redistribute it and/or modify it | ||
1332 | 5 | # under the terms of the GNU General Public License version 3, as published | ||
1333 | 6 | # by the Free Software Foundation. | ||
1334 | 7 | |||
1335 | 8 | import os | ||
1336 | 9 | import time | ||
1337 | 10 | |||
1338 | 11 | from gi.repository import Unity, GObject | ||
1339 | 12 | |||
1340 | 13 | from testtools.matchers import Equals, GreaterThan, NotEquals | ||
1341 | 14 | from testtools import skipUnless | ||
1342 | 15 | |||
1343 | 16 | from autopilot import platform | ||
1344 | 17 | from autopilot.matchers import Eventually | ||
1345 | 18 | |||
1346 | 19 | from unity.emulators import ensure_unity_is_running | ||
1347 | 20 | |||
1348 | 21 | from unity_webapps_qml.tests import UnityWebappsTestCaseBase | ||
1349 | 22 | |||
1350 | 23 | |||
1351 | 24 | class UnityWebappsMediaplayerTestCase(UnityWebappsTestCaseBase): | ||
1352 | 25 | LOCAL_HTML_TEST_FILE = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), '../../html/test_webapps_mediaplayer.html') | ||
1353 | 26 | INSTALLED_HTML_TEST_FILE = '/usr/share/unity-webapps-qml/autopilot-tests/html/test_webapps_mediaplayer.html' | ||
1354 | 27 | |||
1355 | 28 | def get_html_test_file(self): | ||
1356 | 29 | if os.path.exists(self.LOCAL_HTML_TEST_FILE): | ||
1357 | 30 | return os.path.abspath(self.LOCAL_HTML_TEST_FILE) | ||
1358 | 31 | return self.INSTALLED_HTML_TEST_FILE | ||
1359 | 32 | |||
1360 | 33 | def setUp(self): | ||
1361 | 34 | super(UnityWebappsMediaplayerTestCase, self).setUp() | ||
1362 | 35 | # On Touch the dbus unity if does is not exposed | ||
1363 | 36 | if platform.model() == 'Desktop': | ||
1364 | 37 | ensure_unity_is_running() | ||
1365 | 38 | self.launch_with_html_filepath(self.get_html_test_file()) | ||
1366 | 39 | |||
1367 | 40 | @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop") | ||
1368 | 41 | def test_checkInitialSetTrack(self): | ||
1369 | 42 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('mediaplayer-updated'))) | ||
1370 | 43 | |||
1371 | 44 | expr = """ | ||
1372 | 45 | document.addEventListener('unity-webapps-do-call-response', function(e) { | ||
1373 | 46 | var response = e.detail; | ||
1374 | 47 | document.getElementById('status').innerHTML = '' + e.detail; | ||
1375 | 48 | }); | ||
1376 | 49 | |||
1377 | 50 | var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['track']})}); | ||
1378 | 51 | document.dispatchEvent (e); | ||
1379 | 52 | return true; | ||
1380 | 53 | """ | ||
1381 | 54 | self.eval_expression_in_page_unsafe(expr) | ||
1382 | 55 | |||
1383 | 56 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('TXlBcnRpc3Q=;TXlUaXRsZQ==;TXlBbGJ1bQ=='))) | ||
1384 | 57 | |||
1385 | 58 | @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop") | ||
1386 | 59 | def test_checkInitialSetCanGoNext(self): | ||
1387 | 60 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('mediaplayer-updated'))) | ||
1388 | 61 | |||
1389 | 62 | expr = """ | ||
1390 | 63 | document.addEventListener('unity-webapps-do-call-response', function(e) { | ||
1391 | 64 | var response = e.detail; | ||
1392 | 65 | document.getElementById('status').innerHTML = '' + e.detail; | ||
1393 | 66 | }); | ||
1394 | 67 | |||
1395 | 68 | var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['can-go-next']})}); | ||
1396 | 69 | document.dispatchEvent (e); | ||
1397 | 70 | return true; | ||
1398 | 71 | """ | ||
1399 | 72 | self.eval_expression_in_page_unsafe(expr) | ||
1400 | 73 | |||
1401 | 74 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('true'))) | ||
1402 | 75 | |||
1403 | 76 | @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop") | ||
1404 | 77 | def test_checkInitialSetCanGoPrevious(self): | ||
1405 | 78 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('mediaplayer-updated'))) | ||
1406 | 79 | |||
1407 | 80 | expr = """ | ||
1408 | 81 | document.addEventListener('unity-webapps-do-call-response', function(e) { | ||
1409 | 82 | var response = e.detail; | ||
1410 | 83 | document.getElementById('status').innerHTML = '' + e.detail; | ||
1411 | 84 | }); | ||
1412 | 85 | |||
1413 | 86 | var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['can-go-previous']})}); | ||
1414 | 87 | document.dispatchEvent (e); | ||
1415 | 88 | return true; | ||
1416 | 89 | """ | ||
1417 | 90 | self.eval_expression_in_page_unsafe(expr) | ||
1418 | 91 | |||
1419 | 92 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('true'))) | ||
1420 | 93 | |||
1421 | 94 | @skipUnless(platform.model() == 'Desktop', "Only runs on the Desktop") | ||
1422 | 95 | def test_checkInitialSetCanPlay(self): | ||
1423 | 96 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('mediaplayer-updated'))) | ||
1424 | 97 | |||
1425 | 98 | expr = """ | ||
1426 | 99 | document.addEventListener('unity-webapps-do-call-response', function(e) { | ||
1427 | 100 | var response = e.detail; | ||
1428 | 101 | document.getElementById('status').innerHTML = '' + e.detail; | ||
1429 | 102 | }); | ||
1430 | 103 | |||
1431 | 104 | var e = new CustomEvent ("unity-webapps-do-call", {"detail": JSON.stringify({"name": 'MediaPlayer.__get', 'with_callback': true, 'args': ['can-play']})}); | ||
1432 | 105 | document.dispatchEvent (e); | ||
1433 | 106 | return true; | ||
1434 | 107 | """ | ||
1435 | 108 | self.eval_expression_in_page_unsafe(expr) | ||
1436 | 109 | |||
1437 | 110 | self.assertThat(lambda: self.eval_expression_in_page_unsafe("return document.getElementById('status').innerHTML;"), Eventually(Equals('true'))) | ||
1438 | 111 |