Bug 592859 Update browser chrome tests to only use chrome paths for mochitest to prep for android support r=ctalbert a=NPOTB
authorJoel Maher <jmaher@mozilla.com>
Fri, 10 Sep 2010 10:20:38 -0700
changeset 52393 f9fcf102493f6bc2a4c9dac8fc004ffdb92a4b63
parent 52392 ab61a67aebb01c3396dbb136f94a23699702405f
child 52394 47c6a53ffd8cbc5f9c610a39008e2d2893148339
push idunknown
push userunknown
push dateunknown
reviewersctalbert, NPOTB
bugs592859
milestone2.0b6pre
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 592859 Update browser chrome tests to only use chrome paths for mochitest to prep for android support r=ctalbert a=NPOTB
browser/base/content/test/browser_bug462673.js
browser/base/content/test/browser_bug550565.js
browser/base/content/test/browser_bug553455.js
browser/base/content/test/browser_discovery.js
browser/base/content/test/browser_page_style_menu.js
browser/base/content/test/browser_pluginnotification.js
browser/base/content/test/file_bug550565_popup.html
browser/components/preferences/tests/browser_privacypane_1.js
browser/components/preferences/tests/browser_privacypane_2.js
browser/components/preferences/tests/browser_privacypane_3.js
browser/components/preferences/tests/browser_privacypane_4.js
browser/components/preferences/tests/browser_privacypane_5.js
browser/components/preferences/tests/browser_privacypane_6.js
browser/components/preferences/tests/browser_privacypane_7.js
browser/components/preferences/tests/browser_privacypane_8.js
browser/components/sessionstore/test/browser/browser_248970_b.js
browser/components/sessionstore/test/browser/browser_346337.js
browser/components/sessionstore/test/browser/browser_408470.js
browser/components/sessionstore/test/browser/browser_454908.js
browser/components/sessionstore/test/browser/browser_456342.js
browser/components/sessionstore/test/browser/browser_459906_sample.html
browser/components/sessionstore/test/browser/browser_463205.js
browser/components/sessionstore/test/browser/browser_485482.js
browser/fuel/test/browser_Browser.js
docshell/test/browser/browser_bug134911.js
docshell/test/browser/browser_bug92473.js
layout/style/test/browser_bug453896.js
testing/mochitest/browser-harness.xul
testing/mochitest/browser-test.js
toolkit/content/tests/browser/browser_save_resend_postdata.js
toolkit/content/tests/browser/common/_loadAll.js
toolkit/mozapps/extensions/test/browser/head.js
toolkit/mozapps/extensions/test/xpinstall/browser_localfile.js
toolkit/mozapps/extensions/test/xpinstall/browser_localfile2.js
toolkit/mozapps/extensions/test/xpinstall/head.js
--- a/browser/base/content/test/browser_bug462673.js
+++ b/browser/base/content/test/browser_bug462673.js
@@ -42,12 +42,12 @@ function runOneTest() {
         win.close();
         if (runs.length)
           runOneTest();
         else
           finish();
       });
     }, true);
 
-    browser.contentWindow.location =
-      "chrome://mochikit/content/browser/browser/base/content/test/test_bug462673.html";
+    var rootDir = getRootDirectory(gTestPath);
+    browser.contentWindow.location = rootDir + "test_bug462673.html"
   }, false);
 }
