dom/datastore/tests/test_app_install.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 - install/uninstall apps</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   if (SpecialPowers.isMainProcess()) {
    14     SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
    15   }
    17   SimpleTest.waitForExplicitFinish();
    19   var gBaseURL = 'http://test/tests/dom/datastore/tests/';
    20   var gHostedManifestURL = gBaseURL + 'file_app.sjs?testToken=file_app_install.html';
    21   var gGenerator = runTest();
    23   SpecialPowers.pushPermissions(
    24     [{ "type": "browser", "allow": 1, "context": document },
    25      { "type": "embed-apps", "allow": 1, "context": document },
    26      { "type": "webapps-manage", "allow": 1, "context": document }],
    27     function() {
    28       SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
    29                                          ["dom.testing.ignore_ipc_principal", true],
    30                                          ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, function() {
    31         gGenerator.next(); });
    32     });
    34   function continueTest() {
    35     try {
    36       gGenerator.next();
    37     } catch (e if e instanceof StopIteration) { }
    38   }
    40   function cbError() {
    41     ok(false, "Error callback invoked");
    42     finish();
    43   }
    45   function runTest() {
    46     ok("getDataStores" in navigator, "getDataStores exists");
    47     is(typeof navigator.getDataStores, "function", "getDataStores exists and it's a function");
    49     SpecialPowers.setAllAppsLaunchable(true);
    50     SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
    52     SpecialPowers.autoConfirmAppInstall(continueTest);
    53     yield undefined;
    55     var request = navigator.mozApps.install(gHostedManifestURL);
    56     request.onerror = cbError;
    57     request.onsuccess = continueTest;
    58     yield undefined;
    60     var app = request.result;
    61     isnot(app, null, "App is non-null");
    62     is(app.manifest.description, "Updated even faster than Firefox, just to annoy slashdotters.",
    63        "Manifest is HTML-sanitized");
    65     var ifr = document.createElement('iframe');
    66     ifr.setAttribute('mozbrowser', 'true');
    67     ifr.setAttribute('mozapp', app.manifestURL);
    68     ifr.setAttribute('src', app.manifest.launch_path);
    69     var domParent = document.getElementById('container');
    71     // Set us up to listen for messages from the app.
    72     var listener = function(e) {
    73       var message = e.detail.message;
    74       if (/^OK/.exec(message)) {
    75         ok(true, "Message from app: " + message);
    76       } else if (/KO/.exec(message)) {
    77         ok(false, "Message from app: " + message);
    78       } else if (/DONE/.exec(message)) {
    79         ok(true, "Messaging from app complete");
    80         ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
    81         domParent.removeChild(ifr);
    83         // Uninstall the app.
    84         request = navigator.mozApps.mgmt.uninstall(app);
    85         request.onerror = cbError;
    86         request.onsuccess = function() {
    87           // All done.
    88           finish();
    89         }
    90       }
    91     }
    93     // This event is triggered when the app calls "alert".
    94     ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
    96     domParent.appendChild(ifr);
    97   }
    99   function finish() {
   100     SpecialPowers.clearUserPref("dom.mozBrowserFramesEnabled");
   101     SimpleTest.finish();
   102   }
   104   </script>
   105 </body>
   106 </html>

mercurial