diff -r 000000000000 -r 6474c204b198 dom/plugins/test/mochitest/utils.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dom/plugins/test/mochitest/utils.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,44 @@ +function paintCountIs(plugin, expected, msg) { + var count = plugin.getPaintCount(); + var realExpected = expected; + var isAsync = SimpleTest.testPluginIsOOP(); + if (isAsync) { + ++realExpected; // extra paint at startup for all async-rendering plugins + } else { + try { + if (SpecialPowers.Cc["@mozilla.org/gfx/info;1"].getService(SpecialPowers.Ci.nsIGfxInfo).D2DEnabled) { + realExpected *= 2; + } + } catch (e) {} + } + ok(realExpected == count, msg + " (expected " + expected + + " independent paints, expected " + realExpected + " logged paints, got " + + count + " actual paints)"); +} + +function getTestPlugin(pluginName) { + var ph = SpecialPowers.Cc["@mozilla.org/plugin/host;1"] + .getService(SpecialPowers.Ci.nsIPluginHost); + var tags = ph.getPluginTags(); + var name = pluginName || "Test Plug-in"; + for (var tag of tags) { + if (tag.name == name) { + return tag; + } + } + + ok(false, "Could not find plugin tag with plugin name '" + name + "'"); + return null; +} + +// call this to set the test plugin(s) initially expected enabled state. +// it will automatically be reset to it's previous value after the test +// ends +function setTestPluginEnabledState(newEnabledState, pluginName) { + var plugin = getTestPlugin(pluginName); + var oldEnabledState = plugin.enabledState; + plugin.enabledState = newEnabledState; + SimpleTest.registerCleanupFunction(function() { + getTestPlugin(pluginName).enabledState = oldEnabledState; + }); +}