Bug 663401 - browser_bug435788.js cleanup. r=mossop
authorDão Gottwald <dao@mozilla.com>
Wed, 15 Jun 2011 08:17:14 +0200
changeset 71071 545e27bf8b812a364c32b880094a9a84701fbcba
parent 71070 c72829d9cb2b5b69158037b6a224477d32b60ea0
child 71072 174a1d29c93e7181cd26949c382e18fd9c92b7b3
push id20486
push userdgottwald@mozilla.com
push dateWed, 15 Jun 2011 06:18:29 +0000
treeherdermozilla-central@174a1d29c93e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs663401, 435788
milestone7.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 663401 - browser_bug435788.js cleanup. r=mossop
toolkit/mozapps/plugins/tests/browser_bug435788.js
--- a/toolkit/mozapps/plugins/tests/browser_bug435788.js
+++ b/toolkit/mozapps/plugins/tests/browser_bug435788.js
@@ -1,29 +1,22 @@
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-
 const TEST_ROOT = "http://example.com/browser/toolkit/mozapps/plugins/tests/";
 
 Components.utils.import("resource://gre/modules/AddonManager.jsm");
 
-var gPrefs, gPFS, gDS, gSeenAvailable;
+var gPFS;
 
 function test() {
   waitForExplicitFinish();
 
-  gPrefs = Cc["@mozilla.org/preferences-service;1"].
-           getService(Ci.nsIPrefBranch);
-  gDS = Cc["@mozilla.org/file/directory_service;1"].
-        getService(Ci.nsIProperties);
   prepare_test_1();
 }
 
-function finishTest(e) {
-  gPrefs.clearUserPref("pfs.datasource.url");
+function finishTest() {
+  Services.prefs.clearUserPref("pfs.datasource.url");
   finish();
 }
 
 // Gets the number of plugin items in the detected list
 function getListCount() {
   var list = gPFS.document.getElementById("pluginList");
   return list.childNodes.length;
 }
@@ -99,638 +92,368 @@ function pfs_loaded() {
     docEle.removeEventListener("pageshow", page_shown, false);
     docEle.removeEventListener("wizardfinish", onwizardfinish, false);
     docEle.removeEventListener("wizardnext", onwizardnext, false);
   }, false);
 
   page_shown();
 }
 
