Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <meta charset="utf-8"> |
michael@0 | 5 | <title>Test for DataStore - bug 976311</title> |
michael@0 | 6 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <div id="container"></div> |
michael@0 | 11 | <script type="application/javascript;version=1.7"> |
michael@0 | 12 | |
michael@0 | 13 | var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_bug976311.html&template=file_bug976311.template.webapp'; |
michael@0 | 14 | var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_bug976311.html&template=file_bug976311.template.webapp'; |
michael@0 | 15 | var gApps = []; |
michael@0 | 16 | |
michael@0 | 17 | function cbError() { |
michael@0 | 18 | ok(false, "Error callback invoked"); |
michael@0 | 19 | finish(); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function installApp(aApp) { |
michael@0 | 23 | var request = navigator.mozApps.install(aApp); |
michael@0 | 24 | request.onerror = cbError; |
michael@0 | 25 | request.onsuccess = function() { |
michael@0 | 26 | gApps.push(request.result); |
michael@0 | 27 | runTest(); |
michael@0 | 28 | } |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | function uninstallApps() { |
michael@0 | 32 | if (!gApps.length) { |
michael@0 | 33 | ok(true, "All done!"); |
michael@0 | 34 | runTest(); |
michael@0 | 35 | return; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | var app = gApps.pop(); |
michael@0 | 39 | var request = navigator.mozApps.mgmt.uninstall(app); |
michael@0 | 40 | request.onerror = cbError; |
michael@0 | 41 | request.onsuccess = uninstallApps; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | |
michael@0 | 45 | function testApp() { |
michael@0 | 46 | var ifr = document.createElement('iframe'); |
michael@0 | 47 | ifr.setAttribute('mozbrowser', 'true'); |
michael@0 | 48 | ifr.setAttribute('mozapp', gApps[0].manifestURL); |
michael@0 | 49 | ifr.setAttribute('src', gApps[0].manifest.launch_path); |
michael@0 | 50 | var domParent = document.getElementById('container'); |
michael@0 | 51 | |
michael@0 | 52 | // Set us up to listen for messages from the app. |
michael@0 | 53 | var listener = function(e) { |
michael@0 | 54 | var message = e.detail.message; |
michael@0 | 55 | if (/^OK/.exec(message)) { |
michael@0 | 56 | ok(true, "Message from app: " + message); |
michael@0 | 57 | } else if (/KO/.exec(message)) { |
michael@0 | 58 | ok(false, "Message from app: " + message); |
michael@0 | 59 | } else if (/DONE/.exec(message)) { |
michael@0 | 60 | ok(true, "Messaging from app complete"); |
michael@0 | 61 | ifr.removeEventListener('mozbrowsershowmodalprompt', listener); |
michael@0 | 62 | domParent.removeChild(ifr); |
michael@0 | 63 | runTest(); |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | // This event is triggered when the app calls "alert". |
michael@0 | 68 | ifr.addEventListener('mozbrowsershowmodalprompt', listener, false); |
michael@0 | 69 | domParent.appendChild(ifr); |
michael@0 | 70 | |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | var tests = [ |
michael@0 | 74 | // Permissions |
michael@0 | 75 | function() { |
michael@0 | 76 | SpecialPowers.pushPermissions( |
michael@0 | 77 | [{ "type": "browser", "allow": 1, "context": document }, |
michael@0 | 78 | { "type": "embed-apps", "allow": 1, "context": document }, |
michael@0 | 79 | { "type": "webapps-manage", "allow": 1, "context": document }], runTest); |
michael@0 | 80 | }, |
michael@0 | 81 | |
michael@0 | 82 | // Preferences |
michael@0 | 83 | function() { |
michael@0 | 84 | SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true], |
michael@0 | 85 | ["dom.testing.ignore_ipc_principal", true], |
michael@0 | 86 | ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest); |
michael@0 | 87 | }, |
michael@0 | 88 | |
michael@0 | 89 | function() { |
michael@0 | 90 | SpecialPowers.setAllAppsLaunchable(true); |
michael@0 | 91 | SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true); |
michael@0 | 92 | runTest(); |
michael@0 | 93 | }, |
michael@0 | 94 | |
michael@0 | 95 | // No confirmation needed when an app is installed |
michael@0 | 96 | function() { |
michael@0 | 97 | SpecialPowers.autoConfirmAppInstall(runTest); |
michael@0 | 98 | }, |
michael@0 | 99 | |
michael@0 | 100 | // Installing the app1 |
michael@0 | 101 | function() { installApp(gHostedManifestURL); }, |
michael@0 | 102 | |
michael@0 | 103 | // Installing the app2 |
michael@0 | 104 | function() { installApp(gHostedManifestURL2); }, |
michael@0 | 105 | |
michael@0 | 106 | // Run tests in app |
michael@0 | 107 | testApp, |
michael@0 | 108 | |
michael@0 | 109 | // Uninstall the apps |
michael@0 | 110 | uninstallApps |
michael@0 | 111 | ]; |
michael@0 | 112 | |
michael@0 | 113 | function runTest() { |
michael@0 | 114 | if (!tests.length) { |
michael@0 | 115 | finish(); |
michael@0 | 116 | return; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | var test = tests.shift(); |
michael@0 | 120 | test(); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | function finish() { |
michael@0 | 124 | SimpleTest.finish(); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | if (SpecialPowers.isMainProcess()) { |
michael@0 | 128 | SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm"); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 132 | runTest(); |
michael@0 | 133 | </script> |
michael@0 | 134 | </body> |
michael@0 | 135 | </html> |