--- a/browser/base/content/test/browser_bug550565.js
+++ b/browser/base/content/test/browser_bug550565.js
@@ -1,12 +1,12 @@
 function test() {
   waitForExplicitFinish();
 
-  let testPath = "chrome://mochikit/content/browser/browser/base/content/test/";
+  let testPath = getRootDirectory(gTestPath);
 
   let tab = gBrowser.addTab(testPath + "file_bug550565_popup.html");
 
   tab.linkedBrowser.addEventListener('DOMContentLoaded', function() {
     let expectedIcon = testPath + "file_bug550565_favicon.ico";
 
     is(gBrowser.getIcon(tab), expectedIcon, "Correct icon before pushState.");
     tab.linkedBrowser.contentWindow.history.pushState("page2", "page2", "page2");
--- a/browser/base/content/test/browser_bug553455.js
+++ b/browser/base/content/test/browser_bug553455.js
@@ -1,17 +1,27 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 const TESTROOT = "http://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/";
 const TESTROOT2 = "http://example.org/browser/toolkit/mozapps/extensions/test/xpinstall/";
-const CHROMEROOT = "chrome://mochikit/content/browser/toolkit/mozapps/extensions/test/xpinstall/";
 const XPINSTALL_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
 
+var rootDir = getRootDirectory(gTestPath);
+var path = rootDir.split('/');
+var chromeName = path[0] + '//' + path[2];
+var croot = chromeName + "/content/browser/toolkit/mozapps/extensions/test/xpinstall/";
+var jar = getJar(croot);
+if (jar) {
+  var tmpdir = extractJarToTmp(jar);
+  croot = 'file://' + tmpdir.path + '/';
+}
+const CHROMEROOT = croot;
+
 var gApp = document.getElementById("bundle_brand").getString("brandShortName");
 var gVersion = Services.appinfo.version;
 
 function wait_for_notification(aCallback) {
   PopupNotifications.panel.addEventListener("popupshown", function() {
     PopupNotifications.panel.removeEventListener("popupshown", arguments.callee, false);
     aCallback(PopupNotifications.panel);
   }, false);
@@ -308,18 +318,21 @@ function test_url() {
       });
     });
   });
 },
 
 function test_localfile() {
   var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
                      .getService(Components.interfaces.nsIChromeRegistry);
-  var path = cr.convertChromeURL(makeURI(CHROMEROOT + "corrupt.xpi")).spec;
-
+  try {
+    var path = cr.convertChromeURL(makeURI(CHROMEROOT + "corrupt.xpi")).spec;
+  } catch (ex) {
+    var path = CHROMEROOT + "corrupt.xpi";
+  }
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.loadURI(path);
 
   // Wait for the complete notification
   wait_for_notification(function(aPanel) {
     let notification = aPanel.childNodes[0];
     is(notification.id, "addon-install-failed-notification", "Should have seen the install fail");
     is(notification.getAttribute("label"),
--- a/browser/base/content/test/browser_discovery.js
+++ b/browser/base/content/test/browser_discovery.js
@@ -14,17 +14,18 @@ function test() {
   waitForExplicitFinish();
 
   gBrowser.selectedTab = gBrowser.addTab();
   browser = gBrowser.selectedBrowser;
   browser.addEventListener("load", function (event) {
     event.currentTarget.removeEventListener("load", arguments.callee, true);
     iconDiscovery();
   }, true);
-  content.location = "chrome://mochikit/content/browser/browser/base/content/test/discovery.html";
+  var rootDir = getRootDirectory(gTestPath);
+  content.location = rootDir + "discovery.html";
 }
 
 var iconDiscoveryTests = [
   { text: "rel icon discovered" },
   { rel: "abcdefg icon qwerty", text: "rel may contain additional rels separated by spaces" },
   { rel: "ICON", text: "rel is case insensitive" },
   { rel: "shortcut-icon", pass: false, text: "rel shortcut-icon not discovered" },
   { href: "moz.png", text: "relative href works" },
@@ -51,18 +52,19 @@ function iconDiscovery() {
   setHandlerFunc(runIconDiscoveryTest);
   if (iconDiscoveryTests.length) {
     gBrowser.setIcon(gBrowser.selectedTab, null);
 
     var test = iconDiscoveryTests[0];
     var head = doc().getElementById("linkparent");
     var link = doc().createElement("link");
 
+    var rootDir = getRootDirectory(gTestPath);
     var rel = test.rel || "icon";
-    var href = test.href || "chrome://mochikit/content/browser/browser/base/content/test/moz.png";
+    var href = test.href || rootDir + "/moz.png";
     var type = test.type || "image/png";
     if (test.pass == undefined)
       test.pass = true;
 
     link.rel = rel;
     link.href = href;
     link.type = type;
     head.appendChild(link);
--- a/browser/base/content/test/browser_page_style_menu.js
+++ b/browser/base/content/test/browser_page_style_menu.js
@@ -1,16 +1,16 @@
 function test() {
   waitForExplicitFinish();
 
   var tab = gBrowser.addTab();
   gBrowser.selectedTab = tab;
   tab.linkedBrowser.addEventListener("load", checkPageStyleMenu, true);
-  content.location =
-    "chrome://mochikit/content/browser/browser/base/content/test/page_style_sample.html";
+  let rootDir = getRootDirectory(gTestPath);
+  content.location = rootDir + "page_style_sample.html";
 }
 
 function checkPageStyleMenu() {
   var menupopup = document.getElementById("pageStyleMenu")
                           .getElementsByTagName("menupopup")[0];
   stylesheetFillPopup(menupopup);
 
   var items = [];
--- a/browser/base/content/test/browser_pluginnotification.js
+++ b/browser/base/content/test/browser_pluginnotification.js
@@ -1,9 +1,10 @@
-const gTestRoot = "chrome://mochikit/content/browser/browser/base/content/test/";
+var rootDir = getRootDirectory(gTestPath);
+const gTestRoot = rootDir;
 
 var gTestBrowser = null;
 var gNextTest = null;
 
 function get_test_plugin() {
   var ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
   var tags = ph.getPluginTags();
 
--- a/browser/base/content/test/file_bug550565_popup.html
+++ b/browser/base/content/test/file_bug550565_popup.html
@@ -1,12 +1,12 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test file for bug 550565.</title>
 
   <!--Set a favicon; that's the whole point of this file.-->
-  <link rel="icon" href="chrome://mochikit/content/browser/browser/base/content/test/file_bug550565_favicon.ico">
+  <link rel="icon" href="file_bug550565_favicon.ico">
 </head>
 <body>
   Test file for bug 550565.
 </body>
 </html>
--- a/browser/components/preferences/tests/browser_privacypane_1.js
+++ b/browser/components/preferences/tests/browser_privacypane_1.js
@@ -33,17 +33,24 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  * 
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                getService(Ci.mozIJSSubScriptLoader);
-  loader.loadSubScript("chrome://mochikit/content/browser/browser/components/preferences/tests/privacypane_tests.js", this);
+
+  let rootDir = getRootDirectory(gTestPath);
+  let jar = getJar(rootDir);
+  if (jar) {
+    let tmpdir = extractJarToTmp(jar);
+    rootDir = "file://" + tmpdir.path;
+  }
+  loader.loadSubScript(rootDir + "/privacypane_tests.js", this);
 
   run_test_subset([
     test_pane_visibility,
     test_dependent_elements,
     test_dependent_cookie_elements,
     test_dependent_clearonclose_elements,
     test_dependent_prefs,
 
--- a/browser/components/preferences/tests/browser_privacypane_2.js
+++ b/browser/components/preferences/tests/browser_privacypane_2.js
@@ -33,17 +33,24 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  * 
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                getService(Ci.mozIJSSubScriptLoader);
-  loader.loadSubScript("chrome://mochikit/content/browser/browser/components/preferences/tests/privacypane_tests.js", this);
+
+  let rootDir = getRootDirectory(gTestPath);
+  let jar = getJar(rootDir);
+  if (jar) {
+    let tmpdir = extractJarToTmp(jar);
+    rootDir = "file://" + tmpdir.path;
+  }
+  loader.loadSubScript(rootDir + "/privacypane_tests.js", this);
 
   run_test_subset([
     test_historymode_retention("remember", undefined),
     test_historymode_retention("dontremember", "remember"),
     test_historymode_retention("custom", "dontremember"),
     // custom without any micro-prefs changed won't retain
     test_historymode_retention("remember", "dontremember"),
     test_historymode_retention("custom", "remember"),
--- a/browser/components/preferences/tests/browser_privacypane_3.js
+++ b/browser/components/preferences/tests/browser_privacypane_3.js
@@ -33,17 +33,23 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  * 
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                getService(Ci.mozIJSSubScriptLoader);
-  loader.loadSubScript("chrome://mochikit/content/browser/browser/components/preferences/tests/privacypane_tests.js", this);
+  let rootDir = getRootDirectory(gTestPath);
+  let jar = getJar(rootDir);
+  if (jar) {
+    let tmpdir = extractJarToTmp(jar);
+    rootDir = "file://" + tmpdir.path;
+  }
+  loader.loadSubScript(rootDir + "/privacypane_tests.js", this);
 
   run_test_subset([
     test_custom_retention("rememberHistory", "remember"),
     test_custom_retention("rememberHistory", "custom"),
     test_custom_retention("rememberDownloads", "remember"),
     test_custom_retention("rememberDownloads", "custom"),
     test_custom_retention("rememberForms", "remember"),
     test_custom_retention("rememberForms", "custom"),
--- a/browser/components/preferences/tests/browser_privacypane_4.js
+++ b/browser/components/preferences/tests/browser_privacypane_4.js
@@ -33,17 +33,23 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  * 
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                getService(Ci.mozIJSSubScriptLoader);
-  loader.loadSubScript("chrome://mochikit/content/browser/browser/components/preferences/tests/privacypane_tests.js", this);
+  let rootDir = getRootDirectory(gTestPath);
+  let jar = getJar(rootDir);
+  if (jar) {
+    let tmpdir = extractJarToTmp(jar);
+    rootDir = "file://" + tmpdir.path;
+  }
+  loader.loadSubScript(rootDir + "/privacypane_tests.js", this);
 
   run_test_subset([
     test_custom_retention("acceptCookies", "remember"),
     test_custom_retention("acceptCookies", "custom"),
     test_custom_retention("acceptThirdParty", "remember"),
     test_custom_retention("acceptThirdParty", "custom"),
     test_custom_retention("keepCookiesUntil", "remember", 1),
     test_custom_retention("keepCookiesUntil", "custom", 2),
--- a/browser/components/preferences/tests/browser_privacypane_5.js
+++ b/browser/components/preferences/tests/browser_privacypane_5.js
@@ -33,17 +33,23 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  * 
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                getService(Ci.mozIJSSubScriptLoader);
-  loader.loadSubScript("chrome://mochikit/content/browser/browser/components/preferences/tests/privacypane_tests.js", this);
+  let rootDir = getRootDirectory(gTestPath);
+  let jar = getJar(rootDir);
+  if (jar) {
+    let tmpdir = extractJarToTmp(jar);
+    rootDir = "file://" + tmpdir.path;
+  }
+  loader.loadSubScript(rootDir + "/privacypane_tests.js", this);
 
   run_test_subset([
     test_locbar_suggestion_retention(-1, undefined),
     test_locbar_suggestion_retention(1, -1),
     test_locbar_suggestion_retention(2, 1),
     test_locbar_suggestion_retention(0, 2),
     test_locbar_suggestion_retention(0, 0),
 
--- a/browser/components/preferences/tests/browser_privacypane_6.js
+++ b/browser/components/preferences/tests/browser_privacypane_6.js
@@ -33,17 +33,23 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  * 
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                getService(Ci.mozIJSSubScriptLoader);
-  loader.loadSubScript("chrome://mochikit/content/browser/browser/components/preferences/tests/privacypane_tests.js", this);
+  let rootDir = getRootDirectory(gTestPath);
+  let jar = getJar(rootDir);
+  if (jar) {
+    let tmpdir = extractJarToTmp(jar);
+    rootDir = "file://" + tmpdir.path;
+  }
+  loader.loadSubScript(rootDir + "/privacypane_tests.js", this);
 
   run_test_subset([
     test_privatebrowsing_toggle,
     enter_private_browsing, // once again, test with PB initially enabled
     test_privatebrowsing_toggle,
 
     // don't reset preferences, will pick up where we left off in browser_privacypane_7.js
   ]);
--- a/browser/components/preferences/tests/browser_privacypane_7.js
+++ b/browser/components/preferences/tests/browser_privacypane_7.js
@@ -33,17 +33,23 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  * 
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                getService(Ci.mozIJSSubScriptLoader);
-  loader.loadSubScript("chrome://mochikit/content/browser/browser/components/preferences/tests/privacypane_tests.js", this);
+  let rootDir = getRootDirectory(gTestPath);
+  let jar = getJar(rootDir);
+  if (jar) {
+    let tmpdir = extractJarToTmp(jar);
+    rootDir = "file://" + tmpdir.path;
+  }
+  loader.loadSubScript(rootDir + "/privacypane_tests.js", this);
 
   run_test_subset([
     test_privatebrowsing_ui,
     enter_private_browsing, // once again, test with PB initially enabled
     test_privatebrowsing_ui,
 
     // reset all preferences to their default values once we're done
     reset_preferences
--- a/browser/components/preferences/tests/browser_privacypane_8.js
+++ b/browser/components/preferences/tests/browser_privacypane_8.js
@@ -32,17 +32,23 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  * 
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                getService(Ci.mozIJSSubScriptLoader);
-  loader.loadSubScript("chrome://mochikit/content/browser/browser/components/preferences/tests/privacypane_tests.js", this);
+  let rootDir = getRootDirectory(gTestPath);
+  let jar = getJar(rootDir);
+  if (jar) {
+    let tmpdir = extractJarToTmp(jar);
+    rootDir = "file://" + tmpdir.path;
+  }
+  loader.loadSubScript(rootDir + "/privacypane_tests.js", this);
 
   run_test_subset([
     // history mode should be initialized to remember
     test_historymode_retention("remember", undefined),
 
     // history mode should remain remember; toggle acceptCookies checkbox
     test_custom_retention("acceptCookies", "remember"),
 
--- a/browser/components/sessionstore/test/browser/browser_248970_b.js
+++ b/browser/components/sessionstore/test/browser/browser_248970_b.js
@@ -112,18 +112,18 @@ function test() {
   // sessionstore service
   let ss = test(function() Cc["@mozilla.org/browser/sessionstore;1"].
                            getService(Ci.nsISessionStore));
 
   //////////////////////////////////////////////////////////////////
   // Test (B) : Session data restoration between modes            //
   //////////////////////////////////////////////////////////////////
 
-  const testURL = "chrome://mochikit/content/browser/" +
-  "browser/components/sessionstore/test/browser/browser_248970_b_sample.html";
+  let rootDir = getRootDirectory(gTestPath);
+  const testURL = rootDir + "browser_248970_b_sample.html";
   const testURL2 = "http://mochi.test:8888/browser/" +
   "browser/components/sessionstore/test/browser/browser_248970_b_sample.html";
 
   // get closed tab count
   let count = ss.getClosedTabCount(window);
   let max_tabs_undo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo");
   ok(0 <= count && count <= max_tabs_undo,
     "getClosedTabCount should return zero or at most max_tabs_undo");
--- a/browser/components/sessionstore/test/browser/browser_346337.js
+++ b/browser/components/sessionstore/test/browser/browser_346337.js
@@ -112,18 +112,18 @@ function test() {
   
   // test setup
   let tabbrowser = gBrowser;
   waitForExplicitFinish();
   
   // make sure we don't save form data at all (except for tab duplication)
   gPrefService.setIntPref("browser.sessionstore.privacy_level", 2);
   
-  let testURL = "chrome://mochikit/content/browser/" +
-    "browser/components/sessionstore/test/browser/browser_346337_sample.html";
+  let rootDir = getRootDirectory(gTestPath);
+  let testURL = rootDir + "browser_346337_sample.html";
   let tab = tabbrowser.addTab(testURL);
   tab.linkedBrowser.addEventListener("load", function(aEvent) {
     this.removeEventListener("load", arguments.callee, true);
     for (let xpath in fieldList)
       setFormValue(tab, xpath, fieldList[xpath]);
     
     let tab2 = tabbrowser.duplicateTab(tab);
     tab2.linkedBrowser.addEventListener("load", function(aEvent) {
--- a/browser/components/sessionstore/test/browser/browser_408470.js
+++ b/browser/components/sessionstore/test/browser/browser_408470.js
@@ -35,18 +35,18 @@
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   /** Test for Bug 408470 **/
   
   waitForExplicitFinish();
   
   let pendingCount = 1;
-  let testUrl = "chrome://mochikit/content/browser/" +
-    "browser/components/sessionstore/test/browser/browser_408470_sample.html";
+  let rootDir = getRootDirectory(gTestPath);
+  let testUrl = rootDir + "browser_408470_sample.html";
   let tab = gBrowser.addTab(testUrl);
   
   tab.linkedBrowser.addEventListener("load", function(aEvent) {
     tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
     // enable all stylesheets and verify that they're correctly persisted
     Array.forEach(tab.linkedBrowser.contentDocument.styleSheets, function(aSS, aIx) {
       pendingCount++;
       let ssTitle = aSS.title;
--- a/browser/components/sessionstore/test/browser/browser_454908.js
+++ b/browser/components/sessionstore/test/browser/browser_454908.js
@@ -42,18 +42,18 @@ function test() {
   let fieldValues = {
     username: "User " + Math.random(),
     passwd:   "pwd" + Date.now()
   };
   
   // make sure we do save form data
   gPrefService.setIntPref("browser.sessionstore.privacy_level", 0);
   
-  let testURL = "chrome://mochikit/content/browser/" +
-    "browser/components/sessionstore/test/browser/browser_454908_sample.html";
+  let rootDir = getRootDirectory(gTestPath);
+  let testURL = rootDir + "browser_454908_sample.html";
   let tab = gBrowser.addTab(testURL);
   tab.linkedBrowser.addEventListener("load", function(aEvent) {
     tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
     let doc = tab.linkedBrowser.contentDocument;
     for (let id in fieldValues)
       doc.getElementById(id).value = fieldValues[id];
     
     gBrowser.removeTab(tab);
--- a/browser/components/sessionstore/test/browser/browser_456342.js
+++ b/browser/components/sessionstore/test/browser/browser_456342.js
@@ -37,18 +37,18 @@
 function test() {
   /** Test for Bug 456342 **/
   
   waitForExplicitFinish();
   
   // make sure we do save form data
   gPrefService.setIntPref("browser.sessionstore.privacy_level", 0);
   
-  let testURL = "chrome://mochikit/content/browser/" +
-    "browser/components/sessionstore/test/browser/browser_456342_sample.xhtml";
+  let rootDir = getRootDirectory(gTestPath);
+  let testURL = rootDir + "browser_456342_sample.xhtml";
   let tab = gBrowser.addTab(testURL);
   tab.linkedBrowser.addEventListener("load", function(aEvent) {
     this.removeEventListener("load", arguments.callee, true);
 
     let expectedValue = "try to save me";
     // Since bug 537289 we only save non-default values, so we need to set each
     // form field's value after load.
     let formEls = aEvent.originalTarget.forms[0].elements;
--- a/browser/components/sessionstore/test/browser/browser_459906_sample.html
+++ b/browser/components/sessionstore/test/browser/browser_459906_sample.html
@@ -17,18 +17,17 @@
     frames[0].removeEventListener("DOMContentLoaded", handleLoad, false);
     frames[1].removeEventListener("DOMContentLoaded", handleLoad, false);
     frames[0].document.designMode = "on";
     frames[0].document.__defineGetter__("designMode", function() {
       // inject a cross domain file ...
       var documentInjected = false;
       document.getElementsByTagName("iframe")[0].onload =
         function() { documentInjected = true; };
-      frames[0].location = "chrome://mochikit/content/browser/" +
-        "browser/components/sessionstore/test/browser/browser_459906_empty.html";
+      frames[0].location = "browser_459906_empty.html";
       
       // ... and ensure that it has time to load
       for (var c = 0; !documentInjected && c < 20; c++) {
         var r = new XMLHttpRequest();
         r.open("GET", location.href, false);
         r.overrideMimeType("text/plain");
         r.send(null);
       }
--- a/browser/components/sessionstore/test/browser/browser_463205.js
+++ b/browser/components/sessionstore/test/browser/browser_463205.js
@@ -34,25 +34,24 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   /** Test for Bug 463205 **/
   
   waitForExplicitFinish();
   
-  let testURL = "chrome://mochikit/content/browser/" +
-    "browser/components/sessionstore/test/browser/browser_463205_sample.html";
+  let rootDir = getRootDirectory(gTestPath);
+  let testURL = rootDir + "browser_463205_sample.html";
 
   let doneURL = "done";
 
   let mainURL = testURL;
   let frame1URL = "data:text/html,<input%20id='original'>";
-  let frame2URL = "chrome://mochikit/content/browser/" +
-    "browser/components/sessionstore/test/browser/browser_463205_helper.html";
+  let frame2URL = rootDir + "browser_463205_helper.html";
   let frame3URL = "data:text/html,mark2";
 
   let frameCount = 0;
   
   let tab = gBrowser.addTab(testURL);
   tab.linkedBrowser.addEventListener("load", function(aEvent) {
     // wait for all frames to load completely
     if (frame1URL != doneURL && aEvent.target.location.href == frame1URL) {
@@ -95,18 +94,17 @@ function test() {
     let uniqueValue = "Unique: " + Math.random();
     let win = tab.linkedBrowser.contentWindow;
     typeText(win.frames[0].document.getElementById("original"), uniqueValue);
     typeText(win.frames[1].document.getElementById("original"), uniqueValue);
 
     mainURL = testURL;
     frame1URL = "http://mochi.test:8888/browser/" +
       "browser/components/sessionstore/test/browser/browser_463205_helper.html";
-    frame2URL = "chrome://mochikit/content/browser/" +
-      "browser/components/sessionstore/test/browser/browser_463205_helper.html";
+    frame2URL = rootDir + "browser_463205_helper.html";
     frame3URL = "data:text/html,mark2";
 
     frameCount = 0;
 
     let tab2 = gBrowser.duplicateTab(tab);
     tab2.linkedBrowser.addEventListener("load", function(aEvent) {
       // wait for all frames to load (and reload!) completely
       if (frame1URL != doneURL && aEvent.target.location.href == frame1URL) {
--- a/browser/components/sessionstore/test/browser/browser_485482.js
+++ b/browser/components/sessionstore/test/browser/browser_485482.js
@@ -36,18 +36,18 @@
 
 function test() {
   /** Test for Bug 485482 **/
   
   waitForExplicitFinish();
   
   let uniqueValue = Math.random();
   
-  let testURL = "chrome://mochikit/content/browser/" +
-    "browser/components/sessionstore/test/browser/browser_485482_sample.html";
+  let rootDir = getRootDirectory(gTestPath);
+  let testURL = rootDir + "browser_485482_sample.html";
   let tab = gBrowser.addTab(testURL);
   tab.linkedBrowser.addEventListener("load", function(aEvent) {
     tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
     let doc = tab.linkedBrowser.contentDocument;
     doc.querySelector("input[type=text]").value = uniqueValue;
     doc.querySelector("input[type=checkbox]").checked = true;
     
     let tab2 = gBrowser.duplicateTab(tab);
--- a/browser/fuel/test/browser_Browser.js
+++ b/browser/fuel/test/browser_Browser.js
@@ -4,55 +4,58 @@ var gPageB = null;
 // cached data from events
 var gTabOpenPageA = null;
 var gTabOpenPageB = null;
 var gTabOpenCount = 0;
 var gTabCloseCount = 0;
 var gTabMoveCount = 0;
 var gPageLoadCount = 0;
 
+var rootDir = getRootDirectory(gTestPath);
+const CHROMEROOT = rootDir;
+
 function test() {
   waitForExplicitFinish();
 
   var windows = Application.windows;
   ok(windows, "Check access to browser windows");
   is(windows.length, 1, "There should be one browser window open");
 
   var activeWin = Application.activeWindow;
   activeWin.events.addListener("TabOpen", onTabOpen);
   activeWin.events.addListener("TabClose", onTabClose);
   activeWin.events.addListener("TabMove", onTabMove);
 
-  gPageA = activeWin.open(makeURI("chrome://mochikit/content/browser/browser/fuel/test/ContentA.html"));
+  gPageA = activeWin.open(makeURI(CHROMEROOT + "ContentA.html"));
   gPageA.events.addListener("load", onPageAFirstLoad);
 
   is(activeWin.tabs.length, 2, "Checking length of 'Browser.tabs' after opening 1 additional tab");
 
   function onPageAFirstLoad(event) {
     gPageA.events.removeListener("load", onPageAFirstLoad);
     is(gPageA.uri.spec, event.data.uri.spec, "Checking event browser tab is equal to page A");
 
-    gPageB = activeWin.open(makeURI("chrome://mochikit/content/browser/browser/fuel/test/ContentB.html"));
+    gPageB = activeWin.open(makeURI(CHROMEROOT + "ContentB.html"));
     gPageB.events.addListener("load", delayAfterOpen);
     gPageB.focus();
 
     is(activeWin.tabs.length, 3, "Checking length of 'Browser.tabs' after opening a second additional tab");
     is(activeWin.activeTab.index, gPageB.index, "Checking 'Browser.activeTab' after setting focus");
   }
 
   function delayAfterOpen() {
     executeSoon(afterOpen);
   }
 
   // need to wait for the url's to be refreshed during the load
   function afterOpen(event) {
     gPageB.events.removeListener("load", delayAfterOpen);
     // check actuals
-    is(gPageA.uri.spec, "chrome://mochikit/content/browser/browser/fuel/test/ContentA.html", "Checking 'BrowserTab.uri' after opening");
-    is(gPageB.uri.spec, "chrome://mochikit/content/browser/browser/fuel/test/ContentB.html", "Checking 'BrowserTab.uri' after opening");
+    is(gPageA.uri.spec, CHROMEROOT + "ContentA.html", "Checking 'BrowserTab.uri' after opening");
+    is(gPageB.uri.spec, CHROMEROOT + "ContentB.html", "Checking 'BrowserTab.uri' after opening");
 
     // check event
     is(gTabOpenCount, 2, "Checking event handler for tab open");
     // check cached values from TabOpen event
     is(gPageA.uri.spec, gTabOpenPageA.uri.spec, "Checking first browser tab open is equal to page A");
     is(gPageB.uri.spec, gTabOpenPageB.uri.spec, "Checking second browser tab open is equal to page B");
 
     // test document access
@@ -86,38 +89,38 @@ function test() {
       onProgressChange: function () 0,
       onStatusChange: function () 0,
       onSecurityChange: function () 0
     });
 
     // test loading new content with a frame into a tab
     // the event will be checked in onPageBLoadComplete
     gPageB.events.addListener("load", onPageBLoadWithFrames);
-    gPageB.load(makeURI("chrome://mochikit/content/browser/browser/fuel/test/ContentWithFrames.html"));
+    gPageB.load(makeURI(CHROMEROOT + "ContentWithFrames.html"));
   }
 
   function onPageBLoadWithFrames(event) {
     gPageLoadCount++;
     info("onPageBLoadWithFrames: " + gPageLoadCount);
   }
 
   function onPageBLoadComplete() {
     gPageB.events.removeListener("load", onPageBLoadWithFrames);
     // check page load with frame event
     is(gPageLoadCount, 1, "Checking load count after loading new content with a frame");
 
     // test loading new content into a tab
     // the event will be checked in onPageASecondLoad
     gPageA.events.addListener("load", onPageASecondLoad);
-    gPageA.load(makeURI("chrome://mochikit/content/browser/browser/fuel/test/ContentB.html"));
+    gPageA.load(makeURI(CHROMEROOT + "ContentB.html"));
   }
 
   function onPageASecondLoad(event) {
     gPageA.events.removeListener("load", onPageASecondLoad);
-    is(gPageA.uri.spec, "chrome://mochikit/content/browser/browser/fuel/test/ContentB.html", "Checking 'BrowserTab.uri' after loading new content");
+    is(gPageA.uri.spec, CHROMEROOT + "ContentB.html", "Checking 'BrowserTab.uri' after loading new content");
 
     // start testing closing tabs
     // the event will be checked in afterClose
     // use executeSoon so the onPageASecondLoad
     // has a chance to finish first
     gPageA.close();
     gPageB.close();
 
--- a/docshell/test/browser/browser_bug134911.js
+++ b/docshell/test/browser/browser_bug134911.js
@@ -4,17 +4,19 @@ const rightText="\u30E6\u30CB\u30B3\u30F
 const enteredText1="The quick brown fox jumps over the lazy dog";
 const enteredText2="\u03BE\u03B5\u03C3\u03BA\u03B5\u03C0\u03AC\u03B6\u03C9\u0020\u03C4\u1F74\u03BD\u0020\u03C8\u03C5\u03C7\u03BF\u03C6\u03B8\u03CC\u03C1\u03B1\u0020\u03B2\u03B4\u03B5\u03BB\u03C5\u03B3\u03BC\u03AF\u03B1";
 
 var testPage;
 
 function test() {
   testPage = Application.activeWindow.open(url("about:blank"));
   testPage.events.addListener("load", afterOpen);
-  testPage.load(url("chrome://mochikit/content/browser/docshell/test/browser/test-form_sjis.html"));
+  
+  var rootDir = getRootDirectory(gTestPath);
+  testPage.load(url(rootDir + "test-form_sjis.html"));
   testPage.focus();
 
   waitForExplicitFinish();
 }
 
 function afterOpen() {
     testPage.events.removeListener("load", afterOpen);
     testPage.events.addListener("load", afterChangeCharset);
--- a/docshell/test/browser/browser_bug92473.js
+++ b/docshell/test/browser/browser_bug92473.js
@@ -37,13 +37,15 @@ function afterChangeCharset() {
     testPage.close();
     finish();
 }
 
 function test() {
   var activeWin = Application.activeWindow;
   testPage = activeWin.open(url("about:blank"));
   testPage.events.addListener("load", afterOpen);
-  testPage.load(url("chrome://mochikit/content/browser/docshell/test/browser/test-form_sjis.html"));
+  
+  var rootDir = getRootDirectory(gTestPath);
+  testPage.load(url(rootDir + "test-form_sjis.html"));
   testPage.focus();
 
   waitForExplicitFinish();
 }
--- a/layout/style/test/browser_bug453896.js
+++ b/layout/style/test/browser_bug453896.js
@@ -9,17 +9,19 @@ var theTab;
 var theBrowser;
 
 function test() {
   waitForExplicitFinish();
 
   theTab = gBrowser.addTab();
   theBrowser = gBrowser.getBrowserForTab(theTab);
   theBrowser.addEventListener("load", listener, true);
-  theBrowser.contentWindow.location = "chrome://mochikit/content/browser/layout/style/test/bug453896_iframe.html";
+  
+  var rootDir = getRootDirectory(gTestPath);
+  theBrowser.contentWindow.location = rootDir + "bug453896_iframe.html";
 }
 
 function doTest() {
   theBrowser.removeEventListener("load", listener, true);
   var fake_window = { ok: ok, SimpleTest: { finish: finish } };
   theBrowser.contentWindow.wrappedJSObject.run(fake_window);
   gBrowser.removeTab(theTab);
 }
--- a/testing/mochitest/browser-harness.xul
+++ b/testing/mochitest/browser-harness.xul
@@ -41,16 +41,17 @@
 
 <window id="browserTestHarness"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         onload="TestStart();"
         title="Browser chrome tests"
         width="1024">
   <script src="chrome://mochikit/content/tests/SimpleTest/MozillaFileLogger.js"/>
   <script src="chrome://mochikit/content/tests/SimpleTest/quit.js"/>
+  <script src="chrome://mochikit/content/chrome-harness.js"/>
   <style xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
     #results {
       margin: 5px;
       background-color: window;
       -moz-user-select: text;
     }
 
     #summary {
@@ -83,16 +84,21 @@
       margin-top: 1em;
     }
 
     p {
       margin: 0.1em;
     }
   ]]></style>
   <script type="application/javascript;version=1.7"><![CDATA[
+    if (Cc === undefined) {
+      var Cc = Components.classes;
+      var Ci = Components.interfaces;
+    }
+    
     var gConfig;
 
     var gDumper = {
       get fileLogger() {
         let logger = null;
         if (gConfig.logPath) {
           try {
             MozillaFileLogger.init(gConfig.logPath);
@@ -157,34 +163,16 @@
       }
 
       sstream.close();
       fileInStream.close();
 
       return eval(config);
     }
 
-    function getChromeDir() {
-      const Cc = Components.classes; const Ci = Components.interfaces;
-
-      /** Find our chrome dir **/
-      var ios = Cc["@mozilla.org/network/io-service;1"].
-                  getService(Ci.nsIIOService);
-      var chromeURI = ios.newURI("chrome://mochikit/content/",
-                                 null, null);
-      var resolvedURI = Cc["@mozilla.org/chrome/chrome-registry;1"].
-                        getService(Ci.nsIChromeRegistry).
-                        convertChromeURL(chromeURI);
-      var fileHandler = Cc["@mozilla.org/network/protocol;1?name=file"].
-                        getService(Ci.nsIFileProtocolHandler);
-      var chromeDir = fileHandler.getFileFromURLSpec(resolvedURI.spec);
-
-      return chromeDir.parent.QueryInterface(Ci.nsILocalFile);
-    }
-
     function browserTest(aTestFile) {
       this.path = aTestFile;
       this.dumper = gDumper;
       this.results = [];
       this.scope = null;
     }
     browserTest.prototype = {
       get passCount() {
@@ -215,74 +203,43 @@
           return "<p class=\"" + class + "\">" + t.result + " | " + path +
                  " | " + _entityEncode(t.msg) + "</p>";
         }).join("\n");
       }
     };
 
     // Returns an array of browserTest objects for all the selected tests
     function listTests() {
-      const Cc = Components.classes; const Ci = Components.interfaces;
-
-      var ioSvc = Cc["@mozilla.org/network/io-service;1"].
-                  getService(Ci.nsIIOService);
-
-      var testsDir = getChromeDir();
-      testsDir.appendRelativePath("browser");
-
-      var requestPath = "chrome://mochikit/content/browser";
-      var fileNameRegexp = /browser_.+\.js$/;
-
-      if (gConfig.testPath) {
-        var testsDirURI = ioSvc.newFileURI(testsDir);
-        testsDir = ioSvc.newURI(gConfig.testPath, null, testsDirURI)
-                        .QueryInterface(Ci.nsIFileURL).file;
-
-        // Invalid testPath...
-        if (!testsDir.exists())
-          return [];
-
-        // If we were passed a specific file, run only that test.
-        if (testsDir.isFile()) {
-          if (fileNameRegexp.test(testsDir.leafName))
-            return [new browserTest(requestPath + "/" + gConfig.testPath)];
-
-          // We were passed a file that's not a test...
-          return [];
-        }
-
-        // otherwise, we were passed a directory of tests
-        requestPath += "/" + gConfig.testPath;
-      }
 
       // load server.js in so we can share template functions
       var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                          getService(Ci.mozIJSSubScriptLoader);
       var srvScope = {};
-      scriptLoader.loadSubScript("chrome://mochikit/content/server.js", srvScope);
+      var baseURL = 'chrome://mochikit/content';
+      scriptLoader.loadSubScript('chrome://mochikit/content/server.js', srvScope);
 
-      var [links, ] = srvScope.list(requestPath, testsDir, true);
+      var [links, singleTestPath] = getFileListing(baseURL, gConfig.testPath, "browser", srvScope);
+
       var fileNames = [];
+      var fileNameRegexp = /browser_.+\.js$/;
       srvScope.arrayOfTestFiles(links, fileNames, fileNameRegexp);
-
       return fileNames.map(function (f) new browserTest(f));
     }
 
     function setStatus(aStatusString) {
       document.getElementById("status").value = aStatusString;
     }
 
     function runTests() {
       var windowMediator = Cc['@mozilla.org/appshell/window-mediator;1'].
                              getService(Ci.nsIWindowMediator);
       var testWin = windowMediator.getMostRecentWindow("navigator:browser");
 
       setStatus("Running...");
       testWin.focus();
-
       var Tester = new testWin.Tester(listTests(), gDumper, testsFinished);
       Tester.start();
     }
 
     function sum(a, b) {
       return a + b;
     }
 
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -18,16 +18,17 @@ function testOnLoad() {
 
   prefs.setBoolPref("testing.browserTestHarness.running", true);
 
   var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
            getService(Ci.nsIWindowWatcher);
   var sstring = Cc["@mozilla.org/supports-string;1"].
                 createInstance(Ci.nsISupportsString);
   sstring.data = location.search;
+
   ww.openWindow(window, "chrome://mochikit/content/browser-harness.xul", "browserTest",
                 "chrome,centerscreen,dialog,resizable,titlebar,toolbar=no,width=800,height=600", sstring);
 }
 
 function Tester(aTests, aDumper, aCallback) {
   this.dumper = aDumper;
   this.tests = aTests;
   this.callback = aCallback;
@@ -189,21 +190,28 @@ Tester.prototype = {
     this.dumper.dump("TEST-START | " + this.currentTest.path + "\n");
 
     // Load the tests into a testscope
     this.currentTest.scope = new testScope(this, this.currentTest);
 
     // Import utils in the test scope.
     this.currentTest.scope.EventUtils = this.EventUtils;
     this.currentTest.scope.SimpleTest = this.SimpleTest;
+    this.currentTest.scope.gTestPath = this.currentTest.path;
+
     // Override SimpleTest methods with ours.
     ["ok", "is", "isnot", "todo", "todo_is", "todo_isnot"].forEach(function(m) {
       this.SimpleTest[m] = this[m];
     }, this.currentTest.scope);
 
+    //load the tools to work with chrome .jar and remote
+    try {
+      this._scriptLoader.loadSubScript("chrome://mochikit/content/chrome-harness.js", this.currentTest.scope);
+    } catch (ex) { /* no chrome-harness tools */ }
+
     // Import head.js script if it exists.
     var currentTestDirPath =
       this.currentTest.path.substr(0, this.currentTest.path.lastIndexOf("/"));
     var headPath = currentTestDirPath + "/head.js";
     try {
       this._scriptLoader.loadSubScript(headPath, this.currentTest.scope);
     } catch (ex) { /* no head */ }
 
@@ -341,16 +349,20 @@ function testScope(aTester, aTest) {
   this.registerCleanupFunction = function test_registerCleanupFunction(aFunction) {
     self.__cleanupFunctions.push(aFunction);
   };
 
   this.requestLongerTimeout = function test_requestLongerTimeout(aFactor) {
     self.__timeoutFactor = aFactor;
   };
 
+  this.copyToProfile = function test_copyToProfile(filename) {
+    self.SimpleTest.copyToProfile(filename);
+  };
+
   this.finish = function test_finish() {
     self.__done = true;
     if (self.__waitTimer) {
       self.executeSoon(function() {
         if (self.__done && self.__waitTimer) {
           clearTimeout(self.__waitTimer);
           self.__waitTimer = null;
           self.__tester.nextTest();
--- a/toolkit/content/tests/browser/browser_save_resend_postdata.js
+++ b/toolkit/content/tests/browser/browser_save_resend_postdata.js
@@ -44,19 +44,20 @@
  * page is no longer in the cache.
  */
 function test() {
 
   // --- Testing support library ---
 
   // Import the toolkit test support library in the scope of the current test.
   // This operation also defines the common constants Cc, Ci, Cu, Cr and Cm.
+  var rootDir = getRootDirectory(gTestPath);
   Components.classes["@mozilla.org/moz/jssubscript-loader;1"].
    getService(Components.interfaces.mozIJSSubScriptLoader).loadSubScript(
-   "chrome://mochikit/content/browser/toolkit/content/tests/browser/common/_loadAll.js",
+   rootDir + "common/_loadAll.js",
    this);
 
   // --- Test implementation ---
 
   const kBaseUrl =
         "http://mochi.test:8888/browser/toolkit/content/tests/browser/data/";
 
   function pageShown(event)
--- a/toolkit/content/tests/browser/common/_loadAll.js
+++ b/toolkit/content/tests/browser/common/_loadAll.js
@@ -42,18 +42,18 @@
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 const Cr = Components.results;
 const Cm = Components.manager;
 
 // Execute the following code while keeping the current scope clean.
 void(function (scriptScope) {
-  const kBaseUrl =
-    "chrome://mochikit/content/browser/toolkit/content/tests/browser/common/";
+  var rootDir = getRootDirectory(gTestPath);
+  const kBaseUrl = rootDir + "common/";
 
   // If you add files here, add them to "Makefile.in" too.
   var scriptNames = [
     "mockObjects.js",
     "testRunner.js",
 
     // To be included after the files above.
     "mockFilePicker.js",
@@ -64,9 +64,9 @@ void(function (scriptScope) {
   // Include all the required scripts.
   var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                      getService(Ci.mozIJSSubScriptLoader);
   for (let [, scriptName] in Iterator(scriptNames)) {
     // Ensure that the subscript is loaded in the scope where this script is
     // being executed, which is not necessarily the global scope.
     scriptLoader.loadSubScript(kBaseUrl + scriptName, scriptScope);
   }
-}(this));
\ No newline at end of file
+}(this));
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -5,22 +5,29 @@
 Components.utils.import("resource://gre/modules/AddonManager.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/NetUtil.jsm");
 
 const RELATIVE_DIR = "browser/toolkit/mozapps/extensions/test/browser/";
 
 const TESTROOT = "http://example.com/" + RELATIVE_DIR;
 const TESTROOT2 = "http://example.org/" + RELATIVE_DIR;
-const CHROMEROOT = "chrome://mochikit/content/" + RELATIVE_DIR;
 
 const MANAGER_URI = "about:addons";
 const INSTALL_URI = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
 const PREF_LOGGING_ENABLED = "extensions.logging.enabled";
 const PREF_SEARCH_MAXRESULTS = "extensions.getAddons.maxResults";
+const CHROME_NAME = "mochikit";
+
+function getChromeRoot(path) {
+  if (path === undefined) {
+    return "chrome://" + CHROME_NAME + "/content/" + RELATIVE_DIR;
+  }
+  return getRootDirectory(path);
+}
 
 var gPendingTests = [];
 var gTestsRun = 0;
 
 var gUseInContentUI = ("switchToTabHavingURI" in window);
 
 // Turn logging on for all tests
 Services.prefs.setBoolPref(PREF_LOGGING_ENABLED, true);
@@ -47,33 +54,29 @@ function run_next_test() {
 
   gTestsRun++;
   info("Running test " + gTestsRun);
 
   gPendingTests.shift()();
 }
 
 function get_addon_file_url(aFilename) {
-  var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
-                         .getService(Ci.mozIJSSubScriptLoader);
-  loader.loadSubScript("chrome://mochikit/content/chrome-harness.js");
-
-  var jar = getJar(CHROMEROOT + "addons/" + aFilename);
-
-  if (jar == null) {
+  var chromeroot = getChromeRoot(gTestPath);
+  try {
     var cr = Cc["@mozilla.org/chrome/chrome-registry;1"].
              getService(Ci.nsIChromeRegistry);
-    var fileurl = cr.convertChromeURL(makeURI(CHROMEROOT + "addons/" + aFilename));
+    var fileurl = cr.convertChromeURL(makeURI(chromeroot + "addons/" + aFilename));
     return fileurl.QueryInterface(Ci.nsIFileURL);
-  } else {
-    var ios = Cc["@mozilla.org/network/io-service;1"].  
-                getService(Ci.nsIIOService);
-
+  } catch(ex) {
+    var jar = getJar(chromeroot + "addons/" + aFilename);
     var tmpDir = extractJarToTmp(jar);
     tmpDir.append(aFilename);
+
+    var ios = Components.classes["@mozilla.org/network/io-service;1"].
+                getService(Components.interfaces.nsIIOService);
     return ios.newFileURI(tmpDir).QueryInterface(Ci.nsIFileURL);
   }
 }
 
 function check_all_in_list(aManager, aIds, aIgnoreExtras) {
   var doc = aManager.document;
   var view = doc.getElementById("view-port").selectedPanel;
   var listid = view.id == "search-view" ? "search-list" : "addon-list";
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_localfile.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_localfile.js
@@ -2,20 +2,25 @@
 // Tests installing an local file works when loading the url
 function test() {
   Harness.installEndedCallback = install_ended;
   Harness.installsCompletedCallback = finish_test;
   Harness.setup();
 
   var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
                      .getService(Components.interfaces.nsIChromeRegistry);
-  var path = cr.convertChromeURL(makeURI(CHROMEROOT + "unsigned.xpi")).spec;
 
+  var chromeroot = extractChromeRoot(gTestPath);
+  try {
+    var xpipath = cr.convertChromeURL(makeURI(chromeroot + "unsigned.xpi")).spec;
+  } catch (ex) {
+    var xpipath = chromeroot + "unsigned.xpi"; //scenario where we are running from a .jar and already extracted
+  }
   gBrowser.selectedTab = gBrowser.addTab();
-  gBrowser.loadURI(path);
+  gBrowser.loadURI(xpipath);
 }
 
 function install_ended(install, addon) {
   install.cancel();
 }
 
 function finish_test(count) {
   is(count, 1, "1 Add-on should have been successfully installed");
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_localfile2.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_localfile2.js
@@ -1,20 +1,26 @@
 // ----------------------------------------------------------------------------
 // Test whether an install fails if the url is a local file when requested from
 // web content
 function test() {
   waitForExplicitFinish();
 
   var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
                      .getService(Components.interfaces.nsIChromeRegistry);
-  var path = cr.convertChromeURL(makeURI(CHROMEROOT + "unsigned.xpi")).spec;
-
+  
+  var chromeroot = getChromeRoot(gTestPath);              
+  try {
+    var xpipath = cr.convertChromeURL(makeURI(chromeroot + "unsigned.xpi")).spec;
+  } catch (ex) {
+    var xpipath = chromeroot + "unsigned.xpi"; //scenario where we are running from a .jar and already extracted
+  }
+  
   var triggers = encodeURIComponent(JSON.stringify({
-    "Unsigned XPI": path
+    "Unsigned XPI": xpipath
   }));
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.selectedBrowser.addEventListener("load", function() {
     gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
     // Allow the in-page load handler to run first
     executeSoon(page_loaded);
   }, true);
   gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
--- a/toolkit/mozapps/extensions/test/xpinstall/head.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/head.js
@@ -1,18 +1,35 @@
 const RELATIVE_DIR = "toolkit/mozapps/extensions/test/xpinstall/";
 
 const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
 const TESTROOT2 = "http://example.org/browser/" + RELATIVE_DIR;
-const CHROMEROOT = "chrome://mochikit/content/browser/" + RELATIVE_DIR;
 const XPINSTALL_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
 const PROMPT_URL = "chrome://global/content/commonDialog.xul";
 const ADDONS_URL = "chrome://mozapps/content/extensions/extensions.xul";
 const PREF_LOGGING_ENABLED = "extensions.logging.enabled";
 const PREF_INSTALL_REQUIREBUILTINCERTS = "extensions.install.requireBuiltInCerts";
+const CHROME_NAME = "mochikit";
+
+function getChromeRoot(path) {
+  if (path === undefined) {
+    return "chrome://" + CHROME_NAME + "/content/browser/" + RELATIVE_DIR
+  }
+  return getRootDirectory(path);
+}
+
+function extractChromeRoot(path) {
+  var path = getChromeRoot(path);
+  var jar = getJar(path);
+  if (jar) {
+    var tmpdir = extractJarToTmp(jar);
+    return "file://" + tmpdir.path + "/";
+  }
+  return path;
+}
 
 Components.utils.import("resource://gre/modules/AddonManager.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 /**
  * This is a test harness designed to handle responding to UI during the process
  * of installing an XPI. A test can set callbacks to hear about specific parts
  * of the sequence.