Bug 1538602 - Dont depend on event for icon shown condition. r=johannh
authorDale Harvey <dale@arandomurl.com>
Fri, 12 Apr 2019 12:32:13 +0000
changeset 469270 d2dfbfc9da12efbbba43f32e2a8238a5b0120b09
parent 469269 5d85f0ed28cc8bf0c636c4675210b5f4c6788f97
child 469271 bd6762543efec64230544fbfa7002a8a24198216
push id112776
push usershindli@mozilla.com
push dateFri, 12 Apr 2019 16:20:17 +0000
treeherdermozilla-inbound@b4501ced5619 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1538602
milestone68.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 1538602 - Dont depend on event for icon shown condition. r=johannh Differential Revision: https://phabricator.services.mozilla.com/D27187
browser/base/content/test/permissions/browser_autoplay_blocked.js
--- a/browser/base/content/test/permissions/browser_autoplay_blocked.js
+++ b/browser/base/content/test/permissions/browser_autoplay_blocked.js
@@ -26,22 +26,22 @@ function autoplayBlockedIcon() {
                                 ".blocked-permission-icon.autoplay-media-icon");
 }
 
 function sleep(ms) {
   /* eslint-disable mozilla/no-arbitrary-setTimeout */
   return new Promise(resolve => setTimeout(resolve, ms));
 }
 
-async function blockedIconShown(browser) {
-  // May need to wait for `GloballyAutoplayBlocked` event before showing icon.
-  if (BrowserTestUtils.is_hidden(autoplayBlockedIcon())) {
-    await BrowserTestUtils.waitForEvent(browser, "GloballyAutoplayBlocked");
-  }
-  ok(!BrowserTestUtils.is_hidden(autoplayBlockedIcon()), "Blocked icon is shown");
+async function blockedIconShown() {
+  await TestUtils.waitForCondition(() => {
+    return BrowserTestUtils.is_visible(autoplayBlockedIcon());
+  });
+
+  ok(BrowserTestUtils.is_visible(autoplayBlockedIcon()), "Blocked icon is shown");
 }
 
 add_task(async function setup() {
   registerCleanupFunction(() => {
     Services.perms.removeAll();
     Services.prefs.clearUserPref(AUTOPLAY_PREF);
   });
 });
@@ -61,17 +61,17 @@ add_task(async function testMainViewVisi
   });
 
   Services.prefs.setIntPref(AUTOPLAY_PREF, Ci.nsIAutoplay.BLOCKED);
 
   await BrowserTestUtils.withNewTab(AUTOPLAY_PAGE, async function(browser) {
     let permissionsList = document.getElementById("identity-popup-permission-list");
     let emptyLabel = permissionsList.nextElementSibling.nextElementSibling;
 
-    await blockedIconShown(browser);
+    await blockedIconShown();
 
     await openIdentityPopup();
     ok(BrowserTestUtils.is_hidden(emptyLabel), "List of permissions is not empty");
     let labelText = SitePermissions.getPermissionLabel(AUTOPLAY_PERM);
     let labels = permissionsList.querySelectorAll(".identity-popup-permission-label");
     is(labels.length, 1, "One permission visible in main view");
     is(labels[0].textContent, labelText, "Correct value");
 
@@ -99,17 +99,17 @@ add_task(async function testMainViewVisi
 });
 
 add_task(async function testGloballyBlockedOnNewWindow() {
   Services.prefs.setIntPref(AUTOPLAY_PREF, Ci.nsIAutoplay.BLOCKED);
 
   let uri = Services.io.newURI(AUTOPLAY_PAGE);
 
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, uri.spec);
-  await blockedIconShown(tab.linkedBrowser);
+  await blockedIconShown();
 
   Assert.deepEqual(SitePermissions.get(uri, AUTOPLAY_PERM, tab.linkedBrowser), {
     state: SitePermissions.BLOCK,
     scope: SitePermissions.SCOPE_PERSISTENT,
   });
 
   let promiseWin = BrowserTestUtils.waitForNewWindow();
   gBrowser.replaceTabWithWindow(tab);
@@ -125,41 +125,41 @@ add_task(async function testGloballyBloc
   await BrowserTestUtils.closeWindow(win);
 });
 
 add_task(async function testBFCache() {
   Services.prefs.setIntPref(AUTOPLAY_PREF, Ci.nsIAutoplay.BLOCKED);
 
   await BrowserTestUtils.withNewTab("about:home", async function(browser) {
     await BrowserTestUtils.loadURI(browser, AUTOPLAY_PAGE);
-    await blockedIconShown(browser);
+    await blockedIconShown();
 
     gBrowser.goBack();
     await TestUtils.waitForCondition(() => {
       return BrowserTestUtils.is_hidden(autoplayBlockedIcon());
     });
 
     // Not sure why using `gBrowser.goForward()` doesn't trigger document's
     // visibility changes in some debug build on try server, which makes us not
     // to receive the blocked event.
     await ContentTask.spawn(browser, null, () => {
       content.history.forward();
     });
-    await blockedIconShown(browser);
+    await blockedIconShown();
   });
 
   Services.perms.removeAll();
 });
 
 add_task(async function testChangingBlockingSettingDuringNavigation() {
   Services.prefs.setIntPref(AUTOPLAY_PREF, Ci.nsIAutoplay.BLOCKED);
 
   await BrowserTestUtils.withNewTab("about:home", async function(browser) {
     await BrowserTestUtils.loadURI(browser, AUTOPLAY_PAGE);
-    await blockedIconShown(browser);
+    await blockedIconShown();
     Services.prefs.setIntPref(AUTOPLAY_PREF, Ci.nsIAutoplay.ALLOWED);
 
     gBrowser.goBack();
     await TestUtils.waitForCondition(() => {
       return BrowserTestUtils.is_hidden(autoplayBlockedIcon());
     });
 
     gBrowser.goForward();
@@ -175,21 +175,23 @@ add_task(async function testChangingBloc
   Services.perms.removeAll();
 });
 
 add_task(async function testSlowLoadingPage() {
   Services.prefs.setIntPref(AUTOPLAY_PREF, Ci.nsIAutoplay.BLOCKED);
 
   let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home");
   let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, SLOW_AUTOPLAY_PAGE);
+  await blockedIconShown();
+
   await BrowserTestUtils.switchTab(gBrowser, tab1);
   // Wait until the blocked icon is hidden by switching tabs
   await TestUtils.waitForCondition(() => {
     return BrowserTestUtils.is_hidden(autoplayBlockedIcon());
   });
   await BrowserTestUtils.switchTab(gBrowser, tab2);
-  await blockedIconShown(tab2.linkedBrowser);
+  await blockedIconShown();
 
   BrowserTestUtils.removeTab(tab1);
   BrowserTestUtils.removeTab(tab2);
 
   Services.perms.removeAll();
 });