Bug 1449255: Part 11c - Rename test_bug514327_3 to test_blocklist_plugin_outdated.js. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Tue, 27 Mar 2018 15:44:49 -0700
changeset 773479 134012be602aabe87fc048b33a2b62dc5d1233ab
parent 773478 c001e343c0eeb3dab0712cc4498af49591d86524
child 773480 e84d17c68fe3d61518d700be78df6e41d0b41366
push id104243
push usermaglione.k@gmail.com
push dateWed, 28 Mar 2018 00:15:32 +0000
reviewersaswan
bugs1449255
milestone61.0a1
Bug 1449255: Part 11c - Rename test_bug514327_3 to test_blocklist_plugin_outdated.js. r?aswan MozReview-Commit-ID: 8mHmOWbgDC3
toolkit/mozapps/extensions/test/xpcshell/test_blocklist_plugin_outdated.js
toolkit/mozapps/extensions/test/xpcshell/test_bug514327_3.js
rename from toolkit/mozapps/extensions/test/xpcshell/test_bug514327_3.js
rename to toolkit/mozapps/extensions/test/xpcshell/test_blocklist_plugin_outdated.js
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug514327_3.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_plugin_outdated.js
@@ -1,22 +1,22 @@
 /* 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/. */
 
+const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+
 ChromeUtils.import("resource://testing-common/httpd.js");
 ChromeUtils.import("resource://testing-common/MockRegistrar.jsm");
 
 const nsIBLS = Ci.nsIBlocklistService;
-const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
 
 var gBlocklist = null;
-var gTestserver = null;
-
-var gNextTestPart = null;
+var gTestserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
+gTestserver.registerDirectory("/data/", do_get_file("data"));
 
 
 var PLUGINS = [{
   // Tests a plugin whose state goes from not-blocked, to outdated
   name: "test_bug514327_outdated",
   version: "5",
   disabled: false,
   blocklisted: false
@@ -37,96 +37,72 @@ var PLUGINS = [{
 
 // A fake plugin host for the blocklist service to use
 var PluginHost = {
   getPluginTags(countRef) {
     countRef.value = PLUGINS.length;
     return PLUGINS;
   },
 
-  QueryInterface(iid) {
-    if (iid.equals(Ci.nsIPluginHost)
-     || iid.equals(Ci.nsISupports))
-      return this;
-
-    throw Cr.NS_ERROR_NO_INTERFACE;
-  }
+  QueryInterface: XPCOMUtils.generateQI(["nsIPluginHost"]),
 };
 
-// Don't need the full interface, attempts to call other methods will just
-// throw which is just fine
-var WindowWatcher = {
-  openWindow(parent, url, name, features, args) {
-    // Should be called to list the newly blocklisted items
-    Assert.equal(url, URI_EXTENSION_BLOCKLIST_DIALOG);
+var BlocklistPrompt = {
+  prompt(list) {
     // Should only include one item
-    Assert.equal(args.wrappedJSObject.list.length, 1);
+    Assert.equal(list.length, 1);
     // And that item should be the blocked plugin, not the outdated one
-    var item = args.wrappedJSObject.list[0];
+    var item = list[0];
     Assert.ok(item.item instanceof Ci.nsIPluginTag);
     Assert.notEqual(item.name, "test_bug514327_outdated");
-
-    // Call the next test after the blocklist has finished up
-    do_timeout(0, gNextTestPart);
   },
 
-  QueryInterface(iid) {
-    if (iid.equals(Ci.nsIWindowWatcher)
-     || iid.equals(Ci.nsISupports))
-      return this;
-
-    throw Cr.NS_ERROR_NO_INTERFACE;
-  }
+  QueryInterface: XPCOMUtils.generateQI(["nsIBlocklistPrompt"]),
 };
 
-MockRegistrar.register("@mozilla.org/plugin/host;1", PluginHost);
-MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher);
-
 
-function do_update_blocklist(aDatafile, aNextPart) {
-  gNextTestPart = aNextPart;
+async function loadBlocklist(file) {
+  let blocklistUpdated = TestUtils.topicObserved("blocklist-updated");
 
-  Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/" + aDatafile);
-  gBlocklist.QueryInterface(Ci.nsITimerCallback).notify(null);
+  Services.prefs.setCharPref("extensions.blocklist.url",
+                             "http://example.com/data/" + file);
+  Services.blocklist.QueryInterface(Ci.nsITimerCallback).notify(null);
+
+  await blocklistUpdated;
 }
 
-function run_test() {
-  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
+MockRegistrar.register("@mozilla.org/plugin/host;1", PluginHost);
 
-  gTestserver = new HttpServer();
-  gTestserver.registerDirectory("/data/", do_get_file("data"));
-  gTestserver.start(-1);
-  gPort = gTestserver.identity.primaryPort;
+let factory = XPCOMUtils.generateSingletonFactory(function() { return BlocklistPrompt; });
+Cm.registerFactory(Components.ID("{26d32654-30c7-485d-b983-b4d2568aebba}"),
+                   "Blocklist Prompt",
+                   "@mozilla.org/addons/blocklist-prompt;1", factory);
 
-  startupManager();
+add_task(async function setup() {
+  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
 
   // initialize the blocklist with no entries
   copyBlocklistToProfile(do_get_file("data/test_bug514327_3_empty.xml"));
 
-  gBlocklist = Cc["@mozilla.org/extensions/blocklist;1"].getService(nsIBLS);
+  await promiseStartupManager();
+
+  gBlocklist = Services.blocklist;
 
   // should NOT be marked as outdated by the blocklist
   Assert.ok(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_NOT_BLOCKED);
+});
 
-  do_test_pending();
-
+add_task(async function test_part_1() {
   // update blocklist with data that marks the plugin as outdated
-  do_update_blocklist("test_bug514327_3_outdated_1.xml", test_part_1);
-}
+  await loadBlocklist("test_bug514327_3_outdated_1.xml");
 
-function test_part_1() {
   // plugin should now be marked as outdated
   Assert.ok(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_OUTDATED);
 
+});
+
+add_task(async function test_part_2() {
   // update blocklist with data that marks the plugin as outdated
-  do_update_blocklist("test_bug514327_3_outdated_2.xml", test_part_2);
-}
+  await loadBlocklist("test_bug514327_3_outdated_2.xml");
 
-function test_part_2() {
   // plugin should still be marked as outdated
   Assert.ok(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_OUTDATED);
-
-  finish();
-}
-
-function finish() {
-  gTestserver.stop(do_test_finished);
-}
+});