+function startTest(num, missingPluginsArray) {
+  info("Test " + num);
+
+  gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
+                           "PFSWindow", "chrome,centerscreen,resizable=yes",
+                           {plugins: missingPluginsArray});
+
+  var testScope = this;
+
+  gPFS.addEventListener("load", function () {
+    gPFS.removeEventListener("load", arguments.callee, false);
+
+    pfs_loaded();
+
+    var seenAvailable = false;
+    var expectAvailable = typeof testScope["test_" + num + "_available"] == "function";
+
+    function availableListener() {
+      seenAvailable = true;
+
+      if (expectAvailable) {
+        executeSoon(function () {
+          testScope["test_" + num + "_available"]();
+          gPFS.document.documentElement.getButton("next").click();
+        });
+      } else {
+        ok(false, "Should not have found plugins to install");
+      }
+    }
+
+    function completeListener() {
+      if (expectAvailable)
+        ok(seenAvailable, "Should have seen the list of available plugins");
+
+      executeSoon(testScope["test_" + num + "_complete"]);
+    }
+
+    gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", availableListener);
+    gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", completeListener);
+
+    gPFS.addEventListener("unload", function () {
+      gPFS.removeEventListener("unload", arguments.callee, false);
+      gPFS.document.documentElement.wizardPages[1].removeEventListener("pageshow", availableListener, false);
+      gPFS.document.documentElement.wizardPages[4].removeEventListener("pageshow", completeListener, false);
+
+      num++;
+      if (typeof testScope["prepare_test_" + num] == "function")
+        testScope["prepare_test_" + num]();
+      else
+        finishTest();
+    });
+  });
+}
+
+function clickFinish() {
+  var finish = gPFS.document.documentElement.getButton("finish");
+  ok(!finish.hidden, "Finish button should not be hidden");
+  ok(!finish.disabled, "Finish button should not be disabled");
+  finish.click();
+}
+
 // Test a working installer
 function prepare_test_1() {
-  ok(true, "Test 1");
-  gPrefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_1.rdf");
+  Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_1.rdf");
 
   var missingPluginsArray = {
     "application/x-working-plugin": {
       mimetype: "application/x-working-plugin",
       pluginsPage: ""
     }
   };
 
-  gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
-                           "PFSWindow", "chrome,centerscreen,resizable=yes",
-                           {plugins: missingPluginsArray});
-  gPFS.addEventListener("load", test_1_start, false);
-}
-
-function test_1_start() {
-  gPFS.removeEventListener("load", test_1_start, false);
-
-  pfs_loaded();
-  gPFS.addEventListener("unload", function () {
-    gPFS.removeEventListener("unload", arguments.callee, false);
-    prepare_test_2();
-  }, false);
-  gSeenAvailable = false;
-
-  gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_1_available);
-  }, false);
-  gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_1_complete);
-  }, false);
+  startTest(1, missingPluginsArray);
 }
 
 function test_1_available() {
-  gSeenAvailable = true;
   is(getListCount(), 1, "Should have found 1 plugin to install");
   ok(hasListItem("Test plugin 1", null), "Should have seen the right plugin name");
-
-  gPFS.document.documentElement.getButton("next").click();
 }
 
 function test_1_complete() {
-  ok(gSeenAvailable, "Should have seen the list of available plugins");
   is(getResultCount(), 1, "Should have attempted to install 1 plugin");
   var item = getResultItem("Test plugin 1", null);
   ok(item, "Should have seen the installed item");
   is(item.status, "Installed", "Should have been a successful install");
 
-  var finish = gPFS.document.documentElement.getButton("finish");
-  ok(!finish.hidden, "Finish button should not be hidden");
-  ok(!finish.disabled, "Finish button should not be disabled");
-  finish.click();
+  clickFinish();
 }
 
 // Test a broken installer (returns exit code 1)
 function prepare_test_2() {
-  ok(true, "Test 2");
   var missingPluginsArray = {
     "application/x-broken-installer": {
       mimetype: "application/x-broken-installer",
       pluginsPage: ""
     }
   };
 
-  gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
-                           "PFSWindow", "chrome,centerscreen,resizable=yes",
-                           {plugins: missingPluginsArray});
-  gPFS.addEventListener("load", test_2_start, false);
-}
-
-function test_2_start() {
-  gPFS.removeEventListener("load", test_2_start, false);
-
-  pfs_loaded();
-  gPFS.addEventListener("unload", function () {
-    gPFS.removeEventListener("unload", arguments.callee, false);
-    prepare_test_3();
-  }, false);
-  gSeenAvailable = false;
-
-  gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_2_available);
-  }, false);
-  gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_2_complete);
-  }, false);
+  startTest(2, missingPluginsArray);
 }
 
 function test_2_available() {
-  gSeenAvailable = true;
   is(getListCount(), 1, "Should have found 1 plugin to install");
   ok(hasListItem("Test plugin 2", null), "Should have seen the right plugin name");
-
-  gPFS.document.documentElement.getButton("next").click();
 }
 
 function test_2_complete() {
-  ok(gSeenAvailable, "Should have seen the list of available plugins");
   is(getResultCount(), 1, "Should have attempted to install 1 plugin");
   var item = getResultItem("Test plugin 2", null);
   ok(item, "Should have seen the installed item");
   is(item.status, "Failed", "Should have been a failed install");
 
-  var finish = gPFS.document.documentElement.getButton("finish");
-  ok(!finish.hidden, "Finish button should not be hidden");
-  ok(!finish.disabled, "Finish button should not be disabled");
-  finish.click();
+  clickFinish();
 }
 
 // Test both working and broken together
 function prepare_test_3() {
-  ok(true, "Test 3");
   var missingPluginsArray = {
     "application/x-working-plugin": {
       mimetype: "application/x-working-plugin",
       pluginsPage: ""
     },
     "application/x-broken-installer": {
       mimetype: "application/x-broken-installer",
       pluginsPage: ""
     }
   };
 
-  gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
-                           "PFSWindow", "chrome,centerscreen,resizable=yes",
-                           {plugins: missingPluginsArray});
-  gPFS.addEventListener("load", test_3_start, false);
-}
-
-function test_3_start() {
-  gPFS.removeEventListener("load", test_3_start, false);
-
-  pfs_loaded();
-  gPFS.addEventListener("unload", function () {
-    gPFS.removeEventListener("unload", arguments.callee, false);
-    prepare_test_4();
-  }, false);
-  gSeenAvailable = false;
-
-  gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_3_available);
-  }, false);
-  gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_3_complete);
-  }, false);
+  startTest(3, missingPluginsArray);
 }
 
 function test_3_available() {
-  gSeenAvailable = true;
   is(getListCount(), 2, "Should have found 2 plugins to install");
   ok(hasListItem("Test plugin 1", null), "Should have seen the right plugin name");
   ok(hasListItem("Test plugin 2", null), "Should have seen the right plugin name");
-
-  gPFS.document.documentElement.getButton("next").click();
 }
 
 function test_3_complete() {
-  ok(gSeenAvailable, "Should have seen the list of available plugins");
   is(getResultCount(), 2, "Should have attempted to install 2 plugins");
   var item = getResultItem("Test plugin 1", null);
   ok(item, "Should have seen the installed item");
   is(item.status, "Installed", "Should have been a successful install");
   item = getResultItem("Test plugin 2", null);
   ok(item, "Should have seen the installed item");
   is(item.status, "Failed", "Should have been a failed install");
 
-  var finish = gPFS.document.documentElement.getButton("finish");
-  ok(!finish.hidden, "Finish button should not be hidden");
-  ok(!finish.disabled, "Finish button should not be disabled");
-  finish.click();
+  clickFinish();
 }
 
 // Test an installer with a bad hash
 function prepare_test_4() {
-  ok(true, "Test 4");
   var missingPluginsArray = {
     "application/x-broken-plugin-hash": {
       mimetype: "application/x-broken-plugin-hash",
       pluginsPage: ""
     }
   };
 
-  gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
-                           "PFSWindow", "chrome,centerscreen,resizable=yes",
-                           {plugins: missingPluginsArray});
-  gPFS.addEventListener("load", test_4_start, false);
-}
-
-function test_4_start() {
-  gPFS.removeEventListener("load", test_4_start, false);
-
-  pfs_loaded();
-  gPFS.addEventListener("unload", function () {
-    gPFS.removeEventListener("unload", arguments.callee, false);
-    prepare_test_5();
-  }, false);
-  gSeenAvailable = false;
-
-  gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_4_available);
-  }, false);
-  gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_4_complete);
-  }, false);
+  startTest(4, missingPluginsArray);
 }
 
 function test_4_available() {
-  gSeenAvailable = true;
   is(getListCount(), 1, "Should have found 1 plugin to install");
   ok(hasListItem("Test plugin 3", null), "Should have seen the right plugin name");
-
-  gPFS.document.documentElement.getButton("next").click();
 }
 
 function test_4_complete() {
-  ok(gSeenAvailable, "Should have seen the list of available plugins");
   is(getResultCount(), 1, "Should have attempted to install 1 plugin");
   var item = getResultItem("Test plugin 3", null);
   ok(item, "Should have seen the installed item");
   is(item.status, "Failed", "Should have not been a successful install");
 
-  var finish = gPFS.document.documentElement.getButton("finish");
-  ok(!finish.hidden, "Finish button should not be hidden");
-  ok(!finish.disabled, "Finish button should not be disabled");
-  finish.click();
+  clickFinish();
 }
 
 // Test a working xpi
 function prepare_test_5() {
-  ok(true, "Test 5");
-
   var missingPluginsArray = {
     "application/x-working-extension": {
       mimetype: "application/x-working-extension",
       pluginsPage: ""
     }
   };
 
-  gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
-                           "PFSWindow", "chrome,centerscreen,resizable=yes",
-                           {plugins: missingPluginsArray});
-  gPFS.addEventListener("load", test_5_start, false);
-}
-
-function test_5_start() {
-  gPFS.removeEventListener("load", test_5_start, false);
-
-  pfs_loaded();
-  gPFS.addEventListener("unload", function () {
-    gPFS.removeEventListener("unload", arguments.callee, false);
-    prepare_test_6();
-  }, false);
-  gSeenAvailable = false;
-
-  gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_5_available);
-  }, false);
-  gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_5_complete);
-  }, false);
+  startTest(5, missingPluginsArray);
 }
 
 function test_5_available() {
-  gSeenAvailable = true;
   is(getListCount(), 1, "Should have found 1 plugin to install");
   ok(hasListItem("Test extension 1", null), "Should have seen the right plugin name");
-
-  gPFS.document.documentElement.getButton("next").click();
 }
 
 function test_5_complete() {
-  ok(gSeenAvailable, "Should have seen the list of available plugins");
   is(getResultCount(), 1, "Should have attempted to install 1 plugin");
   var item = getResultItem("Test extension 1", null);
   ok(item, "Should have seen the installed item");
   is(item.status, "Installed", "Should have been a successful install");
 
   AddonManager.getAllInstalls(function(installs) {
     is(installs.length, 1, "Should be just one install");
     is(installs[0].state, AddonManager.STATE_INSTALLED, "Should be fully installed");
     is(installs[0].addon.id, "bug435788_1@tests.mozilla.org", "Should have installed the extension");
     installs[0].cancel();
 
-    var finish = gPFS.document.documentElement.getButton("finish");
-    ok(!finish.hidden, "Finish button should not be hidden");
-    ok(!finish.disabled, "Finish button should not be disabled");
-    finish.click();
+    clickFinish();
   });
 }
 
 // Test a broke xpi (no install.rdf)
 function prepare_test_6() {
-  ok(true, "Test 6");
   var missingPluginsArray = {
     "application/x-broken-extension": {
       mimetype: "application/x-broken-extension",
       pluginsPage: ""
     }
   };
 
-  gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
-                           "PFSWindow", "chrome,centerscreen,resizable=yes",
-                           {plugins: missingPluginsArray});
-  gPFS.addEventListener("load", test_6_start, false);
-}
-
-function test_6_start() {
-  gPFS.removeEventListener("load", test_6_start, false);
-
-  pfs_loaded();
-  gPFS.addEventListener("unload", function () {
-    gPFS.removeEventListener("unload", arguments.callee, false);
-    prepare_test_7();
-  }, false);
-  gSeenAvailable = false;
-
-  gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_6_available);
-  }, false);
-  gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_6_complete);
-  }, false);
+  startTest(6, missingPluginsArray);
 }
 
 function test_6_available() {
-  gSeenAvailable = true;
   is(getListCount(), 1, "Should have found 1 plugin to install");
   ok(hasListItem("Test extension 2", null), "Should have seen the right plugin name");
-
-  gPFS.document.documentElement.getButton("next").click();
 }
 
 function test_6_complete() {
-  ok(gSeenAvailable, "Should have seen the list of available plugins");
   is(getResultCount(), 1, "Should have attempted to install 1 plugin");
   var item = getResultItem("Test extension 2", null);
   ok(item, "Should have seen the installed item");
   is(item.status, "Failed", "Should have been a failed install");
 
-  var finish = gPFS.document.documentElement.getButton("finish");
-  ok(!finish.hidden, "Finish button should not be hidden");
-  ok(!finish.disabled, "Finish button should not be disabled");
-  finish.click();
+  clickFinish();
 }
 
 // Test both working and broken xpi
 function prepare_test_7() {
-  ok(true, "Test 7");
   var missingPluginsArray = {
     "application/x-working-extension": {
       mimetype: "application/x-working-extension",
       pluginsPage: ""
     },
     "application/x-broken-extension": {
       mimetype: "application/x-broken-extension",
       pluginsPage: ""
     }
   };
 
-  gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
-                           "PFSWindow", "chrome,centerscreen,resizable=yes",
-                           {plugins: missingPluginsArray});
-  gPFS.addEventListener("load", test_7_start, false);
-}
-
-function test_7_start() {
-  gPFS.removeEventListener("load", test_7_start, false);
-
-  pfs_loaded();
-  gPFS.addEventListener("unload", function () {
-    gPFS.removeEventListener("unload", arguments.callee, false);
-    prepare_test_8();
-  }, false);
-  gSeenAvailable = false;
-
-  gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_7_available);
-  }, false);
-  gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_7_complete);
-  }, false);
+  startTest(7, missingPluginsArray);
 }
 
 function test_7_available() {
-  gSeenAvailable = true;
   is(getListCount(), 2, "Should have found 2 plugins to install");
   ok(hasListItem("Test extension 1", null), "Should have seen the right plugin name");
   ok(hasListItem("Test extension 2", null), "Should have seen the right plugin name");
-
-  gPFS.document.documentElement.getButton("next").click();
 }
 
 function test_7_complete() {
-  ok(gSeenAvailable, "Should have seen the list of available plugins");
   is(getResultCount(), 2, "Should have attempted to install 2 plugins");
   var item = getResultItem("Test extension 1", null);
   ok(item, "Should have seen the installed item");
   is(item.status, "Installed", "Should have been a failed install");
   item = getResultItem("Test extension 2", null);
   ok(item, "Should have seen the installed item");
   is(item.status, "Failed", "Should have been a failed install");
 
   AddonManager.getAllInstalls(function(installs) {
     is(installs.length, 1, "Should be one active installs");
     installs[0].cancel();
 
-    gPFS.document.documentElement.getButton("finish").click();
+    clickFinish();
   });
-
-  var finish = gPFS.document.documentElement.getButton("finish");
-  ok(!finish.hidden, "Finish button should not be hidden");
-  ok(!finish.disabled, "Finish button should not be disabled");
-  finish.click();
 }
 
 // Test an xpi with a bad hash
 function prepare_test_8() {
-  ok(true, "Test 8");
   var missingPluginsArray = {
     "application/x-broken-extension-hash": {
       mimetype: "application/x-broken-extension-hash",
       pluginsPage: ""
     }
   };
 
-  gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
-                           "PFSWindow", "chrome,centerscreen,resizable=yes",
-                           {plugins: missingPluginsArray});
-  gPFS.addEventListener("load", test_8_start, false);
-}
-
-function test_8_start() {
-  gPFS.removeEventListener("load", test_8_start, false);
-
-  pfs_loaded();
-  gPFS.addEventListener("unload", function () {
-    gPFS.removeEventListener("unload", arguments.callee, false);
-    prepare_test_9();
-  }, false);
-  gSeenAvailable = false;
-
-  gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_8_available);
-  }, false);
-  gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_8_complete);
-  }, false);
+  startTest(8, missingPluginsArray);
 }
 
 function test_8_available() {
-  gSeenAvailable = true;
   is(getListCount(), 1, "Should have found 1 plugin to install");
   ok(hasListItem("Test extension 3", null), "Should have seen the right plugin name");
-
-  gPFS.document.documentElement.getButton("next").click();
 }
 
 function test_8_complete() {
-  ok(gSeenAvailable, "Should have seen the list of available plugins");
   is(getResultCount(), 1, "Should have attempted to install 1 plugin");
   var item = getResultItem("Test extension 3", null);
   ok(item, "Should have seen the installed item");
   is(item.status, "Failed", "Should have not been a successful install");
 
   AddonManager.getAllInstalls(function(installs) {
     is(installs.length, 0, "Should not be any installs");
 
-    gPFS.document.documentElement.getButton("finish").click();
+    clickFinish();
   });
-
-  var finish = gPFS.document.documentElement.getButton("finish");
-  ok(!finish.hidden, "Finish button should not be hidden");
-  ok(!finish.disabled, "Finish button should not be disabled");
-  finish.click();
 }
 
 // Test when no plugin exists in the datasource
 function prepare_test_9() {
-  ok(true, "Test 9");
   var missingPluginsArray = {
     "application/x-unknown-plugin": {
       mimetype: "application/x-unknown-plugin",
       pluginsPage: ""
     }
   };
 
-  gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
-                           "PFSWindow", "chrome,centerscreen,resizable=yes",
-                           {plugins: missingPluginsArray});
-  gPFS.addEventListener("load", test_9_start, false);
-}
-
-function test_9_start() {
-  gPFS.removeEventListener("load", test_9_start, false);
-
-  pfs_loaded();
-  gPFS.addEventListener("unload", function () {
-    gPFS.removeEventListener("unload", arguments.callee, false);
-    prepare_test_10();
-  }, false);
-
-  gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    ok(false, "Should not have found plugins to install");
-  }, false);
-  gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_9_complete);
-  }, false);
+  startTest(9, missingPluginsArray);
 }
 
 function test_9_complete() {
   is(getResultCount(), 0, "Should have found no plugins");
 
-  var finish = gPFS.document.documentElement.getButton("finish");
-  ok(!finish.hidden, "Finish button should not be hidden");
-  ok(!finish.disabled, "Finish button should not be disabled");
-  finish.click();
+  clickFinish();
 }
 
 // Test when the datasource is invalid xml
 function prepare_test_10() {
-  ok(true, "Test 10");
-  gPrefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_2.rdf");
+  Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_2.rdf");
 
   var missingPluginsArray = {
     "application/x-broken-xml": {
       mimetype: "application/x-broken-xml",
       pluginsPage: ""
     }
   };
 
-  gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
-                           "PFSWindow", "chrome,centerscreen,resizable=yes",
-                           {plugins: missingPluginsArray});
-  gPFS.addEventListener("load", test_10_start, false);
-}
-
-function test_10_start() {
-  gPFS.removeEventListener("load", test_10_start, false);
-
-  pfs_loaded();
-  gPFS.addEventListener("unload", function () {
-    gPFS.removeEventListener("unload", arguments.callee, false);
-    prepare_test_11();
-  }, false);
-
-  gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    ok(false, "Should not have found plugins to install");
-  }, false);
-  gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_10_complete);
-  }, false);
+  startTest(10, missingPluginsArray);
 }
 
 function test_10_complete() {
   is(getResultCount(), 0, "Should have found no plugins");
 
-  var finish = gPFS.document.documentElement.getButton("finish");
-  ok(!finish.hidden, "Finish button should not be hidden");
-  ok(!finish.disabled, "Finish button should not be disabled");
-  finish.click();
+  clickFinish();
 }
 
 // Test when no datasource is returned
 function prepare_test_11() {
-  ok(true, "Test 11");
-  gPrefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_foo.rdf");
+  Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_foo.rdf");
 
   var missingPluginsArray = {
     "application/x-missing-xml": {
       mimetype: "application/x-missing-xml",
       pluginsPage: ""
     }
   };
 
-  gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
-                           "PFSWindow", "chrome,centerscreen,resizable=yes",
-                           {plugins: missingPluginsArray});
-  gPFS.addEventListener("load", test_11_start, false);
-}
-
-function test_11_start() {
-  gPFS.removeEventListener("load", test_11_start, false);
-
-  pfs_loaded();
-  gPFS.addEventListener("unload", function () {
-    gPFS.removeEventListener("unload", arguments.callee, false);
-    finishTest();
-  }, false);
-
-  gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    ok(false, "Should not have found plugins to install");
-  }, false);
-  gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", function(e) {
-    e.currentTarget.removeEventListener(e.type, arguments.callee, false);
-    executeSoon(test_11_complete);
-  }, false);
+  startTest(11, missingPluginsArray);
 }
 
 function test_11_complete() {
   is(getResultCount(), 0, "Should have found no plugins");
 
-  var finish = gPFS.document.documentElement.getButton("finish");
-  ok(!finish.hidden, "Finish button should not be hidden");
-  ok(!finish.disabled, "Finish button should not be disabled");
-  finish.click();
+  clickFinish();
 }