dom/datastore/tests/test_oop.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.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <meta charset="utf-8">
     5   <title>Test for DataStore - basic operation on a readonly db</title>
     6   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     7   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     8 </head>
     9 <body>
    10 <div id="container"></div>
    11   <script type="application/javascript;version=1.7">
    13   var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_basic.html';
    14   var gApp;
    16   function cbError() {
    17     ok(false, "Error callback invoked");
    18     finish();
    19   }
    21   function installApp() {
    22     var request = navigator.mozApps.install(gHostedManifestURL);
    23     request.onerror = cbError;
    24     request.onsuccess = function() {
    25       gApp = request.result;
    26       runTest();
    27     }
    28   }
    30   function uninstallApp() {
    31     // Uninstall the app.
    32     var request = navigator.mozApps.mgmt.uninstall(gApp);
    33     request.onerror = cbError;
    34     request.onsuccess = function() {
    35       // All done.
    36       info("All done");
    37       runTest();
    38     }
    39   }
    41   function testApp() {
    42     var ifr = document.createElement('iframe');
    43     ifr.setAttribute('mozbrowser', 'true');
    44     ifr.setAttribute('mozapp', gApp.manifestURL);
    45     ifr.setAttribute('src', gApp.manifest.launch_path);
    46     var domParent = document.getElementById('container');
    48     // Set us up to listen for messages from the app.
    49     var listener = function(e) {
    50       var message = e.detail.message;
    51       if (/^OK/.exec(message)) {
    52         ok(true, "Message from app: " + message);
    53       } else if (/KO/.exec(message)) {
    54         ok(false, "Message from app: " + message);
    55       } else if (/DONE/.exec(message)) {
    56         ok(true, "Messaging from app complete");
    57         ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
    58         domParent.removeChild(ifr);
    59         runTest();
    60       }
    61     }
    63     // This event is triggered when the app calls "alert".
    64     ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
    65     domParent.appendChild(ifr);
    66   }
    68   var tests = [
    69     // Permissions
    70     function() {
    71       SpecialPowers.pushPermissions(
    72         [{ "type": "browser", "allow": 1, "context": document },
    73          { "type": "embed-apps", "allow": 1, "context": document },
    74          { "type": "webapps-manage", "allow": 1, "context": document }], runTest);
    75     },
    77     // Preferences
    78     function() {
    79       SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
    80                                          ["dom.ipc.browser_frames.oop_by_default", true],
    81                                          ["dom.testing.ignore_ipc_principal", true],
    82                                          ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
    83     },
    85     function() {
    86       SpecialPowers.setAllAppsLaunchable(true);
    87       SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
    88       runTest();
    89     },
    91     // No confirmation needed when an app is installed
    92     function() {
    93       SpecialPowers.autoConfirmAppInstall(runTest);
    94     },
    96     // Installing the app
    97     installApp,
    99     // Run tests in app
   100     testApp,
   102     // Uninstall the app
   103     uninstallApp
   104   ];
   106   function runTest() {
   107     if (!tests.length) {
   108       finish();
   109       return;
   110     }
   112     var test = tests.shift();
   113     test();
   114   }
   116   function finish() {
   117     SimpleTest.finish();
   118   }
   120   if (SpecialPowers.isMainProcess()) {
   121     SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
   122   }
   124   SimpleTest.waitForExplicitFinish();
   125   runTest();
   126   </script>
   127 </body>
   128 </html>

mercurial