Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 - basic operation on a readonly db</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_basic.html'; |
michael@0 | 14 | var gApp; |
michael@0 | 15 | |
michael@0 | 16 | function cbError() { |
michael@0 | 17 | ok(false, "Error callback invoked"); |
michael@0 | 18 | finish(); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function installApp() { |
michael@0 | 22 | var request = navigator.mozApps.install(gHostedManifestURL); |
michael@0 | 23 | request.onerror = cbError; |
michael@0 | 24 | request.onsuccess = function() { |
michael@0 | 25 | gApp = request.result; |
michael@0 | 26 | runTest(); |
michael@0 | 27 | } |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function uninstallApp() { |
michael@0 | 31 | // Uninstall the app. |
michael@0 | 32 | var request = navigator.mozApps.mgmt.uninstall(gApp); |
michael@0 | 33 | request.onerror = cbError; |
michael@0 | 34 | request.onsuccess = function() { |
michael@0 | 35 | // All done. |
michael@0 | 36 | info("All done"); |
michael@0 | 37 | runTest(); |
michael@0 | 38 | } |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function testApp() { |
michael@0 | 42 | var ifr = document.createElement('iframe'); |
michael@0 | 43 | ifr.setAttribute('mozbrowser', 'true'); |
michael@0 | 44 | ifr.setAttribute('mozapp', gApp.manifestURL); |
michael@0 | 45 | ifr.setAttribute('src', gApp.manifest.launch_path); |
michael@0 | 46 | var domParent = document.getElementById('container'); |
michael@0 | 47 | |
michael@0 | 48 | // Set us up to listen for messages from the app. |
michael@0 | 49 | var listener = function(e) { |
michael@0 | 50 | var message = e.detail.message; |
michael@0 | 51 | if (/^OK/.exec(message)) { |
michael@0 | 52 | ok(true, "Message from app: " + message); |
michael@0 | 53 | } else if (/KO/.exec(message)) { |
michael@0 | 54 | ok(false, "Message from app: " + message); |
michael@0 | 55 | } else if (/DONE/.exec(message)) { |
michael@0 | 56 | ok(true, "Messaging from app complete"); |
michael@0 | 57 | ifr.removeEventListener('mozbrowsershowmodalprompt', listener); |
michael@0 | 58 | domParent.removeChild(ifr); |
michael@0 | 59 | runTest(); |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | // This event is triggered when the app calls "alert". |
michael@0 | 64 | ifr.addEventListener('mozbrowsershowmodalprompt', listener, false); |
michael@0 | 65 | domParent.appendChild(ifr); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | var tests = [ |
michael@0 | 69 | // Permissions |
michael@0 | 70 | function() { |
michael@0 | 71 | SpecialPowers.pushPermissions( |
michael@0 | 72 | [{ "type": "browser", "allow": 1, "context": document }, |
michael@0 | 73 | { "type": "embed-apps", "allow": 1, "context": document }, |
michael@0 | 74 | { "type": "webapps-manage", "allow": 1, "context": document }], runTest); |
michael@0 | 75 | }, |
michael@0 | 76 | |
michael@0 | 77 | // Preferences |
michael@0 | 78 | function() { |
michael@0 | 79 | SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true], |
michael@0 | 80 | ["dom.ipc.browser_frames.oop_by_default", true], |
michael@0 | 81 | ["dom.testing.ignore_ipc_principal", true], |
michael@0 | 82 | ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest); |
michael@0 | 83 | }, |
michael@0 | 84 | |
michael@0 | 85 | function() { |
michael@0 | 86 | SpecialPowers.setAllAppsLaunchable(true); |
michael@0 | 87 | SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true); |
michael@0 | 88 | runTest(); |
michael@0 | 89 | }, |
michael@0 | 90 | |
michael@0 | 91 | // No confirmation needed when an app is installed |
michael@0 | 92 | function() { |
michael@0 | 93 | SpecialPowers.autoConfirmAppInstall(runTest); |
michael@0 | 94 | }, |
michael@0 | 95 | |
michael@0 | 96 | // Installing the app |
michael@0 | 97 | installApp, |
michael@0 | 98 | |
michael@0 | 99 | // Run tests in app |
michael@0 | 100 | testApp, |
michael@0 | 101 | |
michael@0 | 102 | // Uninstall the app |
michael@0 | 103 | uninstallApp |
michael@0 | 104 | ]; |
michael@0 | 105 | |
michael@0 | 106 | function runTest() { |
michael@0 | 107 | if (!tests.length) { |
michael@0 | 108 | finish(); |
michael@0 | 109 | return; |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | var test = tests.shift(); |
michael@0 | 113 | test(); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | function finish() { |
michael@0 | 117 | SimpleTest.finish(); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | if (SpecialPowers.isMainProcess()) { |
michael@0 | 121 | SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm"); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 125 | runTest(); |
michael@0 | 126 | </script> |
michael@0 | 127 | </body> |
michael@0 | 128 | </html> |