dom/plugins/test/mochitest/utils.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/mochitest/utils.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +function paintCountIs(plugin, expected, msg) {
     1.5 +  var count = plugin.getPaintCount();
     1.6 +  var realExpected = expected;
     1.7 +  var isAsync = SimpleTest.testPluginIsOOP();
     1.8 +  if (isAsync) {
     1.9 +    ++realExpected; // extra paint at startup for all async-rendering plugins
    1.10 +  } else {
    1.11 +    try {
    1.12 +      if (SpecialPowers.Cc["@mozilla.org/gfx/info;1"].getService(SpecialPowers.Ci.nsIGfxInfo).D2DEnabled) {
    1.13 +        realExpected *= 2;
    1.14 +      }
    1.15 +    } catch (e) {}
    1.16 +  }
    1.17 +  ok(realExpected == count, msg + " (expected " + expected +
    1.18 +     " independent paints, expected " + realExpected + " logged paints, got " +
    1.19 +     count + " actual paints)");
    1.20 +}
    1.21 +
    1.22 +function getTestPlugin(pluginName) {
    1.23 +  var ph = SpecialPowers.Cc["@mozilla.org/plugin/host;1"]
    1.24 +                                 .getService(SpecialPowers.Ci.nsIPluginHost);
    1.25 +  var tags = ph.getPluginTags();
    1.26 +  var name = pluginName || "Test Plug-in";
    1.27 +  for (var tag of tags) {
    1.28 +    if (tag.name == name) {
    1.29 +      return tag;
    1.30 +    }
    1.31 +  }
    1.32 +
    1.33 +  ok(false, "Could not find plugin tag with plugin name '" + name + "'");
    1.34 +  return null;
    1.35 +}
    1.36 +
    1.37 +// call this to set the test plugin(s) initially expected enabled state.
    1.38 +// it will automatically be reset to it's previous value after the test
    1.39 +// ends
    1.40 +function setTestPluginEnabledState(newEnabledState, pluginName) {
    1.41 +  var plugin = getTestPlugin(pluginName);
    1.42 +  var oldEnabledState = plugin.enabledState;
    1.43 +  plugin.enabledState = newEnabledState;
    1.44 +  SimpleTest.registerCleanupFunction(function() {
    1.45 +    getTestPlugin(pluginName).enabledState = oldEnabledState;
    1.46 +  });
    1.47 +}

mercurial