Bug 785161 - Stop uninstalling all installed apps in WebApps tests. r=jlebar
authorMounir Lamouri <mounir.lamouri@gmail.com>
Thu, 23 Aug 2012 11:46:38 -0700
changeset 103225 ebe6e3330f6384dec428eecc7950ea72e0790d2f
parent 103224 93a43b48cb6690c16fad7cb866502af09adc97d2
child 103226 4e0bd449dcb19b9b12bb8c42a0fe2d0f4684ed89
push id13890
push userryanvm@gmail.com
push dateThu, 23 Aug 2012 23:50:55 +0000
treeherdermozilla-inbound@e137f28dfe70 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlebar
bugs785161
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 785161 - Stop uninstalling all installed apps in WebApps tests. r=jlebar
dom/tests/mochitest/webapps/apphelper.js
dom/tests/mochitest/webapps/jshelper.js
dom/tests/mochitest/webapps/test_cross_domain.xul
dom/tests/mochitest/webapps/test_getNotInstalled.xul
dom/tests/mochitest/webapps/test_install_app.xul
dom/tests/mochitest/webapps/test_install_errors.xul
dom/tests/mochitest/webapps/test_install_receipts.xul
dom/tests/mochitest/webapps/test_install_utf8.xul
--- a/dom/tests/mochitest/webapps/apphelper.js
+++ b/dom/tests/mochitest/webapps/apphelper.js
@@ -100,14 +100,13 @@ function readFile(aFile) {
 }
 
 function getOrigin(url) {
   return Services.io.newURI(url, null, null).prePath;
 }
 
 function tearDown() {
   debug("in " + arguments.callee.name);
-  uninstallAll();
   popupNotifications.panel.removeEventListener("popupshown", mainCommand, false);
   SpecialPowers.clearUserPref('browser.mozApps.installer.dry_run');
   DOMApplicationRegistry.allAppsLaunchable = originalAAL;
 }
 
--- a/dom/tests/mochitest/webapps/jshelper.js
+++ b/dom/tests/mochitest/webapps/jshelper.js
@@ -29,51 +29,16 @@ function onIframeLoad(name, check, next)
   document.getElementById(name).contentWindow.wrappedJSObject.getOrigin = getOrigin;
   document.getElementById(name).contentWindow.wrappedJSObject.check = check;
   document.getElementById(name).contentWindow.wrappedJSObject.debug = debug;
   document.getElementById(name).contentWindow.wrappedJSObject.appURL = SERVERS[name]; 
   document.getElementById(name).contentWindow.wrappedJSObject.popup_listener = popup_listener;
   document.getElementById(name).contentWindow.wrappedJSObject.readFile = readFile;
 }
 
-/**
- * Uninstall All uninstalls all Apps
- * @next  The next operation to jump to, this might need to be invoked by the iframe when the test has completed
- */
-
-function uninstallAll(next) {
-  var pendingGetAll = navigator.mozApps.mgmt.getAll();
-  pendingGetAll.onsuccess = function() {
-    var m = this.result;
-    var total = m.length;
-    var finished = (total === 0);
-    debug("total = " + total);
-    for (var i=0; i < m.length; i++) {
-      var app = m[i];
-      var pendingUninstall = app.uninstall();
-      pendingUninstall.onsuccess = function(r) {
-        finished = (--total === 0);
-        if(finished == true) {
-          next();
-        }
-      };
-      pendingUninstall.onerror = function () {
-        finished = true;
-        throw('Failed');
-        if(finished == true) {
-          next();
-        }
-      };
-    }
-    if(finished == true && total ==  0) {
-      next();
-    }
-  }
-}
-
 function subsetOf(resultObj, list) {
   var returnObj = {} ;
   for (var i=0; i < list.length; i++) {
     returnObj[list[i]] = resultObj[list[i]];
   }
   return returnObj;
 }
 
