mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-23 21:17:52 +00:00
Bug 1196539 - Add plugin window visibility tests. r=roc
This commit is contained in:
parent
ef553da542
commit
f70b45c550
@ -4,3 +4,5 @@ support-files =
|
||||
|
||||
[browser_bug1163570.js]
|
||||
skip-if = (!e10s || os != "win")
|
||||
[browser_bug1196539.js]
|
||||
skip-if = (!e10s || os != "win")
|
||||
|
159
dom/plugins/test/mochitest/browser_bug1196539.js
Normal file
159
dom/plugins/test/mochitest/browser_bug1196539.js
Normal file
@ -0,0 +1,159 @@
|
||||
let gTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
|
||||
|
||||
// Returns the chrome side nsIPluginTag for this plugin
|
||||
function getTestPlugin(aName) {
|
||||
let pluginName = aName || "Test Plug-in";
|
||||
let ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
||||
let tags = ph.getPluginTags();
|
||||
|
||||
// Find the test plugin
|
||||
for (let i = 0; i < tags.length; i++) {
|
||||
if (tags[i].name == pluginName)
|
||||
return tags[i];
|
||||
}
|
||||
ok(false, "Unable to find plugin");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set the test plugin state, disabling features like click-to-play
|
||||
function setTestPluginEnabledState(newEnabledState, pluginName) {
|
||||
let name = pluginName || "Test Plug-in";
|
||||
let plugin = getTestPlugin(name);
|
||||
plugin.enabledState = newEnabledState;
|
||||
}
|
||||
|
||||
function promiseNewTabSwitched() {
|
||||
return new Promise(resolve => {
|
||||
gBrowser.addEventListener("TabSwitchDone", function onSwitch() {
|
||||
gBrowser.removeEventListener("TabSwitchDone", onSwitch);
|
||||
executeSoon(resolve);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function waitForMs(aMs) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(done, aMs);
|
||||
function done() {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkPaintCount(aCount) {
|
||||
ok(aCount != 0, "paint count can't be greater than zero, count was " + aCount);
|
||||
ok(aCount < kMaxPaints, "paint count should be within limits, count was " + aCount);
|
||||
}
|
||||
|
||||
// maximum number of paints we allow before failing. The test plugin doesn't
|
||||
// animate so this should really be just 1, but operating systems can
|
||||
// occasionally fire a few of these so we give these tests a fudge factor.
|
||||
// A bad regression would either be 0, or 100+.
|
||||
const kMaxPaints = 10;
|
||||
|
||||
add_task(function* () {
|
||||
let result, tabSwitchedPromise;
|
||||
|
||||
setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Test Plug-in");
|
||||
|
||||
let testTab = gBrowser.selectedTab;
|
||||
let pluginTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, gTestRoot + "plugin_test.html");
|
||||
let homeTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home");
|
||||
|
||||
result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
|
||||
let doc = content.document;
|
||||
let plugin = doc.getElementById("testplugin");
|
||||
return !!plugin;
|
||||
});
|
||||
is(result, true, "plugin is loaded");
|
||||
|
||||
result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
|
||||
let doc = content.document;
|
||||
let plugin = doc.getElementById("testplugin");
|
||||
return !XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
|
||||
});
|
||||
is(result, true, "plugin is hidden");
|
||||
|
||||
// reset plugin paint count
|
||||
yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
|
||||
let doc = content.document;
|
||||
let plugin = doc.getElementById("testplugin");
|
||||
XPCNativeWrapper.unwrap(plugin).resetPaintCount();
|
||||
});
|
||||
|
||||
// select plugin tab
|
||||
tabSwitchedPromise = promiseNewTabSwitched();
|
||||
gBrowser.selectedTab = pluginTab;
|
||||
yield tabSwitchedPromise;
|
||||
|
||||
// wait a bit for spurious paints
|
||||
yield waitForMs(100);
|
||||
|
||||
result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
|
||||
let doc = content.document;
|
||||
let plugin = doc.getElementById("testplugin");
|
||||
return XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
|
||||
});
|
||||
is(result, true, "plugin is visible");
|
||||
|
||||
// check for good paint count
|
||||
result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
|
||||
let doc = content.document;
|
||||
let plugin = doc.getElementById("testplugin");
|
||||
return XPCNativeWrapper.unwrap(plugin).getPaintCount();
|
||||
});
|
||||
checkPaintCount(result);
|
||||
|
||||
// select home tab
|
||||
tabSwitchedPromise = promiseNewTabSwitched();
|
||||
gBrowser.selectedTab = homeTab;
|
||||
yield tabSwitchedPromise;
|
||||
|
||||
// reset paint count
|
||||
yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
|
||||
let doc = content.document;
|
||||
let plugin = doc.getElementById("testplugin");
|
||||
XPCNativeWrapper.unwrap(plugin).resetPaintCount();
|
||||
});
|
||||
|
||||
// wait a bit for spurious paints
|
||||
yield waitForMs(100);
|
||||
|
||||
// check for no paint count
|
||||
result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
|
||||
let doc = content.document;
|
||||
let plugin = doc.getElementById("testplugin");
|
||||
return XPCNativeWrapper.unwrap(plugin).getPaintCount();
|
||||
});
|
||||
is(result, 0, "no paints, this is correct.");
|
||||
|
||||
result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
|
||||
let doc = content.document;
|
||||
let plugin = doc.getElementById("testplugin");
|
||||
return !XPCNativeWrapper.unwrap(plugin).nativeWidgetIsVisible();
|
||||
});
|
||||
is(result, true, "plugin is hidden");
|
||||
|
||||
// reset paint count
|
||||
yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
|
||||
let doc = content.document;
|
||||
let plugin = doc.getElementById("testplugin");
|
||||
XPCNativeWrapper.unwrap(plugin).resetPaintCount();
|
||||
});
|
||||
|
||||
// select plugin tab
|
||||
tabSwitchedPromise = promiseNewTabSwitched();
|
||||
gBrowser.selectedTab = pluginTab;
|
||||
yield tabSwitchedPromise;
|
||||
|
||||
// check paint count
|
||||
result = yield ContentTask.spawn(pluginTab.linkedBrowser, null, function*() {
|
||||
let doc = content.document;
|
||||
let plugin = doc.getElementById("testplugin");
|
||||
return XPCNativeWrapper.unwrap(plugin).getPaintCount();
|
||||
});
|
||||
checkPaintCount(result);
|
||||
|
||||
gBrowser.removeTab(homeTab);
|
||||
gBrowser.removeTab(pluginTab);
|
||||
});
|
@ -122,6 +122,7 @@ static bool stopWatchingInstanceCount(NPObject* npobj, const NPVariant* args, ui
|
||||
static bool getLastMouseX(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool getLastMouseY(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool getPaintCount(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool resetPaintCount(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool getWidthAtLastPaint(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool setInvalidateDuringPaint(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool setSlowPaint(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
@ -192,6 +193,7 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = {
|
||||
"getLastMouseX",
|
||||
"getLastMouseY",
|
||||
"getPaintCount",
|
||||
"resetPaintCount",
|
||||
"getWidthAtLastPaint",
|
||||
"setInvalidateDuringPaint",
|
||||
"setSlowPaint",
|
||||
@ -263,6 +265,7 @@ static const ScriptableFunction sPluginMethodFunctions[] = {
|
||||
getLastMouseX,
|
||||
getLastMouseY,
|
||||
getPaintCount,
|
||||
resetPaintCount,
|
||||
getWidthAtLastPaint,
|
||||
setInvalidateDuringPaint,
|
||||
setSlowPaint,
|
||||
@ -2436,6 +2439,18 @@ getPaintCount(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVaria
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
resetPaintCount(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
|
||||
{
|
||||
if (argCount != 0)
|
||||
return false;
|
||||
|
||||
NPP npp = static_cast<TestNPObject*>(npobj)->npp;
|
||||
InstanceData* id = static_cast<InstanceData*>(npp->pdata);
|
||||
id->paintCount = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
getWidthAtLastPaint(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user