dom/plugins/test/mochitest/utils.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 function paintCountIs(plugin, expected, msg) {
     2   var count = plugin.getPaintCount();
     3   var realExpected = expected;
     4   var isAsync = SimpleTest.testPluginIsOOP();
     5   if (isAsync) {
     6     ++realExpected; // extra paint at startup for all async-rendering plugins
     7   } else {
     8     try {
     9       if (SpecialPowers.Cc["@mozilla.org/gfx/info;1"].getService(SpecialPowers.Ci.nsIGfxInfo).D2DEnabled) {
    10         realExpected *= 2;
    11       }
    12     } catch (e) {}
    13   }
    14   ok(realExpected == count, msg + " (expected " + expected +
    15      " independent paints, expected " + realExpected + " logged paints, got " +
    16      count + " actual paints)");
    17 }
    19 function getTestPlugin(pluginName) {
    20   var ph = SpecialPowers.Cc["@mozilla.org/plugin/host;1"]
    21                                  .getService(SpecialPowers.Ci.nsIPluginHost);
    22   var tags = ph.getPluginTags();
    23   var name = pluginName || "Test Plug-in";
    24   for (var tag of tags) {
    25     if (tag.name == name) {
    26       return tag;
    27     }
    28   }
    30   ok(false, "Could not find plugin tag with plugin name '" + name + "'");
    31   return null;
    32 }
    34 // call this to set the test plugin(s) initially expected enabled state.
    35 // it will automatically be reset to it's previous value after the test
    36 // ends
    37 function setTestPluginEnabledState(newEnabledState, pluginName) {
    38   var plugin = getTestPlugin(pluginName);
    39   var oldEnabledState = plugin.enabledState;
    40   plugin.enabledState = newEnabledState;
    41   SimpleTest.registerCleanupFunction(function() {
    42     getTestPlugin(pluginName).enabledState = oldEnabledState;
    43   });
    44 }

mercurial