Bug 658738 - clean out each test's scope. r=gavin
authorDão Gottwald <dao@mozilla.com>
Fri, 10 Jun 2011 09:00:45 +0200
changeset 70842 443c7cd5bdf8c11e1b22460a7f12b52b990c581e
parent 70841 1619d8fc6416ad49bb59b81840f2c3d4a4c6b2dc
child 70854 1e3af440ce238c3dcd850237c340a4cfb741332c
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersgavin
bugs658738
milestone7.0a1
Bug 658738 - clean out each test's scope. r=gavin
browser/components/places/tests/browser/browser_library_search.js
browser/components/sessionstore/test/browser/browser_615394-SSWindowState_events.js
browser/components/sessionstore/test/browser/browser_618151.js
testing/mochitest/browser-test.js
--- a/browser/components/places/tests/browser/browser_library_search.js
+++ b/browser/components/places/tests/browser/browser_library_search.js
@@ -109,19 +109,19 @@ var testCases = [
     resetSearch("scopeBarFolder");
     search(folderId, "dummy", "scopeBarFolder");
     bmsvc.removeItem(folderId);
   },
 ];
 
 ///////////////////////////////////////////////////////////////////////////////
 
-const bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
+var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
               getService(Ci.nsINavBookmarksService);
-const histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
+var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
                 getService(Ci.nsINavHistoryService);
 var libraryWin;
 
 ///////////////////////////////////////////////////////////////////////////////
 
 /**
  * Returns the default search scope for a given folder.
  *
--- a/browser/components/sessionstore/test/browser/browser_615394-SSWindowState_events.js
+++ b/browser/components/sessionstore/test/browser/browser_615394-SSWindowState_events.js
@@ -30,17 +30,17 @@
  * 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 ***** */
 
-const ss = Cc["@mozilla.org/browser/sessionstore;1"].
+var ss = Cc["@mozilla.org/browser/sessionstore;1"].
            getService(Ci.nsISessionStore);
 
 const stateBackup = ss.getBrowserState();
 const testState = {
   windows: [{
     tabs: [
       { entries: [{ url: "about:blank" }] },
       { entries: [{ url: "about:robots" }] }
--- a/browser/components/sessionstore/test/browser/browser_618151.js
+++ b/browser/components/sessionstore/test/browser/browser_618151.js
@@ -30,17 +30,17 @@
  * 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 ***** */
 
-const ss = Cc["@mozilla.org/browser/sessionstore;1"].
+var ss = Cc["@mozilla.org/browser/sessionstore;1"].
            getService(Ci.nsISessionStore);
 
 const stateBackup = ss.getBrowserState();
 const testState = {
   windows: [{
     tabs: [
       { entries: [{ url: "about:blank" }] },
       { entries: [{ url: "about:robots" }] }
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -114,20 +114,17 @@ Tester.prototype = {
         else
           this.dumper.dump("TEST-UNEXPECTED-FAIL | (browser-test.js) | " + msg + "\n");
 
         win.close();
       }
     }
 
     // Make sure the window is raised before each test.
-    let self = this;
-    this.SimpleTest.waitForFocus(function() {
-      aCallback.apply(self);
-    });
+    this.SimpleTest.waitForFocus(aCallback);
   },
 
   finish: function Tester_finish(aSkipSummary) {
     this._cs.unregisterListener(this);
 
     this.dumper.dump("\nINFO TEST-START | Shutdown\n");
     if (this.tests.length) {
       this.dumper.dump("Browser Chrome Test Summary\n");
@@ -187,32 +184,33 @@ Tester.prototype = {
       // for its own purposes, nulling it out it will go back to the default
       // behavior of returning the last opened popup.
       document.popupNode = null;
 
       // Note the test run time
       let time = Date.now() - this.lastStartTime;
       this.dumper.dump("INFO TEST-END | " + this.currentTest.path + " | finished in " + time + "ms\n");
       this.currentTest.setDuration(time);
+
+      testScope.destroy();
+      this.currentTest.scope = null;
     }
 
     // Check the window state for the current test before moving to the next one.
     // This also causes us to check before starting any tests, since nextTest()
     // is invoked to start the tests.
-    this.waitForWindowsState(this.realNextTest);
-  },
+    this.waitForWindowsState((function () {
+      if (this.done) {
+        this.finish();
+        return;
+      }
 
-  realNextTest: function Test_realNextTest() {
-    if (this.done) {
-      this.finish();
-      return;
-    }
-
-    this.currentTestIndex++;
-    this.execTest();
+      this.currentTestIndex++;
+      this.execTest();
+    }).bind(this));
   },
 
   execTest: function Tester_execTest() {
     this.dumper.dump("TEST-START | " + this.currentTest.path + "\n");
 
     // Load the tests into a testscope
     this.currentTest.scope = new testScope(this, this.currentTest);
 
@@ -432,10 +430,15 @@ function testScope(aTester, aTest) {
 testScope.prototype = {
   __done: true,
   __generator: null,
   __waitTimer: null,
   __cleanupFunctions: [],
   __timeoutFactor: 1,
 
   EventUtils: {},
-  SimpleTest: {}
+  SimpleTest: {},
+
+  destroy: function test_destroy() {
+    for (let prop in this)
+      delete this[prop];
+  }
 };