dom/apps/tests/test_bug_795164.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 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=795164
     5 -->
     6 <head>
     7   <meta charset="utf-8">
     8   <title>Test for Bug 795164</title>
     9   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    11   <script type="application/javascript;version=1.7">
    13   /** Test for Bug 795164 **/
    15   SimpleTest.waitForExplicitFinish();
    17   var url1 = 'http://test1.example.com/tests/dom/apps/tests/file_app.sjs?apptype=hosted&getmanifest=true';
    18   var url2 = 'http://test2.example.com/tests/dom/apps/tests/file_app.sjs?apptype=hosted&getmanifest=true';
    20   var gGenerator = runTest();
    22   function go() {
    23     SpecialPowers.pushPermissions(
    24       [{ "type": "webapps-manage", "allow": 1, "context": document }],
    25       function() { gGenerator.next() });
    26   }
    28   function continueTest() {
    29     try {
    30       gGenerator.next();
    31     } catch (e if e instanceof StopIteration) {
    32       SimpleTest.finish();
    33     }
    34   }
    36   function mozAppsError() {
    37     ok(false, "mozApps error: " + this.error.name);
    38     SimpleTest.finish();
    39   }
    41   function runTest() {
    42     // Set up.
    43     SpecialPowers.setAllAppsLaunchable(true);
    44     SpecialPowers.autoConfirmAppInstall(continueTest);
    45     yield undefined;
    47     // Keeping track of the number of times `mozApps.mgmt.onuninstall` gets triggered
    48     let uninstallCount = 0;
    50     navigator.mozApps.mgmt.onuninstall = function() {
    51       uninstallCount++;
    52     };
    54     let request = navigator.mozApps.install(url1);
    55     request.onerror = mozAppsError;
    56     request.onsuccess = continueTest;
    57     yield undefined;
    58     let app1 = request.result;
    59     ok(app1, "App1 is non-null");
    61     request = navigator.mozApps.install(url2);
    62     request.onerror = mozAppsError;
    63     request.onsuccess = continueTest;
    64     yield undefined;
    65     let app2 = request.result;
    66     ok(app2, "App2 is non-null");
    68     request = navigator.mozApps.mgmt.uninstall(app1);
    69     request.onsuccess = function() {
    70       ok(true, "Succeed to uninstall the app1 as expected");
    71       continueTest();
    72     };
    73     request.onerror = function() {
    74       ok(false, "Fail to uninstall the app1");
    75       continueTest();
    76     };
    77     yield undefined;
    79     request = navigator.mozApps.mgmt.uninstall(app2);
    80     request.onsuccess = function() {
    81       ok(true, "Succeed to uninstall the app2 as expected");
    82       continueTest();
    83     };
    84     request.onerror = function() {
    85       ok(false, "Fail to uninstall the app2");
    86       continueTest();
    87     };
    88     yield undefined;
    90     is(uninstallCount, 2, "mgmt.onuninstall got triggered only twice");
    92     navigator.mozApps.mgmt.onuninstall = null;
    93   }
    94   </script>
    95 </head>
    96 <body onload="go()">
    97 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=795164">Mozilla Bug 795164</a>
    98 <p id="display"></p>
    99 <div id="content" style="display: none">
   101 </div>
   102 <pre id="test">
   103 </pre>
   104 </body>
   105 </html>

mercurial