Bug 1176019 - Fix browser_tabswitchbetweenplugins.js r=mconley
☠☠ backed out by 4303d49c5393 ☠ ☠
authorDoug Thayer <dothayer@mozilla.com>
Tue, 08 May 2018 15:26:15 -0700
changeset 417839 2dd8b719d64584af09cdf97bf775241d91e5e225
parent 417838 9c6b0eb062ca41adb298dd5a5170fe0649c8e8d7
child 417840 45e028b105e5ee6136c1dff28a59d99f0c304b39
push id33980
push userebalazs@mozilla.com
push dateFri, 11 May 2018 09:35:12 +0000
treeherdermozilla-central@8e9a4a323f0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1176019
milestone62.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 1176019 - Fix browser_tabswitchbetweenplugins.js r=mconley After digging into this, I'm still not entirely sure why the timing has changed such that the checks don't work immediately. I have a strong suspicion though that it's simply because our tab switch is now instant, resulting in the necessary messages just being a little bit behind. Hopefully this is an acceptable bandaid. MozReview-Commit-ID: H1wKW1UQBxp
dom/plugins/test/mochitest/browser_tabswitchbetweenplugins.js
--- a/dom/plugins/test/mochitest/browser_tabswitchbetweenplugins.js
+++ b/dom/plugins/test/mochitest/browser_tabswitchbetweenplugins.js
@@ -1,10 +1,38 @@
 var gTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
 
+function waitForPluginVisibility(browser, shouldBeVisible, errorMessage) {
+  return new Promise((resolve, reject) => {
+    let windowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                            .getInterface(Ci.nsIDOMWindowUtils);
+    let lastTransactionId = windowUtils.lastTransactionId;
+    let listener = async (event) => {
+      let visibility = await ContentTask.spawn(browser, null, async function() {
+        let doc = content.document;
+        let plugin = doc.getElementById("testplugin");
+        return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
+      });
+
+      if (visibility == shouldBeVisible) {
+        window.removeEventListener("MozAfterPaint", listener);
+        resolve();
+      } else if (event && event.transactionId > lastTransactionId) {
+        // We want to allow for one failed check since we call listener
+        // directly, but if we get a MozAfterPaint notification and we
+        // still don't have the correct visibility, that's likely a
+        // problem.
+        reject(new Error("MozAfterPaint had a mismatched plugin visibility"));
+      }
+    };
+    window.addEventListener("MozAfterPaint", listener);
+    listener(null);
+  });
+}
+
 // tests that we get plugin updates when we flip between tabs that
 // have the same plugin in the same position in the page.
 
 add_task(async function() {
   let result, tabSwitchedPromise;
 
   setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Test Plug-in");
 
@@ -24,82 +52,50 @@ add_task(async function() {
     let plugin = doc.getElementById("testplugin");
     return !!plugin;
   });
   is(result, true, "plugin2 is loaded");
 
   // plugin tab 2 should be selected
   is(gBrowser.selectedTab == pluginTab2, true, "plugin2 is selected");
 
-  result = await ContentTask.spawn(pluginTab1.linkedBrowser, null, async function() {
-    let doc = content.document;
-    let plugin = doc.getElementById("testplugin");
-    return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
-  });
-  is(result, false, "plugin1 is hidden");
+  await waitForPluginVisibility(pluginTab1.linkedBrowser,
+                                false, "plugin1 should be hidden");
 
-  result = await ContentTask.spawn(pluginTab2.linkedBrowser, null, async function() {
-    let doc = content.document;
-    let plugin = doc.getElementById("testplugin");
-    return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
-  });
-  is(result, true, "plugin2 is visible");
+  await waitForPluginVisibility(pluginTab2.linkedBrowser,
+                                true, "plugin2 should be visible");
 
   // select plugin1 tab
   tabSwitchedPromise = waitTabSwitched();
   gBrowser.selectedTab = pluginTab1;
   await tabSwitchedPromise;
 
-  result = await ContentTask.spawn(pluginTab1.linkedBrowser, null, async function() {
-    let doc = content.document;
-    let plugin = doc.getElementById("testplugin");
-    return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
-  });
-  is(result, true, "plugin1 is visible");
+  await waitForPluginVisibility(pluginTab1.linkedBrowser,
+                                true, "plugin1 should be visible");
 
-  result = await ContentTask.spawn(pluginTab2.linkedBrowser, null, async function() {
-    let doc = content.document;
-    let plugin = doc.getElementById("testplugin");
-    return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
-  });
-  is(result, false, "plugin2 is hidden");
+  await waitForPluginVisibility(pluginTab2.linkedBrowser,
+                                false, "plugin2 should be hidden");
 
   // select plugin2 tab
   tabSwitchedPromise = waitTabSwitched();
   gBrowser.selectedTab = pluginTab2;
   await tabSwitchedPromise;
 
-  result = await ContentTask.spawn(pluginTab1.linkedBrowser, null, async function() {
-    let doc = content.document;
-    let plugin = doc.getElementById("testplugin");
-    return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
-  });
-  is(result, false, "plugin1 is hidden");
+  await waitForPluginVisibility(pluginTab1.linkedBrowser,
+                                false, "plugin1 should be hidden");
 
-  result = await ContentTask.spawn(pluginTab2.linkedBrowser, null, async function() {
-    let doc = content.document;
-    let plugin = doc.getElementById("testplugin");
-    return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
-  });
-  is(result, true, "plugin2 is visible");
+  await waitForPluginVisibility(pluginTab2.linkedBrowser,
+                                true, "plugin2 should be visible");
 
   // select test tab
   tabSwitchedPromise = waitTabSwitched();
   gBrowser.selectedTab = testTab;
   await tabSwitchedPromise;
 
-  result = await ContentTask.spawn(pluginTab1.linkedBrowser, null, async function() {
-    let doc = content.document;
-    let plugin = doc.getElementById("testplugin");
-    return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
-  });
-  is(result, false, "plugin1 is hidden");
+  await waitForPluginVisibility(pluginTab1.linkedBrowser,
+                                false, "plugin1 should be hidden");
 
-  result = await ContentTask.spawn(pluginTab2.linkedBrowser, null, async function() {
-    let doc = content.document;
-    let plugin = doc.getElementById("testplugin");
-    return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
-  });
-  is(result, false, "plugin2 is hidden");
+  await waitForPluginVisibility(pluginTab2.linkedBrowser,
+                                false, "plugin2 should be hidden");
 
   gBrowser.removeTab(pluginTab1);
   gBrowser.removeTab(pluginTab2);
 });