From 11c490eb56257f55830105bbdaf27a00d3e85d85 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Tue, 26 Apr 2011 15:23:18 -0700 Subject: [PATCH] Bug 650965 - Test for removal of node using waitForAndContinue. r=mfinkle --- mobile/chrome/tests/browser_addons.js | 13 +++++++------ mobile/chrome/tests/head.js | 5 +++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mobile/chrome/tests/browser_addons.js b/mobile/chrome/tests/browser_addons.js index c50246a4c808..2324f358cdd2 100644 --- a/mobile/chrome/tests/browser_addons.js +++ b/mobile/chrome/tests/browser_addons.js @@ -372,14 +372,15 @@ function installFromURLBar(aAddon) { is(updateButton.disabled, false, "Update button is enabled"); ExtensionsView.uninstall(elt); - setTimeout(function() { - elt = get_addon_element(aAddon.id); - ok(!elt || !elt.addon, "Addon element removed during uninstall"); - if (elt && !elt.addon) - info("Element is still visible in search area"); + waitForAndContinue(function() { + let elt = get_addon_element(aAddon.id); + ok(!elt, "Addon element removed during uninstall"); Browser.closeTab(gCurrentTab); close_manager(run_next_test); - }, 0); + }, function() { + let elt = get_addon_element(aAddon.id); + return !elt; + }); } else { ok(!elt, "Extension not in list"); AddonManager.getAllInstalls(function(aInstalls) { diff --git a/mobile/chrome/tests/head.js b/mobile/chrome/tests/head.js index f48903a63d3c..ff877e9c369e 100644 --- a/mobile/chrome/tests/head.js +++ b/mobile/chrome/tests/head.js @@ -2,6 +2,7 @@ Common Helpers functions =============================================================================*/ +const kDefaultWait = 2000; // Wait for a condition and call a supplied callback if condition is met within // alloted time. If condition is not met, cause a hard failure, stopping the test. function waitFor(callback, test, timeout) { @@ -11,7 +12,7 @@ function waitFor(callback, test, timeout) { } timeout = timeout || Date.now(); - if (Date.now() - timeout > 1000) + if (Date.now() - timeout > kDefaultWait) throw "waitFor timeout"; setTimeout(waitFor, 50, callback, test, timeout); }; @@ -26,7 +27,7 @@ function waitForAndContinue(callback, test, timeout) { } timeout = timeout || Date.now(); - if (Date.now() - timeout > 1000) { + if (Date.now() - timeout > kDefaultWait) { callback(); return; }