No bug - fix some browser chrome tests that pollute the global scope
authorDão Gottwald <dao@mozilla.com>
Tue, 24 Jan 2012 23:08:42 +0100
changeset 86420 f92194f05828df1c2369ef72be2c68c8739a32a9
parent 86419 c3643d492d6825c5858dd9b76877745d3413bbe6
child 86421 90480621f7c5276483c563b864ee3943c8d6fb7f
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone12.0a1
No bug - fix some browser chrome tests that pollute the global scope
browser/base/content/test/browser_clearplugindata.js
browser/base/content/test/browser_sanitize-passwordDisabledHosts.js
browser/base/content/test/browser_sanitize-sitepermissions.js
browser/base/content/test/browser_sanitize-timespans.js
browser/base/content/test/browser_sanitizeDialog.js
browser/components/sessionstore/test/browser_248970_b.js
browser/components/sessionstore/test/browser_346337.js
dom/tests/browser/browser_ConsoleStorageAPITests.js
image/test/browser/browser_image.js
testing/mochitest/tests/SimpleTest/ChromeUtils.js
toolkit/content/tests/browser/browser_Geometry.js
toolkit/mozapps/extensions/test/browser/browser_bug562899.js
toolkit/mozapps/extensions/test/browser/browser_bug591465.js
toolkit/mozapps/extensions/test/browser/browser_bug618502.js
toolkit/mozapps/extensions/test/browser/browser_bug679604.js
toolkit/mozapps/extensions/test/browser/browser_list.js
toolkit/mozapps/extensions/test/browser/browser_updatessl.js
--- a/browser/base/content/test/browser_clearplugindata.js
+++ b/browser/base/content/test/browser_clearplugindata.js
@@ -2,18 +2,20 @@
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Test clearing plugin data using sanitize.js.
 const testURL1 = "http://mochi.test:8888/browser/browser/base/content/test/browser_clearplugindata.html";
 const testURL2 = "http://mochi.test:8888/browser/browser/base/content/test/browser_clearplugindata_noage.html";
 
+let tempScope = {};
 Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
-                                           .loadSubScript("chrome://browser/content/sanitize.js");
+                                           .loadSubScript("chrome://browser/content/sanitize.js", tempScope);
+let Sanitizer = tempScope.Sanitizer;
 
 const pluginHostIface = Ci.nsIPluginHost;
 var pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
 pluginHost.QueryInterface(pluginHostIface);
 
 var pluginTag;
 var s;
 
--- a/browser/base/content/test/browser_sanitize-passwordDisabledHosts.js
+++ b/browser/base/content/test/browser_sanitize-passwordDisabledHosts.js
@@ -1,13 +1,15 @@
 // Bug 474792 - Clear "Never remember passwords for this site" when
 // clearing site-specific settings in Clear Recent History dialog
 
+let tempScope = {};
 Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
