From 4090b5057368365cb4112e3588427e465a6c175c Mon Sep 17 00:00:00 2001 From: David Keeler Date: Thu, 14 Jun 2012 16:52:49 -0700 Subject: [PATCH] Bug 764421 - poll with setInterval instead of using setTimeout in browser_bug743421.js; r=jaws --- .../base/content/test/browser_bug743421.js | 19 +++++++++++++------ .../test/browser_pluginnotification.js | 15 --------------- browser/base/content/test/head.js | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/browser/base/content/test/browser_bug743421.js b/browser/base/content/test/browser_bug743421.js index f4b1f669028c..5f9bfff531c5 100644 --- a/browser/base/content/test/browser_bug743421.js +++ b/browser/base/content/test/browser_bug743421.js @@ -42,7 +42,8 @@ function test1a() { ok(!popupNotification, "Test 1a, Should not have a click-to-play notification"); var plugin = gTestBrowser.contentWindow.addPlugin(); - setTimeout(test1b, 500); + var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); + waitForCondition(condition, test1b, "Test 1a, Waited too long for plugin notification"); } function test1b() { @@ -53,7 +54,7 @@ function test1b() { ok(!objLoadingContent.activated, "Test 1b, Plugin should not be activated"); popupNotification.mainAction.callback(); - setTimeout(test1c, 500); + test1c(); } function test1c() { @@ -61,7 +62,9 @@ function test1c() { ok(!popupNotification, "Test 1c, Should not have a click-to-play notification"); var plugin = gTestBrowser.contentWindow.addPlugin(); - setTimeout(test1d, 500); + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); + var condition = function() objLoadingContent.activated; + waitForCondition(condition, test1d, "Test 1c, Waited too long for plugin activation"); } function test1d() { @@ -82,7 +85,9 @@ function test1e() { ok(!popupNotification, "Test 1e, Should not have a click-to-play notification"); var plugin = gTestBrowser.contentWindow.addPlugin(); - setTimeout(test1f, 500); + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); + var condition = function() objLoadingContent.activated; + waitForCondition(condition, test1f, "Test 1e, Waited too long for plugin activation"); } function test1f() { @@ -93,8 +98,10 @@ function test1f() { ok(objLoadingContent.activated, "Test 1f, Plugin should be activated"); gTestBrowser.contentWindow.history.replaceState({}, "", "replacedState"); - gTestBrowser.contentWindow.addPlugin(); - setTimeout(test1g, 500); + var plugin = gTestBrowser.contentWindow.addPlugin(); + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); + var condition = function() objLoadingContent.activated; + waitForCondition(condition, test1g, "Test 1f, Waited too long for plugin activation"); } function test1g() { diff --git a/browser/base/content/test/browser_pluginnotification.js b/browser/base/content/test/browser_pluginnotification.js index e7722cc33eb0..c11fcf312247 100644 --- a/browser/base/content/test/browser_pluginnotification.js +++ b/browser/base/content/test/browser_pluginnotification.js @@ -213,21 +213,6 @@ function test8() { prepareTest(test9a, gTestRoot + "plugin_test2.html"); } -function waitForCondition(condition, nextTest, errorMsg) { - var tries = 0; - var interval = setInterval(function() { - if (tries >= 500) { - ok(false, errorMsg); - moveOn(); - } - if (condition()) { - moveOn(); - } - tries++; - }, 10); - var moveOn = function() { clearInterval(interval); nextTest(); }; -} - // Tests that activating one click-to-play plugin will activate only that plugin (part 1/3) function test9a() { var notificationBox = gBrowser.getNotificationBox(gTestBrowser); diff --git a/browser/base/content/test/head.js b/browser/base/content/test/head.js index 6389a249037b..bfe25c9427c4 100644 --- a/browser/base/content/test/head.js +++ b/browser/base/content/test/head.js @@ -72,3 +72,18 @@ function closeToolbarCustomizationUI(aCallback, aBrowserWin) { button.focus(); button.doCommand(); } + +function waitForCondition(condition, nextTest, errorMsg) { + var tries = 0; + var interval = setInterval(function() { + if (tries >= 30) { + ok(false, errorMsg); + moveOn(); + } + if (condition()) { + moveOn(); + } + tries++; + }, 100); + var moveOn = function() { clearInterval(interval); nextTest(); }; +}