dom/datastore/tests/test_readonly.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_readonly.html';
michael@0 13 var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_readonly.html&template=file_app2.template.webapp';
michael@0 14 var gGenerator = runTest();
michael@0 15
michael@0 16 SpecialPowers.pushPermissions(
michael@0 17 [{ "type": "browser", "allow": 1, "context": document },
michael@0 18 { "type": "embed-apps", "allow": 1, "context": document },
michael@0 19 { "type": "webapps-manage", "allow": 1, "context": document }],
michael@0 20 function() { gGenerator.next() });
michael@0 21
michael@0 22 function continueTest() {
michael@0 23 try { gGenerator.next(); }
michael@0 24 catch(e) {}
michael@0 25 }
michael@0 26
michael@0 27 function cbError() {
michael@0 28 ok(false, "Error callback invoked");
michael@0 29 finish();
michael@0 30 }
michael@0 31
michael@0 32 function runTest() {
michael@0 33 SpecialPowers.setAllAppsLaunchable(true);
michael@0 34 SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
michael@0 35
michael@0 36 SpecialPowers.autoConfirmAppInstall(continueTest);
michael@0 37 yield undefined;
michael@0 38
michael@0 39 var request = navigator.mozApps.install(gHostedManifestURL);
michael@0 40 request.onerror = cbError;
michael@0 41 request.onsuccess = continueTest;
michael@0 42 yield undefined;
michael@0 43
michael@0 44 var app = request.result;
michael@0 45
michael@0 46 request = navigator.mozApps.install(gHostedManifestURL2);
michael@0 47 request.onerror = cbError;
michael@0 48 request.onsuccess = continueTest;
michael@0 49 yield undefined;
michael@0 50
michael@0 51 var app2 = request.result;
michael@0 52
michael@0 53 var ifr = document.createElement('iframe');
michael@0 54 ifr.setAttribute('mozbrowser', 'true');
michael@0 55 ifr.setAttribute('mozapp', app2.manifestURL);
michael@0 56 ifr.setAttribute('src', app2.manifest.launch_path);
michael@0 57 var domParent = document.getElementById('container');
michael@0 58
michael@0 59 // Set us up to listen for messages from the app.
michael@0 60 var listener = function(e) {
michael@0 61 var message = e.detail.message;
michael@0 62 if (/^OK/.exec(message)) {
michael@0 63 ok(true, "Message from app: " + message);
michael@0 64 } else if (/KO/.exec(message)) {
michael@0 65 ok(false, "Message from app: " + message);
michael@0 66 } else if (/DONE/.exec(message)) {
michael@0 67 ok(true, "Messaging from app complete");
michael@0 68 ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
michael@0 69 domParent.removeChild(ifr);
michael@0 70
michael@0 71 // Uninstall the app.
michael@0 72 request = navigator.mozApps.mgmt.uninstall(app);
michael@0 73 request.onerror = cbError;
michael@0 74 request.onsuccess = function() {
michael@0 75 // Uninstall app2
michael@0 76 request = navigator.mozApps.mgmt.uninstall(app2);
michael@0 77 request.onerror = cbError;
michael@0 78 request.onsuccess = function() {
michael@0 79 // All done.
michael@0 80 info("All done");
michael@0 81 finish();
michael@0 82 }
michael@0 83 }
michael@0 84 }
michael@0 85 }
michael@0 86
michael@0 87 // This event is triggered when the app calls "alert".
michael@0 88 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
michael@0 89
michael@0 90 domParent.appendChild(ifr);
michael@0 91 }
michael@0 92
michael@0 93 function finish() {
michael@0 94 SpecialPowers.clearUserPref("dom.mozBrowserFramesEnabled");
michael@0 95 SimpleTest.finish();
michael@0 96 }
michael@0 97
michael@0 98 if (SpecialPowers.isMainProcess()) {
michael@0 99 SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
michael@0 100 }
michael@0 101
michael@0 102 SimpleTest.waitForExplicitFinish();
michael@0 103 SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
michael@0 104 ["dom.testing.ignore_ipc_principal", true],
michael@0 105 ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
michael@0 106 </script>
michael@0 107 </body>
michael@0 108 </html>

mercurial