dom/datastore/tests/test_changes.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 - 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 <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_changes.html';
    18   var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_changes2.html&template=file_app2.template.webapp';
    19   var gApps = [];
    20   var gApp2Events = 0;
    21   var gStore;
    23   function cbError() {
    24     ok(false, "Error callback invoked");
    25     finish();
    26   }
    28   function installApp(aApp) {
    29     var request = navigator.mozApps.install(aApp);
    30     request.onerror = cbError;
    31     request.onsuccess = function() {
    32       gApps.push(request.result);
    33       runTest();
    34     }
    35   }
    37   function uninstallApps() {
    38     if (!gApps.length) {
    39       ok(true, "All done!");
    40       runTest();
    41       return;
    42     }
    44     var app = gApps.pop();
    45     var request = navigator.mozApps.mgmt.uninstall(app);
    46     request.onerror = cbError;
    47     request.onsuccess = uninstallApps;
    48   }
    50   function setupApp2() {
    51     var ifr = document.createElement('iframe');
    52     ifr.setAttribute('mozbrowser', 'true');
    53     ifr.setAttribute('mozapp', gApps[1].manifestURL);
    54     ifr.setAttribute('src', gApps[1].manifest.launch_path);
    55     var domParent = document.getElementById('content');
    57     // Set us up to listen for messages from the app.
    58     var listener = function(e) {
    59       var message = e.detail.message;
    60       if (/^OK/.exec(message)) {
    61         ok(true, "Message from app: " + message);
    62       } else if (/KO/.exec(message)) {
    63         ok(false, "Message from app: " + message);
    64       } else if (/READY/.exec(message)) {
    65         ok(true, "App2 ready");
    66         runTest();
    67       } else if (/DONE/.exec(message)) {
    68         ok(true, "Messaging from app complete");
    69         ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
    70         domParent.removeChild(ifr);
    71         gApp2Events++;
    72       }
    73     }
    75     // This event is triggered when the app calls "alert".
    76     ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
    77     domParent.appendChild(ifr);
    78   }
    80   function testApp1() {
    81     var ifr = document.createElement('iframe');
    82     ifr.setAttribute('mozbrowser', 'true');
    83     ifr.setAttribute('mozapp', gApps[0].manifestURL);
    84     ifr.setAttribute('src', gApps[0].manifest.launch_path);
    85     var domParent = document.getElementById('content');
    87     // Set us up to listen for messages from the app.
    88     var listener = function(e) {
    89       var message = e.detail.message;
    90       if (/^OK/.exec(message)) {
    91         ok(true, "Message from app: " + message);
    92       } else if (/KO/.exec(message)) {
    93         ok(false, "Message from app: " + message);
    94       } else if (/DONE/.exec(message)) {
    95         ok(true, "Messaging from app complete");
    96         ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
    97         domParent.removeChild(ifr);
    98         runTest();
    99       }
   100     }
   102     // This event is triggered when the app calls "alert".
   103     ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
   104     domParent.appendChild(ifr);
   105   }
   107   function checkApp2() {
   108     ok(gApp2Events, "App2 received events");
   109     runTest();
   110   }
   112   var tests = [
   113     // Permissions
   114     function() {
   115       SpecialPowers.pushPermissions(
   116         [{ "type": "browser", "allow": 1, "context": document },
   117          { "type": "embed-apps", "allow": 1, "context": document },
   118          { "type": "webapps-manage", "allow": 1, "context": document }], runTest);
   119     },
   121     // Preferences
   122     function() {
   123       SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
   124                                          ["dom.testing.ignore_ipc_principal", true],
   125                                          ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
   126     },
   128     // Enabling mozBrowser
   129     function() {
   130       SpecialPowers.setAllAppsLaunchable(true);
   131       SpecialPowers.pushPrefEnv({"set": [["dom.mozBrowserFramesEnabled", true]]}, runTest);
   132     },
   134     // No confirmation needed when an app is installed
   135     function() {
   136       SpecialPowers.autoConfirmAppInstall(runTest);
   137     },
   139     // Installing the app1
   140     function() { installApp(gHostedManifestURL); },
   142     // Installing the app2
   143     function() { installApp(gHostedManifestURL2); },
   145     // Setup app2 for receving events
   146     setupApp2,
   148     // Run tests in app
   149     testApp1,
   151     // Check app2
   152     checkApp2,
   154     // Uninstall the apps
   155     uninstallApps,
   156   ];
   158   function runTest() {
   159     if (!tests.length) {
   160       finish();
   161       return;
   162     }
   164     var test = tests.shift();
   165     test();
   166   }
   168   function finish() {
   169     SimpleTest.finish();
   170   }
   172   if (SpecialPowers.isMainProcess()) {
   173     SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
   174   }
   176   SimpleTest.waitForExplicitFinish();
   177   runTest();
   178   </script>
   179 </pre>
   180 </body>
   181 </html>

mercurial