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

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <meta charset="utf-8">
     5   <title>Test for DataStore - string or unsigned long keys</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_keys.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.testing.ignore_ipc_principal", true],
    81                                          ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
    82     },
    84     function() {
    85       SpecialPowers.setAllAppsLaunchable(true);
    86       SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
    87       runTest();
    88     },
    90     // No confirmation needed when an app is installed
    91     function() {
    92       SpecialPowers.autoConfirmAppInstall(runTest);
    93     },
    95     // Installing the app
    96     installApp,
    98     // Run tests in app
    99     testApp,
   101     // Uninstall the app
   102     uninstallApp
   103   ];
   105   function runTest() {
   106     if (!tests.length) {
   107       finish();
   108       return;
   109     }
   111     var test = tests.shift();
   112     test();
   113   }
   115   function finish() {
   116     SimpleTest.finish();
   117   }
   119   if (SpecialPowers.isMainProcess()) {
   120     SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
   121   }
   123   SimpleTest.waitForExplicitFinish();
   124   runTest();
   125   </script>
   126 </body>
   127 </html>

mercurial