From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- dom/plugins/test/mochitest/plugin-utils.js | 95 ++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 dom/plugins/test/mochitest/plugin-utils.js (limited to 'dom/plugins/test/mochitest/plugin-utils.js') diff --git a/dom/plugins/test/mochitest/plugin-utils.js b/dom/plugins/test/mochitest/plugin-utils.js new file mode 100644 index 000000000..90d3c285d --- /dev/null +++ b/dom/plugins/test/mochitest/plugin-utils.js @@ -0,0 +1,95 @@ +function paintCountIs(plugin, expected, msg) { + var count = plugin.getPaintCount(); + var realExpected = expected; + ++realExpected; // extra paint at startup for all async-rendering plugins + 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 oldEnabledState = SpecialPowers.setTestPluginEnabledState(newEnabledState, pluginName); + var plugin = getTestPlugin(pluginName); + while (plugin.enabledState != newEnabledState) { + // Run a nested event loop to wait for the preference change to + // propagate to the child. Yuck! + SpecialPowers.Services.tm.currentThread.processNextEvent(true); + } + SimpleTest.registerCleanupFunction(function() { + SpecialPowers.setTestPluginEnabledState(oldEnabledState, pluginName); + }); +} + +function crashAndGetCrashServiceRecord(crashMethodName, callback) { + var crashMan = + SpecialPowers.Cu.import("resource://gre/modules/Services.jsm"). + Services.crashmanager; + + // First, clear the crash record store. + info("Waiting for pruneOldCrashes"); + var future = new Date(Date.now() + 1000 * 60 * 60 * 24); + crashMan.pruneOldCrashes(future).then(function () { + + var iframe = document.getElementById("iframe1"); + var p = iframe.contentDocument.getElementById("plugin1"); + + var crashDateMS = Date.now(); + try { + p[crashMethodName](); + ok(false, "p." + crashMethodName + "() should throw an exception"); + } + catch (e) { + ok(true, "p." + crashMethodName + "() should throw an exception"); + } + + // The crash record store is written and read back asyncly, so poll for + // the new record. + function tryGetCrash() { + info("Waiting for getCrashes"); + crashMan.getCrashes().then(SpecialPowers.wrapCallback(function (crashes) { + if (crashes.length) { + is(crashes.length, 1, "There should be only one record"); + var crash = SpecialPowers.wrap(crashes[0]); + ok(!!crash.id, "Record should have an ID"); + ok(!!crash.crashDate, "Record should have a crash date"); + var dateMS = crash.crashDate.valueOf(); + var twoMin = 1000 * 60 * 2; + ok(crashDateMS - twoMin <= dateMS && + dateMS <= crashDateMS + twoMin, + "Record's crash date should be nowish: " + + "now=" + crashDateMS + " recordDate=" + dateMS); + callback(crashMan, crash); + } + else { + setTimeout(tryGetCrash, 1000); + } + }), function (err) { + ok(false, "Error getting crashes: " + err); + SimpleTest.finish(); + }); + } + setTimeout(tryGetCrash, 1000); + + }, function () { + ok(false, "pruneOldCrashes error"); + SimpleTest.finish(); + }); +} -- cgit v1.2.3