dom/datastore/tests/test_bug976311.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <meta charset="utf-8">
     5   <title>Test for DataStore - bug 976311</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_bug976311.html&template=file_bug976311.template.webapp';
    14   var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_bug976311.html&template=file_bug976311.template.webapp';
    15   var gApps = [];
    17   function cbError() {
    18     ok(false, "Error callback invoked");
    19     finish();
    20   }
    22   function installApp(aApp) {
    23     var request = navigator.mozApps.install(aApp);
    24     request.onerror = cbError;
    25     request.onsuccess = function() {
    26       gApps.push(request.result);
    27       runTest();
    28     }
    29   }
    31   function uninstallApps() {
    32     if (!gApps.length) {
    33       ok(true, "All done!");
    34       runTest();
    35       return;
    36     }
    38     var app = gApps.pop();
    39     var request = navigator.mozApps.mgmt.uninstall(app);
    40     request.onerror = cbError;
    41     request.onsuccess = uninstallApps;
    42   }
    45   function testApp() {
    46    var ifr = document.createElement('iframe');
    47    ifr.setAttribute('mozbrowser', 'true');
    48    ifr.setAttribute('mozapp', gApps[0].manifestURL);
    49    ifr.setAttribute('src', gApps[0].manifest.launch_path);
    50    var domParent = document.getElementById('container');
    52    // Set us up to listen for messages from the app.
    53    var listener = function(e) {
    54      var message = e.detail.message;
    55      if (/^OK/.exec(message)) {
    56        ok(true, "Message from app: " + message);
    57      } else if (/KO/.exec(message)) {
    58        ok(false, "Message from app: " + message);
    59      } else if (/DONE/.exec(message)) {
    60        ok(true, "Messaging from app complete");
    61        ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
    62        domParent.removeChild(ifr);
    63        runTest();
    64      }
    65    }
    67    // This event is triggered when the app calls "alert".
    68    ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
    69    domParent.appendChild(ifr);
    71   }
    73   var tests = [
    74     // Permissions
    75     function() {
    76       SpecialPowers.pushPermissions(
    77         [{ "type": "browser", "allow": 1, "context": document },
    78          { "type": "embed-apps", "allow": 1, "context": document },
    79          { "type": "webapps-manage", "allow": 1, "context": document }], runTest);
    80     },
    82     // Preferences
    83     function() {
    84       SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
    85                                          ["dom.testing.ignore_ipc_principal", true],
    86                                          ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
    87     },
    89     function() {
    90       SpecialPowers.setAllAppsLaunchable(true);
    91       SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
    92       runTest();
    93     },
    95     // No confirmation needed when an app is installed
    96     function() {
    97       SpecialPowers.autoConfirmAppInstall(runTest);
    98     },
   100     // Installing the app1
   101     function() { installApp(gHostedManifestURL); },
   103     // Installing the app2
   104     function() { installApp(gHostedManifestURL2); },
   106     // Run tests in app
   107     testApp,
   109     // Uninstall the apps
   110     uninstallApps
   111   ];
   113   function runTest() {
   114     if (!tests.length) {
   115       finish();
   116       return;
   117     }
   119     var test = tests.shift();
   120     test();
   121   }
   123   function finish() {
   124     SimpleTest.finish();
   125   }
   127   if (SpecialPowers.isMainProcess()) {
   128     SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
   129   }
   131   SimpleTest.waitForExplicitFinish();
   132   runTest();
   133   </script>
   134 </body>
   135 </html>

mercurial