dom/datastore/tests/test_changes.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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 <p id="display"></p>
michael@0 11 <div id="content" style="display: none">
michael@0 12
michael@0 13 </div>
michael@0 14 <pre id="test">
michael@0 15 <script type="application/javascript;version=1.7">
michael@0 16
michael@0 17 var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_changes.html';
michael@0 18 var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_changes2.html&template=file_app2.template.webapp';
michael@0 19 var gApps = [];
michael@0 20 var gApp2Events = 0;
michael@0 21 var gStore;
michael@0 22
michael@0 23 function cbError() {
michael@0 24 ok(false, "Error callback invoked");
michael@0 25 finish();
michael@0 26 }
michael@0 27
michael@0 28 function installApp(aApp) {
michael@0 29 var request = navigator.mozApps.install(aApp);
michael@0 30 request.onerror = cbError;
michael@0 31 request.onsuccess = function() {
michael@0 32 gApps.push(request.result);
michael@0 33 runTest();
michael@0 34 }
michael@0 35 }
michael@0 36
michael@0 37 function uninstallApps() {
michael@0 38 if (!gApps.length) {
michael@0 39 ok(true, "All done!");
michael@0 40 runTest();
michael@0 41 return;
michael@0 42 }
michael@0 43
michael@0 44 var app = gApps.pop();
michael@0 45 var request = navigator.mozApps.mgmt.uninstall(app);
michael@0 46 request.onerror = cbError;
michael@0 47 request.onsuccess = uninstallApps;
michael@0 48 }
michael@0 49
michael@0 50 function setupApp2() {
michael@0 51 var ifr = document.createElement('iframe');
michael@0 52 ifr.setAttribute('mozbrowser', 'true');
michael@0 53 ifr.setAttribute('mozapp', gApps[1].manifestURL);
michael@0 54 ifr.setAttribute('src', gApps[1].manifest.launch_path);
michael@0 55 var domParent = document.getElementById('content');
michael@0 56
michael@0 57 // Set us up to listen for messages from the app.
michael@0 58 var listener = function(e) {
michael@0 59 var message = e.detail.message;
michael@0 60 if (/^OK/.exec(message)) {
michael@0 61 ok(true, "Message from app: " + message);
michael@0 62 } else if (/KO/.exec(message)) {
michael@0 63 ok(false, "Message from app: " + message);
michael@0 64 } else if (/READY/.exec(message)) {
michael@0 65 ok(true, "App2 ready");
michael@0 66 runTest();
michael@0 67 } else if (/DONE/.exec(message)) {
michael@0 68 ok(true, "Messaging from app complete");
michael@0 69 ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
michael@0 70 domParent.removeChild(ifr);
michael@0 71 gApp2Events++;
michael@0 72 }
michael@0 73 }
michael@0 74
michael@0 75 // This event is triggered when the app calls "alert".
michael@0 76 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
michael@0 77 domParent.appendChild(ifr);
michael@0 78 }
michael@0 79
michael@0 80 function testApp1() {
michael@0 81 var ifr = document.createElement('iframe');
michael@0 82 ifr.setAttribute('mozbrowser', 'true');
michael@0 83 ifr.setAttribute('mozapp', gApps[0].manifestURL);
michael@0 84 ifr.setAttribute('src', gApps[0].manifest.launch_path);
michael@0 85 var domParent = document.getElementById('content');
michael@0 86
michael@0 87 // Set us up to listen for messages from the app.
michael@0 88 var listener = function(e) {
michael@0 89 var message = e.detail.message;
michael@0 90 if (/^OK/.exec(message)) {
michael@0 91 ok(true, "Message from app: " + message);
michael@0 92 } else if (/KO/.exec(message)) {
michael@0 93 ok(false, "Message from app: " + message);
michael@0 94 } else if (/DONE/.exec(message)) {
michael@0 95 ok(true, "Messaging from app complete");
michael@0 96 ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
michael@0 97 domParent.removeChild(ifr);
michael@0 98 runTest();
michael@0 99 }
michael@0 100 }
michael@0 101
michael@0 102 // This event is triggered when the app calls "alert".
michael@0 103 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
michael@0 104 domParent.appendChild(ifr);
michael@0 105 }
michael@0 106
michael@0 107 function checkApp2() {
michael@0 108 ok(gApp2Events, "App2 received events");
michael@0 109 runTest();
michael@0 110 }
michael@0 111
michael@0 112 var tests = [
michael@0 113 // Permissions
michael@0 114 function() {
michael@0 115 SpecialPowers.pushPermissions(
michael@0 116 [{ "type": "browser", "allow": 1, "context": document },
michael@0 117 { "type": "embed-apps", "allow": 1, "context": document },
michael@0 118 { "type": "webapps-manage", "allow": 1, "context": document }], runTest);
michael@0 119 },
michael@0 120
michael@0 121 // Preferences
michael@0 122 function() {
michael@0 123 SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
michael@0 124 ["dom.testing.ignore_ipc_principal", true],
michael@0 125 ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
michael@0 126 },
michael@0 127
michael@0 128 // Enabling mozBrowser
michael@0 129 function() {
michael@0 130 SpecialPowers.setAllAppsLaunchable(true);
michael@0 131 SpecialPowers.pushPrefEnv({"set": [["dom.mozBrowserFramesEnabled", true]]}, runTest);
michael@0 132 },
michael@0 133
michael@0 134 // No confirmation needed when an app is installed
michael@0 135 function() {
michael@0 136 SpecialPowers.autoConfirmAppInstall(runTest);
michael@0 137 },
michael@0 138
michael@0 139 // Installing the app1
michael@0 140 function() { installApp(gHostedManifestURL); },
michael@0 141
michael@0 142 // Installing the app2
michael@0 143 function() { installApp(gHostedManifestURL2); },
michael@0 144
michael@0 145 // Setup app2 for receving events
michael@0 146 setupApp2,
michael@0 147
michael@0 148 // Run tests in app
michael@0 149 testApp1,
michael@0 150
michael@0 151 // Check app2
michael@0 152 checkApp2,
michael@0 153
michael@0 154 // Uninstall the apps
michael@0 155 uninstallApps,
michael@0 156 ];
michael@0 157
michael@0 158 function runTest() {
michael@0 159 if (!tests.length) {
michael@0 160 finish();
michael@0 161 return;
michael@0 162 }
michael@0 163
michael@0 164 var test = tests.shift();
michael@0 165 test();
michael@0 166 }
michael@0 167
michael@0 168 function finish() {
michael@0 169 SimpleTest.finish();
michael@0 170 }
michael@0 171
michael@0 172 if (SpecialPowers.isMainProcess()) {
michael@0 173 SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
michael@0 174 }
michael@0 175
michael@0 176 SimpleTest.waitForExplicitFinish();
michael@0 177 runTest();
michael@0 178 </script>
michael@0 179 </pre>
michael@0 180 </body>
michael@0 181 </html>
michael@0 182
michael@0 183

mercurial