dom/datastore/tests/test_bug986056.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 - bug 986056</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 <p id="display"></p>
    11 <div id="content" style="display: none">
    13 </div>
    14 <pre id="test">
    15   <script type="application/javascript;version=1.7">
    17   var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_bug986056.html&template=file_bug986056.template.webapp';
    18   var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_bug986056.html&template=file_bug986056.template.webapp';
    19   var gApps = [];
    21   function cbError() {
    22     ok(false, "Error callback invoked");
    23     finish();
    24   }
    26   function installApp(aApp) {
    27     var request = navigator.mozApps.install(aApp);
    28     request.onerror = cbError;
    29     request.onsuccess = function() {
    30       gApps.push(request.result);
    31       runTest();
    32     }
    33   }
    35   function uninstallApp(aApp) {
    36     var request = navigator.mozApps.mgmt.uninstall(aApp);
    37     request.onerror = cbError;
    38     request.onsuccess = runTest;
    39   }
    41   function testApp(aCount) {
    42     var ifr = document.createElement('iframe');
    43     ifr.setAttribute('mozbrowser', 'true');
    44     ifr.setAttribute('mozapp', gApps[0].manifestURL);
    45     ifr.setAttribute('src', gApps[0].manifest.launch_path);
    46     var domParent = document.getElementById('content');
    48     // Set us up to listen for messages from the app.
    49     var listener = function(e) {
    50       var message = e.detail.message;
    51       if (/KO/.exec(message)) {
    52         ok(false, "Message from app: " + message);
    53       } else if (/^OK/.exec(message)) {
    54         is(message, "OK " + aCount, "Number of dataStore matches");
    55         ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
    56         domParent.removeChild(ifr);
    57         runTest();
    58       }
    59     }
    61     // This event is triggered when the app calls "alert".
    62     ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
    63     domParent.appendChild(ifr);
    64   }
    66   var tests = [
    67     // Permissions
    68     function() {
    69       SpecialPowers.pushPermissions(
    70         [{ "type": "browser", "allow": 1, "context": document },
    71          { "type": "embed-apps", "allow": 1, "context": document },
    72          { "type": "webapps-manage", "allow": 1, "context": document }], runTest);
    73     },
    75     // Preferences
    76     function() {
    77       SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
    78                                          ["dom.testing.ignore_ipc_principal", true],
    79                                          ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
    80     },
    82     // Enabling mozBrowser
    83     function() {
    84       SpecialPowers.setAllAppsLaunchable(true);
    85       SpecialPowers.pushPrefEnv({"set": [["dom.mozBrowserFramesEnabled", true]]}, runTest);
    86     },
    88     // No confirmation needed when an app is installed
    89     function() {
    90       SpecialPowers.autoConfirmAppInstall(runTest);
    91     },
    93     // Installing the app1
    94     function() { installApp(gHostedManifestURL); },
    96     // Installing the app2
    97     function() { installApp(gHostedManifestURL2); },
    99     // Run tests in app. 2 apps are installed so we want to have 2 'foo'
   100     // dataStore.
   101     function() { testApp(2); },
   103     // Uninstall the first app
   104     function() { uninstallApp(gApps.shift()); },
   106     // Run tests in app. 1 single apps is installed so we want to have 1 'foo'
   107     // dataStore.
   108     function() { testApp(1); },
   110     // Installing the app1
   111     function() { installApp(gHostedManifestURL); },
   113     // Run tests in app. Back to 2 apps, 2 datastores.
   114     function() { testApp(2); },
   116     // Uninstall the first app
   117     function() { uninstallApp(gApps.shift()); },
   119     // Uninstall the second app
   120     function() { uninstallApp(gApps.shift()); }
   121   ];
   123   function runTest() {
   124     if (!tests.length) {
   125       finish();
   126       return;
   127     }
   129     var test = tests.shift();
   130     test();
   131   }
   133   function finish() {
   134     SimpleTest.finish();
   135   }
   137   if (SpecialPowers.isMainProcess()) {
   138     SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
   139   }
   141   SimpleTest.waitForExplicitFinish();
   142   runTest();
   143   </script>
   144 </pre>
   145 </body>
   146 </html>

mercurial