-                                           .loadSubScript("chrome://browser/content/sanitize.js");
+                                           .loadSubScript("chrome://browser/content/sanitize.js", tempScope);
+let Sanitizer = tempScope.Sanitizer;
 
 function test() {
 
   var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
 
   // Add a disabled host
   pwmgr.setLoginSavingEnabled("http://example.com", false);
   
--- a/browser/base/content/test/browser_sanitize-sitepermissions.js
+++ b/browser/base/content/test/browser_sanitize-sitepermissions.js
@@ -1,12 +1,14 @@
 // Bug 380852 - Delete permission manager entries in Clear Recent History
 
+let tempScope = {};
 Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
-                                           .loadSubScript("chrome://browser/content/sanitize.js");
+                                           .loadSubScript("chrome://browser/content/sanitize.js", tempScope);
+let Sanitizer = tempScope.Sanitizer;
 
 function test() {
   
   // Add a permission entry
   var pm = Services.perms;
   pm.add(makeURI("http://example.com"), "testing", pm.ALLOW_ACTION);
   
   // Sanity check
--- a/browser/base/content/test/browser_sanitize-timespans.js
+++ b/browser/base/content/test/browser_sanitize-timespans.js
@@ -1,17 +1,19 @@
 // Bug 453440 - Test the timespan-based logic of the sanitizer code
 var now_uSec = Date.now() * 1000;
 
 const dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
 const bhist = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIBrowserHistory);
 const formhist = Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
 
+let tempScope = {};
 Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
-                                           .loadSubScript("chrome://browser/content/sanitize.js");
+                                           .loadSubScript("chrome://browser/content/sanitize.js", tempScope);
+let Sanitizer = tempScope.Sanitizer;
 
 function test() {
   
   var hoursSinceMidnight = new Date().getHours();
   var minutesSinceMidnight = hoursSinceMidnight * 60 + new Date().getMinutes();
 
   setupHistory();
   setupFormHistory();
--- a/browser/base/content/test/browser_sanitizeDialog.js
+++ b/browser/base/content/test/browser_sanitizeDialog.js
@@ -45,19 +45,20 @@
  * browser/base/content/test/browser_sanitize-timespans.js does that.  This
  * test checks the UI of the dialog and makes sure it's correctly connected to
  * the sanitize timespan code.
  *
  * Some of this code, especially the history creation parts, was taken from
  * browser/base/content/test/browser_sanitize-timespans.js.
  */
 
-Cc["@mozilla.org/moz/jssubscript-loader;1"].
-  getService(Ci.mozIJSSubScriptLoader).
-  loadSubScript("chrome://browser/content/sanitize.js");
+let tempScope = {};
+Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
+                                           .loadSubScript("chrome://browser/content/sanitize.js", tempScope);
+let Sanitizer = tempScope.Sanitizer;
 
 const dm = Cc["@mozilla.org/download-manager;1"].
            getService(Ci.nsIDownloadManager);
 const formhist = Cc["@mozilla.org/satchel/form-history;1"].
                  getService(Ci.nsIFormHistory2);
 
 // Add tests here.  Each is a function that's called by doNextTest().
 var gAllTests = [
--- a/browser/components/sessionstore/test/browser_248970_b.js
+++ b/browser/components/sessionstore/test/browser_248970_b.js
@@ -43,17 +43,17 @@ function test() {
       return aLambda() || true;
     } catch(ex) { }
     return false;
   }
 
   var file = Components.classes["@mozilla.org/file/directory_service;1"]
              .getService(Components.interfaces.nsIProperties)
              .get("TmpD", Components.interfaces.nsIFile);
-  filePath = file.path;
+  var filePath = file.path;
 
   let fieldList = {
     "//input[@name='input']":     Date.now().toString(),
     "//input[@name='spaced 1']":  Math.random().toString(),
     "//input[3]":                 "three",
     "//input[@type='checkbox']":  true,
     "//input[@name='uncheck']":   false,
     "//input[@type='radio'][1]":  false,
--- a/browser/components/sessionstore/test/browser_346337.js
+++ b/browser/components/sessionstore/test/browser_346337.js
@@ -37,23 +37,23 @@
 function test() {
   /** Test for Bug 346337 **/
 
   var file = Components.classes["@mozilla.org/file/directory_service;1"]
                .getService(Components.interfaces.nsIProperties)
                .get("TmpD", Components.interfaces.nsILocalFile);
   file.append("346337_test1.file");
   file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
-  filePath1 = file.path;
+  var filePath1 = file.path;
   file = Components.classes["@mozilla.org/file/directory_service;1"]
              .getService(Components.interfaces.nsIProperties)
              .get("TmpD", Components.interfaces.nsILocalFile);
   file.append("346337_test2.file");
   file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
-  filePath2 = file.path;
+  var filePath2 = file.path;
   
   let fieldList = {
     "//input[@name='input']":     Date.now().toString(),
     "//input[@name='spaced 1']":  Math.random().toString(),
     "//input[3]":                 "three",
     "//input[@type='checkbox']":  true,
     "//input[@name='uncheck']":   false,
     "//input[@type='radio'][1]":  false,
--- a/dom/tests/browser/browser_ConsoleStorageAPITests.js
+++ b/dom/tests/browser/browser_ConsoleStorageAPITests.js
@@ -1,15 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const TEST_URI = "http://example.com/browser/dom/tests/browser/test-console-api.html";
 const TEST_URI_NAV = "http://example.com/browser/dom/tests/browser/";
 
-Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm");
+let tempScope = {};
+Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm", tempScope);
+let ConsoleAPIStorage = tempScope.ConsoleAPIStorage;
 
 var apiCallCount;
 
 var ConsoleObserver = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
 
   init: function CO_init()
   {
--- a/image/test/browser/browser_image.js
+++ b/image/test/browser/browser_image.js
@@ -136,17 +136,17 @@ function testSharedContainers() {
         actOnMozImage(gBrowser.contentDocument, "img"+i, function(image) {
           gImages[i] = image;
         });
       });
       goer.next();
     }, true);
     yield;
 
-    chances = 120;
+    var chances = 120;
     do {
       gTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
       gTimer.initWithCallback(function() {
         if (gImages[0].framesNotified - gFrames >= 10) {
           goer.send(true);
         } else {
           chances--;
           goer.send(chances == 0); // maybe if we wait a bit, it will happen
--- a/testing/mochitest/tests/SimpleTest/ChromeUtils.js
+++ b/testing/mochitest/tests/SimpleTest/ChromeUtils.js
@@ -213,20 +213,18 @@ function synthesizeDragStart(element, ex
  *
  * Returns the drop effect that was desired.
  */
 function synthesizeDrop(srcElement, destElement, dragData, dropEffect, aWindow, eventUtils)
 {
   if (!aWindow)
     aWindow = window;
 
-  if (typeof(eventUtils) != 'undefined') {
-    synthesizeMouseAtCenter = eventUtils.synthesizeMouseAtCenter;
-    synthesizeMouse = eventUtils.synthesizeMouse;
-  }
+  var synthesizeMouseAtCenter = (eventUtils || window).synthesizeMouseAtCenter;
+  var synthesizeMouse = (eventUtils || window).synthesizeMouse;
 
   var gWindowUtils  = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
                              getInterface(Components.interfaces.nsIDOMWindowUtils);
   var ds = Components.classes["@mozilla.org/widget/dragservice;1"].
            getService(Components.interfaces.nsIDragService);
 
   var dataTransfer;
   var trapDrag = function(event) {
--- a/toolkit/content/tests/browser/browser_Geometry.js
+++ b/toolkit/content/tests/browser/browser_Geometry.js
@@ -29,17 +29,20 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * 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 ***** */
 
-Components.utils.import("resource://gre/modules/Geometry.jsm");
+let tempScope = {};
+Components.utils.import("resource://gre/modules/Geometry.jsm", tempScope);
+let Point = tempScope.Point;
+let Rect = tempScope.Rect;
 
 function test() {
   ok(Rect, "Rect class exists");
   for (var fname in tests) {
     tests[fname]();
   }
 }
 
--- a/toolkit/mozapps/extensions/test/browser/browser_bug562899.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug562899.js
@@ -1,16 +1,18 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Simulates quickly switching between different list views to verify that only
 // the last selected is displayed
 
-Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
+let tempScope = {};
+Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", tempScope);
+let LightweightThemeManager = tempScope.LightweightThemeManager;
 
 const xpi = "browser/toolkit/mozapps/extensions/test/browser/browser_installssl.xpi";
 
 var gManagerWindow;
 var gCategoryUtilities;
 
 function test() {
   waitForExplicitFinish();
--- a/toolkit/mozapps/extensions/test/browser/browser_bug591465.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug591465.js
@@ -1,16 +1,18 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Bug 591465 - Context menu of add-ons miss context related state change entries
 
 
-Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
+let tempScope = {};
+Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", tempScope);
+let LightweightThemeManager = tempScope.LightweightThemeManager;
 
 
 const PREF_GETADDONS_MAXRESULTS = "extensions.getAddons.maxResults";
 const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url";
 const SEARCH_URL = TESTROOT + "browser_bug591465.xml";
 const SEARCH_QUERY = "SEARCH";
 
 var gManagerWindow;
--- a/toolkit/mozapps/extensions/test/browser/browser_bug618502.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug618502.js
@@ -24,19 +24,17 @@ add_test(function() {
 
     close_manager(aManager, run_next_test);
   });
 });
 
 // Also test that opening directly to an add-on that does exist doesn't break
 // and selects the right category
 add_test(function() {
-  gProvider = new MockProvider();
-
-  gProvider.createAddons([{
+  new MockProvider().createAddons([{
     id: "addon1@tests.mozilla.org",
     name: "addon 1",
     version: "1.0"
   }]);
 
   open_manager("addons://detail/addon1@tests.mozilla.org", function(aManager) {
     gCategoryUtilities = new CategoryUtilities(aManager);
     is(gCategoryUtilities.selectedCategory, "extension", "Should have selected the right category");
--- a/toolkit/mozapps/extensions/test/browser/browser_bug679604.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug679604.js
@@ -16,16 +16,16 @@ function test() {
     var categories = aWindow.document.getElementById("categories");
     categories.setAttribute("last-selected", "foo");
     aWindow.document.persist("categories", "last-selected");
 
     close_manager(aWindow, function() {
       Services.prefs.clearUserPref(PREF_UI_LASTCATEGORY);
 
       open_manager(null, function(aWindow) {
-        gCategoryUtilities = new CategoryUtilities(aWindow);
-        is(gCategoryUtilities.selectedCategory, "discover", "Should have loaded the right view");
+        is(new CategoryUtilities(aWindow).selectedCategory, "discover",
+           "Should have loaded the right view");
 
         close_manager(aWindow, finish);
       });
     });
   });
 }
--- a/toolkit/mozapps/extensions/test/browser/browser_list.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_list.js
@@ -1,15 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Tests the list view
 
-Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
+let tempScope = {};
+Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", tempScope);
+let LightweightThemeManager = tempScope.LightweightThemeManager;
 
 
 var gProvider;
 var gManagerWindow;
 var gCategoryUtilities;
 
 var gApp = document.getElementById("bundle_brand").getString("brandShortName");
 var gVersion = Services.appinfo.version;
--- a/toolkit/mozapps/extensions/test/browser/browser_updatessl.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_updatessl.js
@@ -1,13 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-Components.utils.import("resource://gre/modules/AddonUpdateChecker.jsm");
+let tempScope = {};
+Components.utils.import("resource://gre/modules/AddonUpdateChecker.jsm", tempScope);
+let AddonUpdateChecker = tempScope.AddonUpdateChecker;
 
 const updaterdf = RELATIVE_DIR + "browser_updatessl.rdf";
 const redirect = RELATIVE_DIR + "redirect.sjs?";
 const SUCCESS = 0;
 const DOWNLOAD_ERROR = AddonUpdateChecker.ERROR_DOWNLOAD_ERROR;
 
 const HTTP = "http://example.com/";
 const HTTPS = "https://example.com/";