Bug 1508942 - Fix or remove tests broken by plugin removal. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 27 Nov 2018 14:40:29 +1300
changeset 33798 d01f1963d14968aeffa96a43c22715edc9fab90a
parent 33797 f35c6c93bcd8a9e91a74cc83bd3be2d68d409186
child 33799 61f67f491dd7c5c1e80be45aeadb3d5cbba37978
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersmkmelin
bugs1508942
Bug 1508942 - Fix or remove tests broken by plugin removal. r=mkmelin
mail/test/mozmill/content-policy/test-plugins-policy.js
mail/test/mozmill/content-tabs/test-plugin-blocked.js
mail/test/mozmill/content-tabs/test-plugin-crashing.js
mail/test/mozmill/content-tabs/test-plugin-outdated.js
--- a/mail/test/mozmill/content-policy/test-plugins-policy.js
+++ b/mail/test/mozmill/content-policy/test-plugins-policy.js
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /**
  * Checks if plugins are enabled in messages correctly or not.
+ * As of bug 1508942, plugins are no longer enabled in any context.
  */
 
 "use strict";
 
 var MODULE_NAME = 'test-plugins-policy';
 
 var RELATIVE_ROOT = '../shared-modules';
 var MODULE_REQUIRES = ['folder-display-helpers', 'window-helpers',
@@ -41,20 +42,16 @@ var setupModule = function (module) {
   let wh = collector.getModule('window-helpers');
   wh.installInto(module);
   composeHelper = collector.getModule('compose-helpers');
   composeHelper.installInto(module);
   let cth = collector.getModule('content-tab-helpers');
   cth.installInto(module);
 
   folder = create_folder("pluginPolicy");
-
-  // Ensure the test plugin is enabled
-  let plugin = get_test_plugin();
-  plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
 };
 
 function addToFolder(aSubject, aBody, aFolder) {
   let msgId = Cc["@mozilla.org/uuid-generator;1"]
                           .getService(Ci.nsIUUIDGenerator)
                           .generateUUID() +"@mozillamessaging.invalid";
 
   let source = "From - Sat Nov  1 12:39:54 2008\n" +
@@ -157,18 +154,18 @@ function test_checkPluginsInNonMessageCo
   select_none();
 
   // load something non-message-like in the message pane
   mozmill.getMail3PaneController().window.GetMessagePaneFrame().location.href =
     url + "plugin.html";
 
   wait_for_message_display_completion();
 
-  if (!isPluginLoaded(mozmill.getMail3PaneController().window.content.document))
-    throw new Error("Plugin is not turned on in content in message pane - it should be.");
+  if (isPluginLoaded(mozmill.getMail3PaneController().window.content.document))
+    throw new Error("Plugin is turned on in content in message pane - it should not be.");
 }
 
 function test_3paneWindowDeniedAgain() {
   select_click_row(0);
 
   assert_selected_and_displayed(0);
 
   // Now check that the content hasn't been loaded
@@ -186,16 +183,16 @@ function test_checkStandaloneMessageWind
 
 function test_checkContentTab() {
   // To open a tab we're going to have to cheat and use tabmail so we can load
   // in the data of what we want.
   let preCount = mc.tabmail.tabContainer.childNodes.length;
 
   let newTab = open_content_tab_with_url(url + "plugin.html");
 
-  if (!isPluginLoaded(mc.tabmail.getBrowserForSelectedTab().contentDocument))
-    throw new Error("Plugin has been unexpectedly blocked in content tab");
+  if (isPluginLoaded(mc.tabmail.getBrowserForSelectedTab().contentDocument))
+    throw new Error("Plugin has been unexpectedly not blocked in content tab");
 
   mc.tabmail.closeTab(newTab);
 
   if (mc.tabmail.tabContainer.childNodes.length != preCount)
     throw new Error("The content tab didn't close");
 }
deleted file mode 100644
--- a/mail/test/mozmill/content-tabs/test-plugin-blocked.js
+++ /dev/null
@@ -1,122 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-"use strict";
-
-var MODULE_NAME = 'test-plugin-blocked';
-
-var RELATIVE_ROOT = '../shared-modules';
-var MODULE_REQUIRES = ['folder-display-helpers', 'content-tab-helpers'];
-
-ChromeUtils.import('resource://gre/modules/Services.jsm');
-
-var gOldStartUrl = null;
-var gOldBlDetailsUrl = null;
-var gOldPluginUpdateUrl = null;
-
-var testDone = false;
-
-var kPluginId = "test-plugin";
-var kStartPagePref = "mailnews.start_page.override_url";
-var kBlDetailsPagePref = "extensions.blocklist.detailsURL";
-var kPluginsUpdatePref = "plugins.update.url";
-// RELATIVE_ROOT messes with the collector, so we have to bring the path back
-// so we get the right path for the resources.
-var kUrl = collector.addHttpResource('../content-tabs/html', '');
-var kPluginUrl = kUrl + "plugin.html";
-var kPluginBlocklistUrl = kUrl + "blocklistHard.xml";
-var kBlDetailsUrl = kUrl + "blocklist_details.html";
-var kPluginUpdateUrl = kUrl + "plugin_update.html";
-
-function setupModule(module) {
-  let fdh = collector.getModule('folder-display-helpers');
-  fdh.installInto(module);
-  let cth = collector.getModule('content-tab-helpers');
-  cth.installInto(module);
-
-  // Set the pref so that what's new opens a local url - we'll save the old
-  // url and put it back in the module teardown.
-  gOldStartUrl = Services.prefs.getCharPref(kStartPagePref);
-  gOldBlDetailsUrl = Services.prefs.getCharPref(kBlDetailsPagePref);
-  gOldPluginUpdateUrl = Services.prefs.getCharPref(kPluginsUpdatePref);
-
-  Services.prefs.setCharPref(kStartPagePref, kPluginUrl);
-  Services.prefs.setCharPref(kBlDetailsPagePref, kBlDetailsUrl);
-  Services.prefs.setCharPref(kPluginsUpdatePref, kPluginUpdateUrl);
-};
-
-function teardownModule(module) {
-  Services.prefs.setCharPref(kStartPagePref, gOldStartUrl);
-  Services.prefs.setCharPref(kBlDetailsPagePref, gOldBlDetailsUrl);
-  Services.prefs.setCharPref(kPluginsUpdatePref, gOldPluginUpdateUrl);
-}
-
-/* Tests that the notification bar appears for plugins that
- * are blocklisted.  Ensures that the notification bar gives
- * links to the human-readable blocklist, as well as the
- * plugin update page.
- */
-function test_blocklisted_plugin_notification() {
-  let plugin = get_test_plugin();
-  let pluginState = plugin.enabledState;
-  plugin.enabledState = plugin.STATE_ENABLED;
-  assert_not_equals(plugin, null, "Test plugin not found");
-  assert_false(plugin.blocklisted, "Test plugin was unexpectedly blocklisted");
-  assert_false(plugin.disabled, "Test plugin not enabled");
-
-  Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
-
-  setAndUpdateBlocklist(mc, kPluginBlocklistUrl, function() {
-    assert_true(plugin.blocklisted, "Test plugin was not properly blocklisted");
-    subtest_blocklisted_plugin_notification();
-  });
-
-  mc.waitFor(function () { return testDone; }, "Plugin test taking too long",
-             100000, 1000);
-
-  let finishedReset = false;
-
-  resetBlocklist(mc, function() { finishedReset = true; });
-
-  mc.waitFor(() => finishedReset, "Reset blocklist took too long");
-
-  plugin.enabledState = pluginState;
-
-  Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
-}
-
-function subtest_blocklisted_plugin_notification() {
-  // Prepare to capture the notification bar
-  NotificationWatcher.planForNotification(mc);
-  let pluginTab = open_content_tab_with_click(mc.menus.helpMenu.whatsNew,
-                                              kPluginUrl);
-  NotificationWatcher.waitForNotification(mc);
-
-  // If we got here, then the notification bar appeared.  Now
-  // let's make sure it displayed the right message.
-  let notificationBar = get_notification_bar_for_tab(mc.tabmail.selectedTab);
-  assert_not_equals(null, notificationBar, "Could not get notification bar");
-  let blNotification = notificationBar.getNotificationWithValue("blocked-plugins");
-  assert_not_equals(null, blNotification, "Notification value was not correct");
-
-  // buttons[0] should be the "more info" button, and buttons[1]
-  // should be the "update my plugins" button.
-  let buttons = notificationBar.getElementsByTagName("button");
-
-  // Let's make sure that the "more info" button opens up a tab
-  // and takes us to the right place.
-  let detailsTab = open_content_tab_with_click(buttons[0], kBlDetailsUrl);
-  assert_tab_has_title(detailsTab, "Plugin Blocklist Details");
-  mc.tabmail.closeTab(detailsTab);
-
-  // Let's make sure that the "update my plugins" button opens up
-  // a tab and takes us to the right place.
-  let updateTab = open_content_tab_with_click(buttons[1], kPluginUpdateUrl);
-  assert_tab_has_title(updateTab, "Plugin Update Page");
-  mc.tabmail.closeTab(updateTab);
-
-  // Close the tab to finish up.
-  mc.tabmail.closeTab(pluginTab);
-  testDone = true;
-}
deleted file mode 100644
--- a/mail/test/mozmill/content-tabs/test-plugin-crashing.js
+++ /dev/null
@@ -1,280 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-"use strict";
-
-var MODULE_NAME = 'test-plugin-crashing';
-
-var RELATIVE_ROOT = '../shared-modules';
-var MODULE_REQUIRES = ['folder-display-helpers', 'content-tab-helpers'];
-
-var frame = {};
-ChromeUtils.import("chrome://mozmill/content/modules/frame.js", frame);
-
-ChromeUtils.import('resource://gre/modules/Services.jsm');
-
-var gContentWindow = null;
-var gJSObject = null;
-var gTabDoc = null;
-var gOldStartPage = null;
-var gOldPluginCrashDocPage = null;
-var crashReporter = null;
-var kPluginId = "test-plugin";
-var kStartPagePref = "mailnews.start_page.override_url";
-var kPluginCrashDocPref = "plugins.crash.supportUrl";
-// RELATIVE_ROOT messes with the collector, so we have to bring the path back
-// so we get the right path for the resources.
-var kUrl = collector.addHttpResource('../content-tabs/html', '');
-var kPluginUrl = kUrl + "plugin.html";
-var kPluginCrashDocUrl = kUrl + "plugin_crashed_help.html";
-
-function setupModule(module) {
-  let fdh = collector.getModule('folder-display-helpers');
-  fdh.installInto(module);
-  let cth = collector.getModule('content-tab-helpers');
-  cth.installInto(module);
-
-  // Set the pref so that what's new opens a local url - we'll save the old
-  // url and put it back in the module teardown.
-  gOldStartPage = Services.prefs.getCharPref(kStartPagePref);
-  gOldPluginCrashDocPage = Services.prefs.getCharPref(kPluginCrashDocPref);
-
-  Services.prefs.setCharPref(kStartPagePref, kPluginUrl);
-  Services.prefs.setCharPref(kPluginCrashDocPref, kPluginCrashDocUrl);
-
-  try {
-    crashReporter = Cc["@mozilla.org/toolkit/crash-reporter;1"]
-                      .getService(Ci.nsICrashReporter);
-    // The crash reporter must be enabled.
-    assert_true(crashReporter.enabled, "Mandatory Crash reporter is not enabled");
-  } catch (e) {
-    // Crashreporter is not working.
-  }
-
-
-  /* Bug 689580 - these crash tests fail randomly on 64-bit OSX.  We'll
-   * disable them for now, until we can figure out what's going on.
-   */
-  let is64BitOSX = (mc.mozmillModule.isMac &&
-                    Services.appinfo.XPCOMABI.includes("x86_64-"));
-
-  // These tests are no good if the crash reporter is disabled, or if
-  // we don't have out-of-process plugins enabled.
-  if (is64BitOSX ||  // XXX Remove once Bug 689580 is resolved
-      !plugins_run_in_separate_processes(mc) || !crashReporter ||
-      !crashReporter.enabled) {
-    let funcsToSkip = [test_can_crash_plugin,
-                       test_crashed_plugin_notification_bar,
-                       test_crashed_plugin_notification_inline];
-
-    funcsToSkip.forEach(function(func) {
-      func.__force_skip__ = true;
-    });
-  }
-  let plugin = get_test_plugin();
-  plugin.enabledState = plugin.STATE_ENABLED;
-};
-
-function teardownModule(module) {
-  Services.prefs.setCharPref(kStartPagePref, gOldStartPage);
-  Services.prefs.setCharPref(kPluginCrashDocPref, gOldPluginCrashDocPage);
-}
-
-function setupTest() {
-  let tab = open_content_tab_with_click(mc.menus.helpMenu.whatsNew, kPluginUrl);
-  assert_tab_has_title(tab, "Plugin Test");
-
-  // Check that window.content is set up correctly wrt content-primary and
-  // content-targetable.
-  if (mc.window.content.location != kPluginUrl)
-    throw new Error("window.content is not set to the url loaded, incorrect type=\"...\"?");
-
-  gContentWindow = mc.tabmail.selectedTab.browser.contentWindow;
-  gJSObject = gContentWindow.wrappedJSObject;
-
-  // Strangely, in order to manipulate the embedded plugin,
-  // we have to use getElementById within the context of the
-  // wrappedJSObject of the content tab browser.
-  gTabDoc = gJSObject.window.document;
-
-}
-
-function teardownTest() {
-  let tab = mc.tabmail.selectedTab;
-  mc.tabmail.closeTab(tab);
-}
-
-/* PluginCrashObserver lets us plan for and wait for plugin crashes. After
- * a plugin has crashed, PluginCrashObserver cleans up the minidump files
- * left behind.
- *
- * IMPORTANT:  Calls to planForCrash must be followed by waitForCrash in
- * order to remove PluginCrashObserver from the nsIObserverService.
- */
-var PluginCrashObserver = {
-  _sawCrash: false,
-
-  planForCrash: function(aController) {
-    this._sawCrash = false;
-    Services.obs.addObserver(this, "plugin-crashed");
-  },
-
-  waitForCrash: function(aController) {
-    if (!this._sawCrash)
-      aController.waitFor(() => this._sawCrash, "Timeout waiting for crash",
-                          5000, 100);
-
-    Services.obs.removeObserver(this, "plugin-crashed");
-  },
-
-  observe: function(aSubject, aTopic, aData) {
-    if (aTopic != "plugin-crashed")
-      return;
-
-    try {
-      this.removeMinidump(aSubject.QueryInterface(Ci.nsIPropertyBag2));
-    } catch (ex) {
-      Cu.reportError(ex);
-      frame.events.fail({exception: ex, test: frame.events.currentTest});
-    }
-  },
-
-  removeMinidump: function PluginCrashObserver_removeMinidump(aPropBag) {
-    this._sawCrash = true;
-
-    let profD = Services.dirsvc.get("ProfD", Ci.nsIFile);
-    profD.append("minidumps");
-
-    // Let's check to see if a minidump was created.  If so, delete
-    // it (along with the .extra file)
-    let crashId = aPropBag.getPropertyAsAString("pluginDumpID");
-    let dumpFile = profD.clone();
-    dumpFile.append(crashId + ".dmp");
-    let extraFile = profD.clone();
-    extraFile.append(crashId + ".extra");
-
-    // Retry deletion until crash reporter releases the file.
-    function remove_locked_file(aFile) {
-      function try_removal(aFile) {
-        try {
-          // Yield to the event loop while waiting for the file to get unlocked.
-          mc.sleep(0);
-          aFile.remove(false);
-        } catch (e) {
-          if (e.result == Cr.NS_ERROR_FILE_IS_LOCKED)
-            return false;
-
-          throw e;
-        }
-        return true;
-      }
-
-      mc.waitFor(() => try_removal(aFile) === true,
-                 `File ${aFile.leafName} couldn't be removed due to a lock`, 20000, 250);
-      assert_false(aFile.exists());
-    }
-
-    if (dumpFile.exists())
-      remove_locked_file(dumpFile);
-
-    if (extraFile.exists())
-      remove_locked_file(extraFile);
-  }
-}
-
-/* Crash the plugin */
-function crash_plugin() {
-  try {
-    let plugin = gTabDoc.getElementById(kPluginId);
-    PluginCrashObserver.planForCrash(mc);
-    plugin.crash();
-  } catch(e) {
-    PluginCrashObserver.waitForCrash(mc);
-    return true;
-  }
-  return false;
-}
-
-/* A quick sanity check - let's ensure that we can actually
- * crash the plugin.
- */
-function test_can_crash_plugin() {
-  assert_true(crash_plugin());
-}
-
-/* Test to check that if a plugin crashes, and the plugin's
- * <object> is too small to display a message, then a
- * notification box appears to tell us about the crash.
- */
-function test_crashed_plugin_notification_bar() {
-  let plugin = gTabDoc.getElementById(kPluginId);
-  plugin.style.width = '10px';
-  plugin.style.height = '10px';
-
-  NotificationWatcher.planForNotification(mc);
-  assert_true(crash_plugin());
-  NotificationWatcher.waitForNotification(mc);
-}
-
-/* Test that if a plugin crashes, and the plugin's <object>
- * is large enough to display a message, it'll display the
- * appropriate crash message.
- */
-function test_crashed_plugin_notification_inline() {
-  let plugin = gTabDoc.getElementById(kPluginId);
-
-  plugin.style.width = '500px';
-  plugin.style.height = '500px';
-
-  assert_true(crash_plugin());
-
-  /* This function attempts to return the status div on the
-   * crashed plugin widget.  Returns null on failure.
-   */
-  function getStatusDiv() {
-    let submitDiv = gContentWindow.document
-                                  .getAnonymousElementByAttribute(plugin,
-                                                                  "class",
-                                                                  "submitStatus");
-    return submitDiv;
-  }
-
-  let submitDiv = null;
-  mc.waitFor(() => (submitDiv = getStatusDiv()) != null,
-             "Timeout waiting for submit status to appear",
-             5000, 100);
-
-  assert_equals(null, mc.tabmail.selectedTab.browser.parentNode
-                                .getNotificationWithValue("plugin-crashed"));
-
-  let statusString = submitDiv.getAttribute("status");
-  if (!statusString) {
-    let submitStatusChanged = false;
-    let observer = new gContentWindow.MutationObserver(function handleMutations(mutations) {
-      submitStatusChanged = true;
-    });
-    observer.observe(submitDiv, { attributes: true });
-
-    mc.waitFor(() => submitStatusChanged,
-               "Timed out: Notification existed and did not disappear.");
-    observer.disconnect();
-  }
-
-  // Depending on the environment we're running this test on,
-  // the status attribute might be "noReport" or "please".
-  assert_true(statusString == "noReport" || statusString == "please",
-              "Expected the status to be \"noReport\" or \"please\". " +
-              "Instead, it was " + statusString);
-
-  // Make sure that the help link in the inline notification works.
-  let helpIcon = gContentWindow.document
-                               .getAnonymousElementByAttribute(plugin,
-                                                               "class",
-                                                               "helpIcon");
-  assert_not_equals(null, helpIcon, "Help Icon should have been available");
-
-  let helpTab = open_content_tab_with_click(helpIcon, kPluginCrashDocUrl);
-  assert_tab_has_title(helpTab, "Plugin Crashed Help");
-  mc.tabmail.closeTab(helpTab);
-}
deleted file mode 100644
--- a/mail/test/mozmill/content-tabs/test-plugin-outdated.js
+++ /dev/null
@@ -1,99 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-"use strict";
-
-var MODULE_NAME = 'test-plugin-outdated';
-
-var RELATIVE_ROOT = '../shared-modules';
-var MODULE_REQUIRES = ['folder-display-helpers', 'content-tab-helpers'];
-
-ChromeUtils.import('resource://gre/modules/Services.jsm');
-
-var gOldStartUrl = null;
-var gOldPluginUpdateUrl = null;
-
-var kStartPagePref = "mailnews.start_page.override_url";
-var kPluginsUpdatePref = "plugins.update.url";
-// RELATIVE_ROOT messes with the collector, so we have to bring the path back
-// so we get the right path for the resources.
-var kUrl = collector.addHttpResource('../content-tabs/html', '');
-var kPluginUrl = kUrl + "plugin.html";
-var kPluginUpdateUrl = kUrl + "plugin_update.html";
-var kPluginBlocklistUrl = kUrl + "blocklist.xml";
-
-var testDone = false;
-
-function setupModule(module) {
-  let fdh = collector.getModule('folder-display-helpers');
-  fdh.installInto(module);
-  let cth = collector.getModule('content-tab-helpers');
-  cth.installInto(module);
-
-  // Set the pref so that what's new opens a local url - we'll save the old
-  // url and put it back in the module teardown.
-  gOldStartUrl = Services.prefs.getCharPref(kStartPagePref);
-
-  // Stash the old plugin update URL so we can put it back on module
-  // teardown
-  gOldPluginUpdateUrl = Services.prefs.getCharPref(kPluginsUpdatePref);
-
-  Services.prefs.setCharPref(kStartPagePref, kPluginUrl);
-  Services.prefs.setCharPref(kPluginsUpdatePref, kPluginUpdateUrl);
-
-  let plugin = get_test_plugin();
-  plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
-}
-
-function teardownModule(module) {
-  Services.prefs.setCharPref(kStartPagePref, gOldStartUrl);
-  Services.prefs.setCharPref(kPluginsUpdatePref, gOldPluginUpdateUrl);
-}
-
-function test_outdated_plugin_notification() {
-  let plugin = get_test_plugin();
-  assert_not_equals(plugin, null, "Test plugin not found");
-
-  Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
-
-  setAndUpdateBlocklist(mc, kPluginBlocklistUrl, function() {
-    subtest_outdated_plugin_notification();
-  });
-
-  mc.waitFor(function () { return testDone; }, "Plugin test taking too long",
-             100000, 1000);
-
-  let finishedReset = false;
-
-  resetBlocklist(mc, function() { finishedReset = true; });
-
-  mc.waitFor(() => finishedReset, "Reset blocklist took too long");
-
-  Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
-}
-
-function subtest_outdated_plugin_notification() {
-  // Prepare to capture the notification bar
-  NotificationWatcher.planForNotification(mc);
-  let pluginTab = open_content_tab_with_click(mc.menus.helpMenu.whatsNew,
-                                              kPluginUrl);
-  NotificationWatcher.waitForNotification(mc);
-
-  let notificationBar = get_notification_bar_for_tab(mc.tabmail.selectedTab);
-  assert_not_equals(null, notificationBar, "Could not get notification bar");
-  let notifValue = notificationBar.getNotificationWithValue("outdated-plugins");
-  assert_not_equals(null, notifValue, "Notification value was not correct");
-
-  // aButton should be the "update my plugins" button.
-  let aButton = notificationBar.querySelector("button");
-
-  // Let's make sure that the "update my plugins" button opens up
-  // a tab and takes us to the right place.
-  let updateTab = open_content_tab_with_click(aButton, kPluginUpdateUrl);
-  assert_tab_has_title(updateTab, "Plugin Update Page");
-  mc.tabmail.closeTab(updateTab);
-
-  mc.tabmail.closeTab(pluginTab);
-  testDone = true;
-}