dom/datastore/tests/test_bug986056.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 986056</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_bug986056.html&template=file_bug986056.template.webapp';
michael@0 18 var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_bug986056.html&template=file_bug986056.template.webapp';
michael@0 19 var gApps = [];
michael@0 20
michael@0 21 function cbError() {
michael@0 22 ok(false, "Error callback invoked");
michael@0 23 finish();
michael@0 24 }
michael@0 25
michael@0 26 function installApp(aApp) {
michael@0 27 var request = navigator.mozApps.install(aApp);
michael@0 28 request.onerror = cbError;
michael@0 29 request.onsuccess = function() {
michael@0 30 gApps.push(request.result);
michael@0 31 runTest();
michael@0 32 }
michael@0 33 }
michael@0 34
michael@0 35 function uninstallApp(aApp) {
michael@0 36 var request = navigator.mozApps.mgmt.uninstall(aApp);
michael@0 37 request.onerror = cbError;
michael@0 38 request.onsuccess = runTest;
michael@0 39 }
michael@0 40
michael@0 41 function testApp(aCount) {
michael@0 42 var ifr = document.createElement('iframe');
michael@0 43 ifr.setAttribute('mozbrowser', 'true');
michael@0 44 ifr.setAttribute('mozapp', gApps[0].manifestURL);
michael@0 45 ifr.setAttribute('src', gApps[0].manifest.launch_path);
michael@0 46 var domParent = document.getElementById('content');
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 (/KO/.exec(message)) {
michael@0 52 ok(false, "Message from app: " + message);
michael@0 53 } else if (/^OK/.exec(message)) {
michael@0 54 is(message, "OK " + aCount, "Number of dataStore matches");
michael@0 55 ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
michael@0 56 domParent.removeChild(ifr);
michael@0 57 runTest();
michael@0 58 }
michael@0 59 }
michael@0 60
michael@0 61 // This event is triggered when the app calls "alert".
michael@0 62 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
michael@0 63 domParent.appendChild(ifr);
michael@0 64 }
michael@0 65
michael@0 66 var tests = [
michael@0 67 // Permissions
michael@0 68 function() {
michael@0 69 SpecialPowers.pushPermissions(
michael@0 70 [{ "type": "browser", "allow": 1, "context": document },
michael@0 71 { "type": "embed-apps", "allow": 1, "context": document },
michael@0 72 { "type": "webapps-manage", "allow": 1, "context": document }], runTest);
michael@0 73 },
michael@0 74
michael@0 75 // Preferences
michael@0 76 function() {
michael@0 77 SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
michael@0 78 ["dom.testing.ignore_ipc_principal", true],
michael@0 79 ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
michael@0 80 },
michael@0 81
michael@0 82 // Enabling mozBrowser
michael@0 83 function() {
michael@0 84 SpecialPowers.setAllAppsLaunchable(true);
michael@0 85 SpecialPowers.pushPrefEnv({"set": [["dom.mozBrowserFramesEnabled", true]]}, runTest);
michael@0 86 },
michael@0 87
michael@0 88 // No confirmation needed when an app is installed
michael@0 89 function() {
michael@0 90 SpecialPowers.autoConfirmAppInstall(runTest);
michael@0 91 },
michael@0 92
michael@0 93 // Installing the app1
michael@0 94 function() { installApp(gHostedManifestURL); },
michael@0 95
michael@0 96 // Installing the app2
michael@0 97 function() { installApp(gHostedManifestURL2); },
michael@0 98
michael@0 99 // Run tests in app. 2 apps are installed so we want to have 2 'foo'
michael@0 100 // dataStore.
michael@0 101 function() { testApp(2); },
michael@0 102
michael@0 103 // Uninstall the first app
michael@0 104 function() { uninstallApp(gApps.shift()); },
michael@0 105
michael@0 106 // Run tests in app. 1 single apps is installed so we want to have 1 'foo'
michael@0 107 // dataStore.
michael@0 108 function() { testApp(1); },
michael@0 109
michael@0 110 // Installing the app1
michael@0 111 function() { installApp(gHostedManifestURL); },
michael@0 112
michael@0 113 // Run tests in app. Back to 2 apps, 2 datastores.
michael@0 114 function() { testApp(2); },
michael@0 115
michael@0 116 // Uninstall the first app
michael@0 117 function() { uninstallApp(gApps.shift()); },
michael@0 118
michael@0 119 // Uninstall the second app
michael@0 120 function() { uninstallApp(gApps.shift()); }
michael@0 121 ];
michael@0 122
michael@0 123 function runTest() {
michael@0 124 if (!tests.length) {
michael@0 125 finish();
michael@0 126 return;
michael@0 127 }
michael@0 128
michael@0 129 var test = tests.shift();
michael@0 130 test();
michael@0 131 }
michael@0 132
michael@0 133 function finish() {
michael@0 134 SimpleTest.finish();
michael@0 135 }
michael@0 136
michael@0 137 if (SpecialPowers.isMainProcess()) {
michael@0 138 SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
michael@0 139 }
michael@0 140
michael@0 141 SimpleTest.waitForExplicitFinish();
michael@0 142 runTest();
michael@0 143 </script>
michael@0 144 </pre>
michael@0 145 </body>
michael@0 146 </html>

mercurial