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

--HG--
extra : rebase_source : 28ca0c294b08c78174985e493039396edd20d16b
This commit is contained in:
Doug Thayer 2018-05-08 15:26:15 -07:00
Родитель 43e6e7eca2
Коммит 5b97c0aaba
1 изменённых файлов: 42 добавлений и 48 удалений

Просмотреть файл

@ -1,5 +1,31 @@
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 visibilityCheckCount = 0;
let listener = async () => {
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 (++visibilityCheckCount > 1) {
// 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();
}
};
window.addEventListener("MozAfterPaint", listener);
listener();
});
}
// tests that we get plugin updates when we flip between tabs that
// have the same plugin in the same position in the page.
@ -29,76 +55,44 @@ add_task(async function() {
// 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);