dom/datastore/tests/test_oop_events.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 - 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 <div id="container"></div>
    11   <script type="application/javascript;version=1.7">
    13   var gHostedManifestURL1 = 'http://test/tests/dom/datastore/tests/file_app.sjs?template=file_app2.template.webapp&testToken=file_event_receiver.html';
    14   var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_event_maker.html';
    15   var gApps = [];
    17   function cbError() {
    18     ok(false, "Error callback invoked");
    19     finish();
    20   }
    22   function installApp(manifest) {
    23     var request = navigator.mozApps.install(manifest);
    24     request.onerror = cbError;
    25     request.onsuccess = function() {
    26       gApps.push(request.result);
    27       runTest();
    28     }
    29   }
    31   function uninstallApp(app) {
    32     // Uninstall the app
    33     var request = navigator.mozApps.mgmt.uninstall(app);
    34     request.onerror = cbError;
    35     request.onsuccess = function() {
    36       runTest();
    37     }
    38   }
    40   function testApp() {
    41     var ifr = document.createElement('iframe');
    42     ifr.setAttribute('mozbrowser', 'true');
    43     ifr.setAttribute('mozapp', gApps[0].manifestURL);
    44     ifr.setAttribute('src', gApps[0].manifest.launch_path);
    45     var domParent = document.getElementById('container');
    47     // Set us up to listen for messages from the app.
    48     var listener = function(e) {
    49       var message = e.detail.message;
    50       if (/^OK/.exec(message)) {
    51         ok(true, "Message from app: " + message);
    52       } else if (/KO/.exec(message)) {
    53         ok(false, "Message from app: " + message);
    54       } else if (/READY/.exec(message)) {
    55         ok(true, "App ready");
    56         testApp2();
    57       } else if (/DONE/.exec(message)) {
    58         ok(true, "Messaging from app complete");
    59         ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
    60         domParent.removeChild(ifr);
    61         runTest();
    62       }
    63     }
    65     // This event is triggered when the app calls "alert".
    66     ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
    67     domParent.appendChild(ifr);
    68   }
    70   function testApp2() {
    71     var ifr = document.createElement('iframe');
    72     ifr.setAttribute('mozbrowser', 'true');
    73     ifr.setAttribute('mozapp', gApps[1].manifestURL);
    74     ifr.setAttribute('src', gApps[1].manifest.launch_path);
    75     var domParent = document.getElementById('container');
    77     // Set us up to listen for messages from the app.
    78     var listener = function(e) {
    79       var message = e.detail.message;
    80       if (/^OK/.exec(message)) {
    81         ok(true, "Message from app: " + message);
    82       } else if (/KO/.exec(message)) {
    83         ok(false, "Message from app: " + message);
    84       } else if (/DONE/.exec(message)) {
    85         ok(true, "Messaging from app complete");
    86         ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
    87         domParent.removeChild(ifr);
    88       }
    89     }
    91     // This event is triggered when the app calls "alert".
    92     ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
    93     domParent.appendChild(ifr);
    94   }
    96   var tests = [
    97     // Permissions
    98     function() {
    99       SpecialPowers.pushPermissions(
   100         [{ "type": "browser", "allow": 1, "context": document },
   101          { "type": "embed-apps", "allow": 1, "context": document },
   102          { "type": "webapps-manage", "allow": 1, "context": document }], runTest);
   103     },
   105     // Preferences
   106     function() {
   107       SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
   108                                          ["dom.ipc.browser_frames.oop_by_default", true],
   109                                          ["dom.testing.ignore_ipc_principal", true],
   110                                          ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
   111     },
   113     function() {
   114       SpecialPowers.setAllAppsLaunchable(true);
   115       SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
   116       runTest();
   117     },
   119     // No confirmation needed when an app is installed
   120     function() {
   121       SpecialPowers.autoConfirmAppInstall(runTest);
   122     },
   124     // Installing the apps
   125     function() { installApp(gHostedManifestURL1); },
   126     function() { installApp(gHostedManifestURL2); },
   128     // Run tests in apps
   129     testApp,
   131     // Uninstall the apps
   132     function() { uninstallApp(gApps[0]); },
   133     function() { uninstallApp(gApps[1]); },
   134   ];
   136   function runTest() {
   137     if (!tests.length) {
   138       finish();
   139       return;
   140     }
   142     var test = tests.shift();
   143     test();
   144   }
   146   function finish() {
   147     SimpleTest.finish();
   148   }
   150   if (SpecialPowers.isMainProcess()) {
   151     SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
   152   }
   154   SimpleTest.waitForExplicitFinish();
   155   runTest();
   156   </script>
   157 </body>
   158 </html>

mercurial