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