--- a/dom/tests/mochitest/webapps/test_cross_domain.xul
+++ b/dom/tests/mochitest/webapps/test_cross_domain.xul
@@ -21,44 +21,29 @@
      target="_blank">Mozilla Bug 741549</a>
   <iframe id="super_crazy" onload="go();" src="http://www.example.com:80/chrome/dom/tests/mochitest/webapps/apps/include.html"/>
   <iframe id="no_delegated_install" onload="go();" src="http://sub2.test2.example.org:80/chrome/dom/tests/mochitest/webapps/apps/include.html"/>
 
   </body>
 
 <script> 
 
-steps = [setUp, verify_no_apps, get_installed_returns_nothing, install_super_crazy, check_event_listener_fired, get_self_returns_nothing, 
+steps = [get_installed_returns_nothing, install_super_crazy, check_event_listener_fired, get_self_returns_nothing, 
          get_self_on_domain, install_on_domain, check_event_listener_fired, get_all_installed, 
          get_installed_on_domain, uninstall_on_domain, get_all_on_domain, tearDown];
 var iframes_loaded = 0 ;
 
 function go() {
   ++iframes_loaded;
   if (iframes_loaded >= 2) {
     runAll(steps);
   } 
 }
 
 
-function setUp(next) { 
-  debug("in " + arguments.callee.name);
-  
-  uninstallAll(next);
-}
-
-function verify_no_apps(next)  {
-  debug("in " + arguments.callee.name);
-  mozAppscb(navigator.mozApps.mgmt.getAll(),
-            [{}],
-            "success",
-            ok,
-            next);
-}
-
 function get_installed_returns_nothing(next) {
   debug("in " + arguments.callee.name);
   mozAppscb(navigator.mozApps.getInstalled(), 
             [{}],
             "success",
             ok, 
             next);
 }
--- a/dom/tests/mochitest/webapps/test_getNotInstalled.xul
+++ b/dom/tests/mochitest/webapps/test_getNotInstalled.xul
@@ -10,60 +10,64 @@
         title="Mozilla Bug 781379">
 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
 <script type="application/javascript" src="apphelper.js"/>
 <script type="application/javascript" src="jshelper.js"/>
 <script type="application/javascript;version=1.8">
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 Cu.import("resource://gre/modules/Webapps.jsm");
 
+let notInstalled = 0;
+
 let _isLaunchable;
 let steps = [
-  cleanUp, installApp, monkeyPatchDOMApplicationRegistry, getNotInstalled,
-  unmonkeyPatchDOMApplicationRegistry, cleanUp, tearDown
+  monkeyPatchDOMApplicationRegistry, getNotInstalled, installApp,
+  compareNotInstalled, unmonkeyPatchDOMApplicationRegistry, cleanUp, tearDown
 ];
 runAll(steps);
 
-// Remove all installed apps and apps from the appregistry
-function cleanUp (next) { 
-  uninstallAll(next);
-}
-
-// Add an app to the appregistry
-function installApp (next) {
-  let appURL = SERVERS["super_crazy"];
-  install(appURL, ok, next);
-}
-
 // Monkey patch DOMApplicationRegistry._isLaunchable for testing.
 // This way, we don't have to create a platform specific application with a
 // status other than "installed".
 function monkeyPatchDOMApplicationRegistry (next) {
   _isLaunchable = DOMApplicationRegistry._isLaunchable;
   DOMApplicationRegistry._isLaunchable = function mockIsLaunchable (aOrigin) {
     return false;
   }
   next();
 }
 
-// Call navigator.mozApps.mgmt.getNotInstalled
+// Call navigator.mozApps.mgmt.getNotInstalled and save the result.
 function getNotInstalled (next) {
+  window.navigator.mozApps.mgmt.getNotInstalled().onsuccess = function() {
+    notInstalled = this.result.length;
+    next();
+  };
+}
+
+// Add an app to the appregistry
+function installApp (next) {
+  let appURL = SERVERS["super_crazy"];
+  install(appURL, ok, next);
+}
+
+// Call navigator.mozApps.mgmt.getNotInstalled and make sure there is one more.
+function compareNotInstalled (next) {
   let results;
   function getNotInstalledError () {
     ok(false, "window.mozApps.mgmt.getNotInstalled onerror called");
     next();
   }
   function getNotInstalledSuccess () {
     ok(true, "window.mozApps.mgmt.getNotInstalled onsuccess called");
-    if (this.result.length === 1) {
-      ok(true, "got the single notInstalled app back")
-      is(this.result[0].origin, "http://www.example.com",
+    is(this.result.length, notInstalled + 1, "should get one more notInstalled app");
+
+    if (this.result.length > 0) {
+      is(this.result[this.result.length-1].origin, "http://www.example.com",
         "getNotInstalled returned the expected app");
-    } else {
-      ok(false, "got an unexpected result from the call to getNotInstalled");
     }
     next();
   }
 
   let type = typeof window.navigator.mozApps.getNotInstalled;
   is(type, "undefined", "getNotInstalled moved from window.navigator");
   type = typeof window.navigator.mozApps.mgmt.getNotInstalled;
   if (type === "function") {
@@ -81,10 +85,17 @@ function unmonkeyPatchDOMApplicationRegi
   if (typeof _isLaunchable === "function") {
     DOMApplicationRegistry._isLaunchable = _isLaunchable;
     ok(true, "restored DOMApplicationRegistry._isLaunchable")
   } else {
     ok(false, "can't restore DOMApplicationRegistry._isLaunchable")
   }
   next();
 }
+
+// Remove installed app.
+function cleanUp (next) {
+  let appURL = SERVERS["super_crazy"];
+  uninstall(appURL, ok, next);
+}
+
 </script>
 </window>
--- a/dom/tests/mochitest/webapps/test_install_app.xul
+++ b/dom/tests/mochitest/webapps/test_install_app.xul
@@ -19,35 +19,21 @@
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741549"
      target="_blank">Mozilla Bug 741549</a> <br />
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=734294"
      target="_blank">Mozilla Bug 734294</a>
   </body>
 
 <script> 
 
-steps = [setUp, verify_no_apps, get_installed_returns_nothing, install_super_crazy, get_self_returns_nothing, 
+steps = [get_installed_returns_nothing, install_super_crazy, get_self_returns_nothing, 
          install_wild_crazy, uninstall_wild_crazy, tearDown];
 
 runAll(steps);
 
-function setUp(next) { 
-  debug("in " + arguments.callee.name);
-  uninstallAll(next);
-}
-
-function verify_no_apps(next)  {
-  debug("in " + arguments.callee.name);
-  mozAppscb(navigator.mozApps.mgmt.getAll(), 
-            [{}],
-            "success",
-            ok,
-            next);
-}
-
 function get_installed_returns_nothing(next) {
   debug("in " + arguments.callee.name);
   mozAppscb(navigator.mozApps.getInstalled(), 
             [{}],
             "success",
             ok,
             next);
 }
--- a/dom/tests/mochitest/webapps/test_install_errors.xul
+++ b/dom/tests/mochitest/webapps/test_install_errors.xul
@@ -21,23 +21,18 @@
   </body>
 
 <script> 
 
 function go() {
   runAll(steps);
 }
 
-steps = [setUp, no_args, parse_error, invalid_manifest, permission_denied, invalid_content,
-         mgmt_api_errors, mgmt_api_add_listener, tearDown];
-
-function setUp(next) {
-  debug("in " + arguments.callee.name);
-  uninstallAll(next);
-}
+steps = [no_args, parse_error, invalid_manifest, permission_denied, invalid_content,
+         mgmt_api_errors, mgmt_api_add_listener, uninstall_apps, tearDown];
 
 function no_args(next)  {
   debug("in " + arguments.callee.name);
   try { 
     navigator.mozApps.install();
   } catch (e) {
     ok(e.message == "Not enough arguments \[mozIDOMApplicationRegistry.install\]", "install returned " + e.message);
     next();
@@ -75,12 +70,21 @@ function mgmt_api_errors(next) {
 }
 
 function mgmt_api_add_listener(next) {
   debug("in " + arguments.callee.name);
   onIframeLoad("no_delegated_install", todo, next);
   document.getElementById("no_delegated_install").contentWindow.postMessage("mgmt.event_error", '*');
 }
 
+function uninstall_apps(next) {
+  debug("in " + arguments.callee.name);
+  var appURL = SERVERS['bad_content_type'];
+  uninstall(appURL, ok, function() {
+    appURL = SERVERS['no_delegated_install'];
+    uninstall(appURL, ok, function() { next(); });
+  });
+}
+
 </script> 
 
 </window>
 
--- a/dom/tests/mochitest/webapps/test_install_receipts.xul
+++ b/dom/tests/mochitest/webapps/test_install_receipts.xul
@@ -17,26 +17,20 @@
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741549"
      target="_blank">Mozilla Bug 741549</a>
   </body>
 
 <script> 
 
-steps = [setUp, install_super_crazy, tearDown];
+steps = [install_super_crazy, uninstall_super_crazy, tearDown];
 
 runAll(steps);
 
-function setUp(next) { 
-  debug("in " + arguments.callee.name);
-  uninstallAll(next);
-}
-
-
 function install_super_crazy(next)  {
   debug("in " + arguments.callee.name);
   var appURL = SERVERS['super_crazy'];
   var pending = navigator.mozApps.install(appURL, {receipts: ["a",0, true,false,null,undefined,{one:1},{nest:{ed:"hi"}},NaN,Infinity]});
   pending.onsuccess = function ()  {
     var receipts = pending.result.receipts; 
     ok(receipts[0] == "a", receipts[0]);
     ok(receipts[1] == 0, receipts[1]);
@@ -48,12 +42,18 @@ function install_super_crazy(next)  {
     ok(receipts[7].nest.ed == "hi", receipts[7].nest.ed);
     todo(receipts[8] == NaN, receipts[8]);
     todo(receipts[9] == Infinity, receipts[9]);
  
     next();
   };
 }
 
+function uninstall_super_crazy(next)  {
+  debug("in " + arguments.callee.name);
+  var appURL = SERVERS['super_crazy'];
+  uninstall(appURL, ok, function() { next(); });
+}
+
 </script> 
 
 </window>
 
--- a/dom/tests/mochitest/webapps/test_install_utf8.xul
+++ b/dom/tests/mochitest/webapps/test_install_utf8.xul
@@ -17,52 +17,43 @@
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741549"
      target="_blank">Mozilla Bug 741549</a>
   </body>
 
 <script> 
 
-steps = [setUp, verify_no_apps, get_installed_returns_nothing, install_bom, tearDown];
+steps = [get_installed_returns_nothing, install_bom, uninstall_bom, tearDown];
 
 runAll(steps);
 
-function setUp(next) { 
-  debug("in " + arguments.callee.name);
-  uninstallAll(next);
-}
-
-function verify_no_apps(next)  {
-  debug("in " + arguments.callee.name);
-  mozAppscb(navigator.mozApps.mgmt.getAll(), 
-            [{}],
-            "success",
-            ok,
-            next);
-}
-
 function get_installed_returns_nothing(next) {
   debug("in " + arguments.callee.name);
-  mozAppscb(navigator.mozApps.getInstalled(), 
-            [{}],
-            "success",
-            ok, 
-            next);
+  navigator.mozApps.getInstalled().onsuccess = function() {
+    is(this.result.length, 0, "should get no installed app");
+    next();
+  };
 }
 
 function install_bom(next)  {
   debug("in " + arguments.callee.name);
   var appURL = SERVERS['manifest_with_bom'];
   var pending = navigator.mozApps.install(appURL, null);
   pending.onsuccess = function()  {
      var name = pending.result.manifest.name;
      var description = pending.result.manifest.description;
      ok(name == "TheBOM  ゲゴケ゚セニツ゚ヅヂチ", name);
      ok(description == "This App is THE BOM, yo. ヅヂチ", description);
      next();
   };
 }
 
+function uninstall_bom(next)  {
+  debug("in " + arguments.callee.name);
+  var appURL = SERVERS['manifest_with_bom'];
+  uninstall(appURL, ok, function() { next(); });
+}
+
 </script> 
 
 </window>