Fix debugger tests when running with a detached toolbox (bug 817562); r=vporof
authorPanos Astithas <past@mozilla.com>
Mon, 07 Jan 2013 00:11:03 +0200
changeset 126966 a030d7a75344c8e9d247c181520834b9fd22704c
parent 126965 2ee91743312d6d2c48341f1d751edf4b915d1723
child 126967 eddf3a4a9d49141941bc27e43ada9a87b79a3143
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvporof
bugs817562
milestone20.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
Fix debugger tests when running with a detached toolbox (bug 817562); r=vporof
browser/devtools/debugger/test/browser_dbg_aaa_run_first_leaktest.js
browser/devtools/debugger/test/browser_dbg_bug727429_watch-expressions-01.js
browser/devtools/debugger/test/browser_dbg_bug727429_watch-expressions-02.js
browser/devtools/debugger/test/browser_dbg_bug731394_editor-contextmenu.js
browser/devtools/debugger/test/browser_dbg_bug740825_conditional-breakpoints-01.js
browser/devtools/debugger/test/browser_dbg_bug740825_conditional-breakpoints-02.js
browser/devtools/debugger/test/browser_dbg_location-changes-blank.js
browser/devtools/debugger/test/browser_dbg_location-changes-new.js
browser/devtools/debugger/test/browser_dbg_propertyview-edit-watch.js
browser/devtools/debugger/test/browser_dbg_propertyview-edit.js
browser/devtools/debugger/test/browser_dbg_propertyview-filter-01.js
browser/devtools/debugger/test/browser_dbg_propertyview-filter-02.js
browser/devtools/debugger/test/browser_dbg_propertyview-filter-05.js
browser/devtools/debugger/test/browser_dbg_propertyview-filter-06.js
browser/devtools/debugger/test/browser_dbg_propertyview-filter-07.js
browser/devtools/debugger/test/browser_dbg_propertyview-filter-08.js
browser/devtools/debugger/test/browser_dbg_reload-preferred-script.js
browser/devtools/debugger/test/browser_dbg_reload-same-script.js
browser/devtools/debugger/test/browser_dbg_script-switching.js
browser/devtools/debugger/test/browser_dbg_scripts-searching-01.js
browser/devtools/debugger/test/browser_dbg_scripts-searching-02.js
browser/devtools/debugger/test/browser_dbg_scripts-searching-03.js
browser/devtools/debugger/test/browser_dbg_scripts-searching-04.js
browser/devtools/debugger/test/browser_dbg_scripts-searching-05.js
browser/devtools/debugger/test/browser_dbg_scripts-searching-06.js
browser/devtools/debugger/test/browser_dbg_scripts-searching-07.js
browser/devtools/debugger/test/browser_dbg_scripts-searching-08.js
browser/devtools/debugger/test/browser_dbg_scripts-searching-files_ui.js
browser/devtools/debugger/test/browser_dbg_stack-05.js
browser/devtools/debugger/test/browser_dbg_update-editor-mode.js
--- a/browser/devtools/debugger/test/browser_dbg_aaa_run_first_leaktest.js
+++ b/browser/devtools/debugger/test/browser_dbg_aaa_run_first_leaktest.js
@@ -26,38 +26,38 @@ function test()
 
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     resumed = true;
 
+    gDebugger.addEventListener("Debugger:SourceShown", onScriptShown);
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       executeSoon(startTest);
     });
 
     executeSoon(function() {
       gDebuggee.firstCall();
     });
   });
 
   function onScriptShown(aEvent)
   {
     scriptShown = aEvent.detail.url.indexOf("-02.js") != -1;
     executeSoon(startTest);
   }
 
-  window.addEventListener("Debugger:SourceShown", onScriptShown);
-
   function startTest()
   {
     if (scriptShown && framesAdded && resumed && !testStarted) {
-      window.removeEventListener("Debugger:SourceShown", onScriptShown);
+      gDebugger.removeEventListener("Debugger:SourceShown", onScriptShown);
       testStarted = true;
       Services.tm.currentThread.dispatch({ run: performTest }, 0);
     }
   }
 
   function performTest()
   {
     closeDebuggerAndFinish();
--- a/browser/devtools/debugger/test/browser_dbg_bug727429_watch-expressions-01.js
+++ b/browser/devtools/debugger/test/browser_dbg_bug727429_watch-expressions-01.js
@@ -111,17 +111,17 @@ function test()
 
     closeDebuggerAndFinish();
   }
 
   function addAndCheckCustomExpression(total, index, string, noBlur) {
     addAndCheckExpressions(total, index, "", true);
 
     for (let i = 0; i < string.length; i++) {
-      EventUtils.sendChar(string[i]);
+      EventUtils.sendChar(string[i], gDebugger);
     }
 
     gDebugger.editor.focus();
 
     let id = gWatch.getItemAtIndex(index).attachment.id;
     let element = gDebugger.document.getElementById("expression-" + id);
 
     is(gWatch.getItemAtIndex(index).attachment.initialExpression, "",
--- a/browser/devtools/debugger/test/browser_dbg_bug727429_watch-expressions-02.js
+++ b/browser/devtools/debugger/test/browser_dbg_bug727429_watch-expressions-02.js
@@ -121,65 +121,65 @@ function test()
   function test4(callback) {
     waitForWatchExpressions(function() {
       info("Performing test4");
       checkWatchExpressions(5, "sensational", 13);
       callback();
     });
     executeSoon(function() {
       gWatch.addExpression("a = 5");
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     });
   }
 
   function test5(callback) {
     waitForWatchExpressions(function() {
       info("Performing test5");
       checkWatchExpressions(5, "sensational", 13);
       callback();
     });
     executeSoon(function() {
       gWatch.addExpression("encodeURI(\"\\\")");
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     });
   }
 
   function test6(callback) {
     waitForWatchExpressions(function() {
       info("Performing test6");
       checkWatchExpressions(5, "sensational", 13);
       callback();
     })
     executeSoon(function() {
       gWatch.addExpression("decodeURI(\"\\\")");
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     });
   }
 
   function test7(callback) {
     waitForWatchExpressions(function() {
       info("Performing test7");
       checkWatchExpressions(5, "sensational", 13);
       callback();
     });
     executeSoon(function() {
       gWatch.addExpression("?");
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     });
   }
 
   function test8(callback) {
     waitForWatchExpressions(function() {
       info("Performing test8");
       checkWatchExpressions(5, "sensational", 13);
       callback();
     });
     executeSoon(function() {
       gWatch.addExpression("a");
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     });
   }
 
   function test9(callback) {
     waitForAfterFramesCleared(function() {
       info("Performing test9");
       callback();
     });
--- a/browser/devtools/debugger/test/browser_dbg_bug731394_editor-contextmenu.js
+++ b/browser/devtools/debugger/test/browser_dbg_bug731394_editor-contextmenu.js
@@ -26,38 +26,38 @@ function test()
 
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     resumed = true;
 
+    gDebugger.addEventListener("Debugger:SourceShown", onScriptShown);
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       executeSoon(startTest);
     });
 
     executeSoon(function() {
       gDebuggee.firstCall();
     });
   });
 
   function onScriptShown(aEvent) {
     scriptShown = aEvent.detail.url.indexOf("-02.js") != -1;
     executeSoon(startTest);
   }
 
-  window.addEventListener("Debugger:SourceShown", onScriptShown);
-
   function startTest()
   {
     if (scriptShown && framesAdded && resumed && !testStarted) {
       testStarted = true;
-      window.removeEventListener("Debugger:SourceShown", onScriptShown);
+      gDebugger.removeEventListener("Debugger:SourceShown", onScriptShown);
       Services.tm.currentThread.dispatch({ run: performTest }, 0);
     }
   }
 
   function performTest()
   {
     let scripts = gDebugger.DebuggerView.Sources._container;
 
--- a/browser/devtools/debugger/test/browser_dbg_bug740825_conditional-breakpoints-01.js
+++ b/browser/devtools/debugger/test/browser_dbg_bug740825_conditional-breakpoints-01.js
@@ -31,38 +31,38 @@ function test()
     gPane = aPane;
     gDebugger = gPane.panelWin;
     gBreakpoints = gDebugger.DebuggerController.Breakpoints;
     gBreakpointsPane = gDebugger.DebuggerView.Breakpoints;
 
     gDebugger.DebuggerView.togglePanes({ visible: true, animated: false });
     resumed = true;
 
+    gDebugger.addEventListener("Debugger:SourceShown", onScriptShown);
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       executeSoon(startTest);
     });
 
     executeSoon(function() {
       gDebuggee.ermahgerd(); // ermahgerd!!
     });
   });
 
   function onScriptShown(aEvent)
   {
     scriptShown = aEvent.detail.url.indexOf("conditional-breakpoints") != -1;
     executeSoon(startTest);
   }
 
-  window.addEventListener("Debugger:SourceShown", onScriptShown);
-
   function startTest()
   {
     if (scriptShown && framesAdded && resumed && !testStarted) {
-      window.removeEventListener("Debugger:SourceShown", onScriptShown);
+      gDebugger.removeEventListener("Debugger:SourceShown", onScriptShown);
       testStarted = true;
       Services.tm.currentThread.dispatch({ run: addBreakpoints }, 0);
     }
   }
 
   function performTest()
   {
     gScripts = gDebugger.DebuggerView.Sources;
--- a/browser/devtools/debugger/test/browser_dbg_bug740825_conditional-breakpoints-02.js
+++ b/browser/devtools/debugger/test/browser_dbg_bug740825_conditional-breakpoints-02.js
@@ -32,16 +32,18 @@ function test()
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     gBreakpoints = gDebugger.DebuggerController.Breakpoints;
     gBreakpointsPane = gDebugger.DebuggerView.Breakpoints;
 
+    gDebugger.addEventListener("Debugger:SourceShown", onScriptShown);
+
     gDebugger.DebuggerView.togglePanes({ visible: true, animated: false });
     resumed = true;
 
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       executeSoon(startTest);
     });
 
@@ -51,22 +53,20 @@ function test()
   });
 
   function onScriptShown(aEvent)
   {
     scriptShown = aEvent.detail.url.indexOf("conditional-breakpoints") != -1;
     executeSoon(startTest);
   }
 
-  window.addEventListener("Debugger:SourceShown", onScriptShown);
-
   function startTest()
   {
     if (scriptShown && framesAdded && resumed && !testStarted) {
-      window.removeEventListener("Debugger:SourceShown", onScriptShown);
+      gDebugger.removeEventListener("Debugger:SourceShown", onScriptShown);
       testStarted = true;
       Services.tm.currentThread.dispatch({ run: performTest }, 0);
     }
   }
 
   function performTest()
   {
     gScripts = gDebugger.DebuggerView.Sources;
@@ -161,17 +161,17 @@ function test()
         });
       });
     });
   }
 
   function modBreakpoint3()
   {
     write("bamboocha");
-    EventUtils.sendKey("RETURN");
+    EventUtils.sendKey("RETURN", gDebugger);
 
     waitForBreakpoint(14, function() {
       waitForCaretPos(13, function() {
         waitForPopup(false, function() {
           is(gBreakpointsPane.selectedClient.conditionalExpression, "bamboocha",
             "The bamboocha expression wasn't fonud on the conditional breakpoint");
 
           executeSoon(setContextMenu);
@@ -563,17 +563,17 @@ function test()
     clear();
     append(text);
   }
 
   function append(text) {
     gBreakpointsPane._cbTextbox.focus();
 
     for (let i = 0; i < text.length; i++) {
-      EventUtils.sendChar(text[i]);
+      EventUtils.sendChar(text[i], gDebugger);
     }
   }
 
   registerCleanupFunction(function() {
     removeTab(gTab);
     gPane = null;
     gTab = null;
     gDebuggee = null;
--- a/browser/devtools/debugger/test/browser_dbg_location-changes-blank.js
+++ b/browser/devtools/debugger/test/browser_dbg_location-changes-blank.js
@@ -17,33 +17,33 @@ function test()
   let framesAdded = false;
 
   debug_tab_pane(STACK_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
 
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+      let url = aEvent.detail.url;
+      if (url.indexOf("browser_dbg_stack") != -1) {
+        scriptShown = true;
+        gDebugger.removeEventListener(aEvent.type, _onEvent);
+        runTest();
+      }
+    });
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       runTest();
     });
 
     gDebuggee.simpleCall();
   });
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    let url = aEvent.detail.url;
-    if (url.indexOf("browser_dbg_stack") != -1) {
-      scriptShown = true;
-      window.removeEventListener(aEvent.type, _onEvent);
-      runTest();
-    }
-  });
-
   function runTest()
   {
     if (scriptShown && framesAdded) {
       Services.tm.currentThread.dispatch({ run: testSimpleCall }, 0);
     }
   }
 }
 
--- a/browser/devtools/debugger/test/browser_dbg_location-changes-new.js
+++ b/browser/devtools/debugger/test/browser_dbg_location-changes-new.js
@@ -17,33 +17,33 @@ function test()
   let framesAdded = false;
 
   debug_tab_pane(STACK_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
 
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+      let url = aEvent.detail.url;
+      if (url.indexOf("browser_dbg_stack") != -1) {
+        scriptShown = true;
+        gDebugger.removeEventListener(aEvent.type, _onEvent);
+        runTest();
+      }
+    });
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       runTest();
     });
 
     gDebuggee.simpleCall();
   });
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    let url = aEvent.detail.url;
-    if (url.indexOf("browser_dbg_stack") != -1) {
-      scriptShown = true;
-      window.removeEventListener(aEvent.type, _onEvent);
-      runTest();
-    }
-  });
-
   function runTest()
   {
     if (scriptShown && framesAdded) {
       Services.tm.currentThread.dispatch({ run: testSimpleCall }, 0);
     }
   }
 }
 
--- a/browser/devtools/debugger/test/browser_dbg_propertyview-edit-watch.js
+++ b/browser/devtools/debugger/test/browser_dbg_propertyview-edit-watch.js
@@ -149,18 +149,18 @@ function testFrameEval() {
     gDebuggee.ermahgerd(); // ermahgerd!!
   });
 }
 
 function testModification(aVar, aTest, aCallback, aNewValue, aNewResult, aArgResult,
                           aLocalScopeIndex = 1, aDeletionFlag = null)
 {
   function makeChangesAndExitInputMode() {
-    EventUtils.sendString(aNewValue);
-    EventUtils.sendKey("RETURN");
+    EventUtils.sendString(aNewValue, gDebugger);
+    EventUtils.sendKey("RETURN", gDebugger);
   }
 
   EventUtils.sendMouseEvent({ type: "dblclick" },
     aVar.querySelector(".name"),
     gDebugger);
 
   executeSoon(function() {
     ok(aVar.querySelector(".element-name-input"),
--- a/browser/devtools/debugger/test/browser_dbg_propertyview-edit.js
+++ b/browser/devtools/debugger/test/browser_dbg_propertyview-edit.js
@@ -60,18 +60,18 @@ function testFrameEval() {
 
   EventUtils.sendMouseEvent({ type: "click" },
     content.document.querySelector("button"),
     content.window);
 }
 
 function testModification(aVar, aCallback, aNewValue, aNewResult) {
   function makeChangesAndExitInputMode() {
-    EventUtils.sendString(aNewValue);
-    EventUtils.sendKey("RETURN");
+    EventUtils.sendString(aNewValue, gDebugger);
+    EventUtils.sendKey("RETURN", gDebugger);
   }
 
   EventUtils.sendMouseEvent({ type: "click" },
     aVar.querySelector(".value"),
     gDebugger);
 
   executeSoon(function() {
     ok(aVar.querySelector(".element-value-input"),
--- a/browser/devtools/debugger/test/browser_dbg_propertyview-filter-01.js
+++ b/browser/devtools/debugger/test/browser_dbg_propertyview-filter-01.js
@@ -497,17 +497,17 @@ function write(text) {
   clear();
   append(text);
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
   gDebugger = null;
--- a/browser/devtools/debugger/test/browser_dbg_propertyview-filter-02.js
+++ b/browser/devtools/debugger/test/browser_dbg_propertyview-filter-02.js
@@ -439,17 +439,17 @@ function write(text) {
   clear();
   append(text);
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
   gDebugger = null;
--- a/browser/devtools/debugger/test/browser_dbg_propertyview-filter-05.js
+++ b/browser/devtools/debugger/test/browser_dbg_propertyview-filter-05.js
@@ -64,17 +64,17 @@ function testVariablesFiltering()
 
     is(loadScope.querySelectorAll(".variable:not([non-match]) > .title > .name")[0].getAttribute("value"),
       "button", "The only load variable displayed should be 'button'");
 
     let oneItem = innerScopeItem.get("one");
     is(oneItem.expanded, false,
       "The one item in the inner scope should not be expanded");
 
-    EventUtils.sendKey("RETURN");
+    EventUtils.sendKey("RETURN", gDebugger);
     is(oneItem.expanded, true,
       "The one item in the inner scope should now be expanded");
   }
 
   function test2()
   {
     write("*two");
     ignoreExtraMatchedProperties();
@@ -103,17 +103,17 @@ function testVariablesFiltering()
 
     is(innerScope.querySelectorAll(".variable:not([non-match]) > .title > .name")[0].getAttribute("value"),
       "two", "The only inner variable displayed should be 'two'");
 
     let twoItem = innerScopeItem.get("two");
     is(twoItem.expanded, false,
       "The two item in the inner scope should not be expanded");
 
-    EventUtils.sendKey("RETURN");
+    EventUtils.sendKey("RETURN", gDebugger);
     is(twoItem.expanded, true,
       "The two item in the inner scope should now be expanded");
   }
 
   function test3()
   {
     backspace(3);
     ignoreExtraMatchedProperties();
@@ -280,25 +280,25 @@ function clear() {
 
 function write(text) {
   clear();
   append(text);
 }
 
 function backspace(times) {
   for (let i = 0; i < times; i++) {
-    EventUtils.sendKey("BACK_SPACE")
+    EventUtils.sendKey("BACK_SPACE", gDebugger)
   }
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
   gDebugger = null;
--- a/browser/devtools/debugger/test/browser_dbg_propertyview-filter-06.js
+++ b/browser/devtools/debugger/test/browser_dbg_propertyview-filter-06.js
@@ -36,43 +36,43 @@ function testVariablesFiltering()
     test1: function()
     {
       assertExpansion(1, [true, false, false, false, false]);
       clear();
     },
     test2: function()
     {
       assertExpansion(2, [true, false, false, false, false]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     },
     test3: function()
     {
       assertExpansion(3, [true, false, false, false, false]);
       gDebugger.editor.focus();
     },
     test4: function()
     {
       assertExpansion(4, [true, false, false, false, false]);
       write("*");
     },
     test5: function() {
       assertExpansion(5, [true, true, true, true, true]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     },
     test6: function() {
       assertExpansion(6, [true, true, true, true, true]);
       gDebugger.editor.focus();
     },
     test7: function() {
       assertExpansion(7, [true, true, true, true, true]);
       backspace(1);
     },
     test8: function() {
       assertExpansion(8, [true, true, true, true, true]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     },
     test9: function() {
       assertExpansion(9, [true, true, true, true, true]);
       gDebugger.editor.focus();
     },
     test10: function() {
       assertExpansion(10, [true, true, true, true, true]);
       innerScopeItem.collapse();
@@ -82,41 +82,41 @@ function testVariablesFiltering()
       globalScopeItem.collapse();
     },
     test11: function() {
       assertExpansion(11, [false, false, false, false, false]);
       clear();
     },
     test12: function() {
       assertExpansion(12, [false, false, false, false, false]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     },
     test13: function() {
       assertExpansion(13, [false, false, false, false, false]);
       gDebugger.editor.focus();
     },
     test14: function() {
       assertExpansion(14, [false, false, false, false, false]);
       write("*");
     },
     test15: function() {
       assertExpansion(15, [true, true, true, true, true]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     },
     test16: function() {
       assertExpansion(16, [true, true, true, true, true]);
       gDebugger.editor.focus();
     },
     test17: function() {
       assertExpansion(17, [true, true, true, true, true]);
       backspace(1);
     },
     test18: function() {
       assertExpansion(18, [true, true, true, true, true]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     },
     test19: function() {
       assertExpansion(19, [true, true, true, true, true]);
       gDebugger.editor.focus();
     },
     test20: function() {
       assertExpansion(20, [true, true, true, true, true]);
     }
@@ -222,25 +222,25 @@ function clear() {
 
 function write(text) {
   clear();
   append(text);
 }
 
 function backspace(times) {
   for (let i = 0; i < times; i++) {
-    EventUtils.sendKey("BACK_SPACE")
+    EventUtils.sendKey("BACK_SPACE", gDebugger)
   }
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
   gDebugger = null;
--- a/browser/devtools/debugger/test/browser_dbg_propertyview-filter-07.js
+++ b/browser/devtools/debugger/test/browser_dbg_propertyview-filter-07.js
@@ -36,43 +36,43 @@ function testVariablesFiltering()
     test1: function()
     {
       assertExpansion(1, [true, false, false, false, false]);
       clear();
     },
     test2: function()
     {
       assertExpansion(2, [true, false, false, false, false]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     },
     test3: function()
     {
       assertExpansion(3, [true, false, false, false, false]);
       gDebugger.editor.focus();
     },
     test4: function()
     {
       assertExpansion(4, [true, false, false, false, false]);
       write("*");
     },
     test5: function() {
       assertExpansion(5, [true, true, true, true, true]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     },
     test6: function() {
       assertExpansion(6, [true, true, true, true, true]);
       gDebugger.editor.focus();
     },
     test7: function() {
       assertExpansion(7, [true, true, true, true, true]);
       backspace(1);
     },
     test8: function() {
       assertExpansion(8, [true, true, true, true, true]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     },
     test9: function() {
       assertExpansion(9, [true, true, true, true, true]);
       gDebugger.editor.focus();
     },
     test10: function() {
       assertExpansion(10, [true, true, true, true, true]);
       innerScopeItem.collapse();
@@ -82,41 +82,41 @@ function testVariablesFiltering()
       globalScopeItem.collapse();
     },
     test11: function() {
       assertExpansion(11, [false, false, false, false, false]);
       clear();
     },
     test12: function() {
       assertExpansion(12, [false, false, false, false, false]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     },
     test13: function() {
       assertExpansion(13, [false, false, false, false, false]);
       gDebugger.editor.focus();
     },
     test14: function() {
       assertExpansion(14, [false, false, false, false, false]);
       write("*");
     },
     test15: function() {
       assertExpansion(15, [true, true, true, true, true]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     },
     test16: function() {
       assertExpansion(16, [true, true, true, true, true]);
       gDebugger.editor.focus();
     },
     test17: function() {
       assertExpansion(17, [true, true, true, true, true]);
       backspace(1);
     },
     test18: function() {
       assertExpansion(18, [true, true, true, true, true]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
     },
     test19: function() {
       assertExpansion(19, [true, true, true, true, true]);
       gDebugger.editor.focus();
     },
     test20: function() {
       assertExpansion(20, [true, true, true, true, true]);
     }
@@ -227,25 +227,25 @@ function clear() {
 
 function write(text) {
   clear();
   append(text);
 }
 
 function backspace(times) {
   for (let i = 0; i < times; i++) {
-    EventUtils.sendKey("BACK_SPACE")
+    EventUtils.sendKey("BACK_SPACE", gDebugger);
   }
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
   gDebugger = null;
--- a/browser/devtools/debugger/test/browser_dbg_propertyview-filter-08.js
+++ b/browser/devtools/debugger/test/browser_dbg_propertyview-filter-08.js
@@ -42,17 +42,17 @@ function testVariablesFiltering()
     test2: function(aCallback)
     {
       is(testScopeItem.get("arguments").expanded, false,
         "The arguments pseudoarray in the testScope should not be expanded");
       is(loadScopeItem.get("arguments").expanded, false,
         "The arguments pseudoarray in the testScope should not be expanded");
 
       assertExpansion(1, [true, true, true, true, true]);
-      EventUtils.sendKey("RETURN");
+      EventUtils.sendKey("RETURN", gDebugger);
       aCallback();
     },
     test3: function(aCallback)
     {
       is(testScopeItem.get("arguments").expanded, true,
         "The arguments pseudoarray in the testScope should now be expanded");
       is(loadScopeItem.get("arguments").expanded, true,
         "The arguments pseudoarray in the testScope should now be expanded");
@@ -297,25 +297,25 @@ function clear() {
 
 function write(text) {
   clear();
   append(text);
 }
 
 function backspace(times) {
   for (let i = 0; i < times; i++) {
-    EventUtils.sendKey("BACK_SPACE")
+    EventUtils.sendKey("BACK_SPACE", gDebugger);
   }
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
   gDebugger = null;
--- a/browser/devtools/debugger/test/browser_dbg_reload-preferred-script.js
+++ b/browser/devtools/debugger/test/browser_dbg_reload-preferred-script.js
@@ -26,33 +26,33 @@ function test()
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     gView = gDebugger.DebuggerView;
     resumed = true;
 
+    gDebugger.addEventListener("Debugger:SourceShown", onScriptShown);
+
     gView.Sources.preferredSource = EXAMPLE_URL + expectedScript;
     startTest();
   });
 
   function onScriptShown(aEvent)
   {
     expectedScriptShown = aEvent.detail.url.indexOf(expectedScript) != -1;
     scriptShownUrl = aEvent.detail.url;
     startTest();
   }
 
-  window.addEventListener("Debugger:SourceShown", onScriptShown);
-
   function startTest()
   {
     if (expectedScriptShown && resumed && !testStarted) {
-      window.removeEventListener("Debugger:SourceShown", onScriptShown);
+      gDebugger.removeEventListener("Debugger:SourceShown", onScriptShown);
       testStarted = true;
       Services.tm.currentThread.dispatch({ run: performTest }, 0);
     }
   }
 
   function performTest()
   {
     info("Currently preferred script: " + gView.Sources.preferredValue);
--- a/browser/devtools/debugger/test/browser_dbg_reload-same-script.js
+++ b/browser/devtools/debugger/test/browser_dbg_reload-same-script.js
@@ -27,16 +27,18 @@ function test()
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     gView = gDebugger.DebuggerView;
     resumed = true;
 
+    gDebugger.addEventListener("Debugger:SourceShown", onScriptShown);
+
     startTest();
   });
 
   function onScriptShown(aEvent)
   {
     expectedScriptShown = aEvent.detail.url.indexOf("-01.js") != -1;
     scriptShownUrl = aEvent.detail.url;
     startTest();
@@ -50,32 +52,30 @@ function test()
     info("The expected script for this ScriptShown event is: " + expectedScript);
     info("The current script for this ScriptShown event is: " + aEvent.detail.url);
 
     expectedScriptShown = aEvent.detail.url.indexOf(expectedScript) != -1;
     scriptShownUrl = aEvent.detail.url;
     testScriptShown();
   }
 
-  window.addEventListener("Debugger:SourceShown", onScriptShown);
-
   function startTest()
   {
     if (expectedScriptShown && resumed && !testStarted) {
-      window.removeEventListener("Debugger:SourceShown", onScriptShown);
-      window.addEventListener("Debugger:SourceShown", onUlteriorScriptShown);
+      gDebugger.removeEventListener("Debugger:SourceShown", onScriptShown);
+      gDebugger.addEventListener("Debugger:SourceShown", onUlteriorScriptShown);
       testStarted = true;
       Services.tm.currentThread.dispatch({ run: performTest }, 0);
     }
   }
 
   function finishTest()
   {
     if (expectedScriptShown && resumed && testStarted) {
-      window.removeEventListener("Debugger:SourceShown", onUlteriorScriptShown);
+      gDebugger.removeEventListener("Debugger:SourceShown", onUlteriorScriptShown);
       closeDebuggerAndFinish();
     }
   }
 
   function performTest()
   {
     testCurrentScript("-01.js", step);
     expectedScript = "-01.js";
--- a/browser/devtools/debugger/test/browser_dbg_script-switching.js
+++ b/browser/devtools/debugger/test/browser_dbg_script-switching.js
@@ -23,38 +23,38 @@ function test()
 
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     resumed = true;
 
+    gDebugger.addEventListener("Debugger:SourceShown", onScriptShown);
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       executeSoon(startTest);
     });
 
     executeSoon(function() {
       gDebuggee.firstCall();
     });
   });
 
   function onScriptShown(aEvent)
   {
     scriptShown = aEvent.detail.url.indexOf("-02.js") != -1;
     executeSoon(startTest);
   }
 
-  window.addEventListener("Debugger:SourceShown", onScriptShown);
-
   function startTest()
   {
     if (scriptShown && framesAdded && resumed && !testStarted) {
-      window.removeEventListener("Debugger:SourceShown", onScriptShown);
+      gDebugger.removeEventListener("Debugger:SourceShown", onScriptShown);
       testStarted = true;
       Services.tm.currentThread.dispatch({ run: testScriptsDisplay }, 0);
     }
   }
 }
 
 function testScriptsDisplay() {
   gScripts = gDebugger.DebuggerView.Sources._container;
@@ -82,20 +82,20 @@ function testScriptsDisplay() {
     label2), "Second script label is incorrect.");
 
   ok(gDebugger.editor.getText().search(/debugger/) != -1,
     "The correct script was loaded initially.");
 
   is(gDebugger.editor.getDebugLocation(), 5,
      "editor debugger location is correct.");
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     let url = aEvent.detail.url;
     if (url.indexOf("-01.js") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
       testSwitchPaused();
     }
   });
 
   gDebugger.DebuggerView.Sources.selectedValue = EXAMPLE_URL + label1;
 }
 
 function testSwitchPaused()
@@ -105,20 +105,20 @@ function testSwitchPaused()
 
   ok(gDebugger.editor.getText().search(/firstCall/) != -1,
     "The first script is displayed.");
 
   is(gDebugger.editor.getDebugLocation(), -1,
      "editor debugger location has been cleared.");
 
   gDebugger.DebuggerController.activeThread.resume(function() {
-    window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
       let url = aEvent.detail.url;
       if (url.indexOf("-02.js") != -1) {
-        window.removeEventListener(aEvent.type, _onEvent);
+        gDebugger.removeEventListener(aEvent.type, _onEvent);
         testSwitchRunning();
       }
     });
 
     gDebugger.DebuggerView.Sources.selectedValue = EXAMPLE_URL +
                                                    "test-script-switching-02.js";
   });
 }
--- a/browser/devtools/debugger/test/browser_dbg_scripts-searching-01.js
+++ b/browser/devtools/debugger/test/browser_dbg_scripts-searching-01.js
@@ -21,30 +21,30 @@ function test()
   let framesAdded = false;
 
   debug_tab_pane(STACK_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
 
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
+      scriptShown = true;
+      runTest();
+    });
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       runTest();
     });
 
     gDebuggee.simpleCall();
   });
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
-    scriptShown = true;
-    runTest();
-  });
-
   function runTest()
   {
     if (scriptShown && framesAdded) {
       Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
     }
   }
 }
 
@@ -58,78 +58,78 @@ function testScriptSearching() {
     gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
     gMenulist = gScripts._container;
 
     write(":12");
     ok(gEditor.getCaretPosition().line == 11 &&
        gEditor.getCaretPosition().col == 0,
       "The editor didn't jump to the correct line.");
 
-    EventUtils.synthesizeKey("g", { metaKey: true });
+    EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger);
     ok(gEditor.getCaretPosition().line == 12 &&
        gEditor.getCaretPosition().col == 0,
       "The editor didn't jump to the correct line after Meta+G");
 
-    EventUtils.synthesizeKey("n", { ctrlKey: true });
+    EventUtils.synthesizeKey("n", { ctrlKey: true }, gDebugger);
     ok(gEditor.getCaretPosition().line == 13 &&
        gEditor.getCaretPosition().col == 0,
       "The editor didn't jump to the correct line after Ctrl+N");
 
-    EventUtils.synthesizeKey("G", { metaKey: true, shiftKey: true });
+    EventUtils.synthesizeKey("G", { metaKey: true, shiftKey: true }, gDebugger);
     ok(gEditor.getCaretPosition().line == 12 &&
        gEditor.getCaretPosition().col == 0,
       "The editor didn't jump to the correct line after Meta+Shift+G");
 
-    EventUtils.synthesizeKey("p", { ctrlKey: true });
+    EventUtils.synthesizeKey("p", { ctrlKey: true }, gDebugger);
     ok(gEditor.getCaretPosition().line == 11 &&
        gEditor.getCaretPosition().col == 0,
       "The editor didn't jump to the correct line after Ctrl+P");
 
     for (let i = 0; i < 100; i++) {
-      EventUtils.sendKey("DOWN");
+      EventUtils.sendKey("DOWN", gDebugger);
     }
     ok(gEditor.getCaretPosition().line == 32 &&
        gEditor.getCaretPosition().col == 0,
       "The editor didn't jump to the correct line after multiple DOWN keys");
 
     for (let i = 0; i < 100; i++) {
-      EventUtils.sendKey("UP");
+      EventUtils.sendKey("UP", gDebugger);
     }
     ok(gEditor.getCaretPosition().line == 0 &&
        gEditor.getCaretPosition().col == 0,
       "The editor didn't jump to the correct line after multiple UP keys");
 
 
     token = "debugger";
     write("#" + token);
     ok(gEditor.getCaretPosition().line == 2 &&
        gEditor.getCaretPosition().col == 44 + token.length,
       "The editor didn't jump to the correct token. (1)");
 
-    EventUtils.sendKey("DOWN");
+    EventUtils.sendKey("DOWN", gDebugger);
     ok(gEditor.getCaretPosition().line == 8 &&
        gEditor.getCaretPosition().col == 2 + token.length,
       "The editor didn't jump to the correct token. (2)");
 
-    EventUtils.sendKey("DOWN");
+    EventUtils.sendKey("DOWN", gDebugger);
     ok(gEditor.getCaretPosition().line == 12 &&
        gEditor.getCaretPosition().col == 8 + token.length,
       "The editor didn't jump to the correct token. (3)");
 
-    EventUtils.sendKey("RETURN");
+    EventUtils.sendKey("RETURN", gDebugger);
     ok(gEditor.getCaretPosition().line == 19 &&
        gEditor.getCaretPosition().col == 4 + token.length,
       "The editor didn't jump to the correct token. (4)");
 
-    EventUtils.sendKey("ENTER");
+    EventUtils.sendKey("ENTER", gDebugger);
     ok(gEditor.getCaretPosition().line == 2 &&
        gEditor.getCaretPosition().col == 44 + token.length,
       "The editor didn't jump to the correct token. (5)");
 
-    EventUtils.sendKey("UP");
+    EventUtils.sendKey("UP", gDebugger);
     ok(gEditor.getCaretPosition().line == 19 &&
        gEditor.getCaretPosition().col == 4 + token.length,
       "The editor didn't jump to the correct token. (5.1)");
 
 
     token = "debugger;";
     write(":bogus#" + token);
     ok(gEditor.getCaretPosition().line == 8 &&
@@ -222,24 +222,24 @@ function testScriptSearching() {
     write("#" + token);
     ok(gEditor.getCaretPosition().line == 2 &&
        gEditor.getCaretPosition().col == 44 + token.length,
       "The editor didn't jump to the correct token. (12.1)");
     isnot(gMenulist.getAttribute("label"), noMatchingScripts,
       "The menulist should not display a notice that matches are found.");
 
     clear();
-    EventUtils.sendKey("RETURN");
+    EventUtils.sendKey("RETURN", gDebugger);
     ok(gEditor.getCaretPosition().line == 2 &&
        gEditor.getCaretPosition().col == 44 + token.length,
       "The editor shouldn't jump to another token. (12.2)");
     isnot(gMenulist.getAttribute("label"), noMatchingScripts,
       "The menulist should not display a notice that matches are found.");
 
-    EventUtils.sendKey("ENTER");
+    EventUtils.sendKey("ENTER", gDebugger);
     ok(gEditor.getCaretPosition().line == 2 &&
        gEditor.getCaretPosition().col == 44 + token.length,
       "The editor shouldn't jump to another token. (12.3)");
     isnot(gMenulist.getAttribute("label"), noMatchingScripts,
       "The menulist should not display a notice that matches are found.");
 
 
     write(":1:2:3:a:b:c:::12");
@@ -247,37 +247,37 @@ function testScriptSearching() {
        gEditor.getCaretPosition().col == 0,
       "The editor didn't jump to the correct line. (13)");
 
     write("#don't#find#me#instead#find#" + token);
     ok(gEditor.getCaretPosition().line == 2 &&
        gEditor.getCaretPosition().col == 44 + token.length,
       "The editor didn't jump to the correct token. (14)");
 
-    EventUtils.sendKey("DOWN");
+    EventUtils.sendKey("DOWN", gDebugger);
     ok(gEditor.getCaretPosition().line == 8 &&
        gEditor.getCaretPosition().col == 2 + token.length,
       "The editor didn't jump to the correct token. (15)");
 
-    EventUtils.sendKey("DOWN");
+    EventUtils.sendKey("DOWN", gDebugger);
     ok(gEditor.getCaretPosition().line == 12 &&
        gEditor.getCaretPosition().col == 8 + token.length,
       "The editor didn't jump to the correct token. (16)");
 
-    EventUtils.sendKey("RETURN");
+    EventUtils.sendKey("RETURN", gDebugger);
     ok(gEditor.getCaretPosition().line == 19 &&
        gEditor.getCaretPosition().col == 4 + token.length,
       "The editor didn't jump to the correct token. (17)");
 
-    EventUtils.sendKey("ENTER");
+    EventUtils.sendKey("ENTER", gDebugger);
     ok(gEditor.getCaretPosition().line == 2 &&
        gEditor.getCaretPosition().col == 44 + token.length,
       "The editor didn't jump to the correct token. (18)");
 
-    EventUtils.sendKey("UP");
+    EventUtils.sendKey("UP", gDebugger);
     ok(gEditor.getCaretPosition().line == 19 &&
        gEditor.getCaretPosition().col == 4 + token.length,
       "The editor didn't jump to the correct token. (18.1)");
 
 
     clear();
     ok(gEditor.getCaretPosition().line == 19 &&
        gEditor.getCaretPosition().col == 4 + token.length,
@@ -300,17 +300,17 @@ function write(text) {
   clear();
   append(text);
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
   info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
--- a/browser/devtools/debugger/test/browser_dbg_scripts-searching-02.js
+++ b/browser/devtools/debugger/test/browser_dbg_scripts-searching-02.js
@@ -23,33 +23,33 @@ function test()
   let framesAdded = false;
 
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
 
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+      let url = aEvent.detail.url;
+      if (url.indexOf("-02.js") != -1) {
+        scriptShown = true;
+        gDebugger.removeEventListener(aEvent.type, _onEvent);
+        runTest();
+      }
+    });
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       runTest();
     });
 
     gDebuggee.firstCall();
   });
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    let url = aEvent.detail.url;
-    if (url.indexOf("-02.js") != -1) {
-      scriptShown = true;
-      window.removeEventListener(aEvent.type, _onEvent);
-      runTest();
-    }
-  });
-
   function runTest()
   {
     if (scriptShown && framesAdded) {
       Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
     }
   }
 }
 
@@ -60,23 +60,23 @@ function testScriptSearching() {
     gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
     gMenulist = gScripts._container;
 
     firstSearch();
   });
 }
 
 function firstSearch() {
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     info("Current script url:\n" + aEvent.detail.url + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = aEvent.detail.url;
     if (url.indexOf("-01.js") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
 
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 4 &&
            gEditor.getCaretPosition().col == 0,
           "The editor didn't jump to the correct line. (1)");
         is(gScripts.visibleItems.length, 1,
           "Not all the correct scripts are shown after the search. (1)");
@@ -86,23 +86,23 @@ function firstSearch() {
     }
   });
   write(".*-01\.js:5");
 }
 
 function secondSearch() {
   let token = "deb";
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     info("Current script url:\n" + aEvent.detail.url + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = aEvent.detail.url;
     if (url.indexOf("-02.js") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
 
       executeSoon(function() {
         append("#" + token);
 
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
            gEditor.getCaretPosition().col == 8 + token.length,
           "The editor didn't jump to the correct line. (2)");
@@ -112,42 +112,42 @@ function secondSearch() {
         waitForFirstScript();
       });
     }
   });
   gScripts.selectedIndex = 1;
 }
 
 function waitForFirstScript() {
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     info("Current script url:\n" + aEvent.detail.url + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = aEvent.detail.url;
     if (url.indexOf("-01.js") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
 
       executeSoon(function() {
         thirdSearch();
       });
     }
   });
   gScripts.selectedIndex = 0;
 }
 
 function thirdSearch() {
   let token = "deb";
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     info("Current script url:\n" + aEvent.detail.url + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = aEvent.detail.url;
     if (url.indexOf("-02.js") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
 
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
            gEditor.getCaretPosition().col == 8 + token.length,
           "The editor didn't jump to the correct line. (3)");
         is(gScripts.visibleItems.length, 1,
           "Not all the correct scripts are shown after the search. (3)");
@@ -162,17 +162,17 @@ function thirdSearch() {
 function fourthSearch(i, string, token) {
   info("Searchbox value: " + gSearchBox.value);
 
   ok(gEditor.getCaretPosition().line == 5 &&
      gEditor.getCaretPosition().col == 8 + token.length + i,
     "The editor didn't remain at the correct token. (4)");
 
   if (string[i]) {
-    EventUtils.sendChar(string[i]);
+    EventUtils.sendChar(string[i], gDebugger);
     fourthSearch(i + 1, string, token);
     return;
   }
 
   clear();
   ok(gEditor.getCaretPosition().line == 5 &&
      gEditor.getCaretPosition().col == 8 + token.length + i,
     "The editor didn't remain at the correct token. (5)");
@@ -240,17 +240,17 @@ function write(text) {
   clear();
   append(text);
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
   info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
--- a/browser/devtools/debugger/test/browser_dbg_scripts-searching-03.js
+++ b/browser/devtools/debugger/test/browser_dbg_scripts-searching-03.js
@@ -25,33 +25,33 @@ function test()
 
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     gDebugger.SourceResults.prototype.alwaysExpand = false;
 
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+      let url = aEvent.detail.url;
+      if (url.indexOf("-02.js") != -1) {
+        scriptShown = true;
+        gDebugger.removeEventListener(aEvent.type, _onEvent);
+        runTest();
+      }
+    });
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       runTest();
     });
 
     gDebuggee.firstCall();
   });
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    let url = aEvent.detail.url;
-    if (url.indexOf("-02.js") != -1) {
-      scriptShown = true;
-      window.removeEventListener(aEvent.type, _onEvent);
-      runTest();
-    }
-  });
-
   function runTest()
   {
     if (scriptShown && framesAdded) {
       Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
     }
   }
 }
 
@@ -69,18 +69,18 @@ function testScriptSearching() {
 function firstSearch() {
   is(gSearchView._container._list.childNodes.length, 0,
     "The global search pane shouldn't have any child nodes yet.");
   is(gSearchView._container._parent.hidden, true,
     "The global search pane shouldn't be visible yet.");
   is(gSearchView._splitter.hidden, true,
     "The global search pane splitter shouldn't be visible yet.");
 
-  window.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
@@ -185,18 +185,18 @@ function firstSearch() {
 function secondSearch() {
   isnot(gSearchView._container._list.childNodes.length, 0,
     "The global search pane should have some child nodes from the previous search.");
   is(gSearchView._container._parent.hidden, false,
     "The global search pane should be visible from the previous search.");
   is(gSearchView._splitter.hidden, false,
     "The global search pane splitter should be visible from the previous search.");
 
-  window.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
@@ -306,25 +306,25 @@ function clear() {
 
 function write(text) {
   clear();
   append(text);
 }
 
 function backspace(times) {
   for (let i = 0; i < times; i++) {
-    EventUtils.sendKey("BACK_SPACE")
+    EventUtils.sendKey("BACK_SPACE", gDebugger);
   }
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
   info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
--- a/browser/devtools/debugger/test/browser_dbg_scripts-searching-04.js
+++ b/browser/devtools/debugger/test/browser_dbg_scripts-searching-04.js
@@ -25,33 +25,33 @@ function test()
 
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     gDebugger.SourceResults.prototype.alwaysExpand = false;
 
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+      let url = aEvent.detail.url;
+      if (url.indexOf("-02.js") != -1) {
+        scriptShown = true;
+        gDebugger.removeEventListener(aEvent.type, _onEvent);
+        runTest();
+      }
+    });
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       runTest();
     });
 
     gDebuggee.firstCall();
   });
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    let url = aEvent.detail.url;
-    if (url.indexOf("-02.js") != -1) {
-      scriptShown = true;
-      window.removeEventListener(aEvent.type, _onEvent);
-      runTest();
-    }
-  });
-
   function runTest()
   {
     if (scriptShown && framesAdded) {
       Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
     }
   }
 }
 
@@ -69,18 +69,18 @@ function testScriptSearching() {
 function doSearch() {
   is(gSearchView._container._list.childNodes.length, 0,
     "The global search pane shouldn't have any child nodes yet.");
   is(gSearchView._container._parent.hidden, true,
     "The global search pane shouldn't be visible yet.");
   is(gSearchView._splitter.hidden, true,
     "The global search pane splitter shouldn't be visible yet.");
 
-  window.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
@@ -103,18 +103,18 @@ function doSearch() {
     }
   });
   executeSoon(function() {
     write("!eval");
   });
 }
 
 function doFirstJump() {
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + aEvent.detail.url + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = aEvent.detail.url;
     if (url.indexOf("-01.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 4 &&
@@ -125,23 +125,23 @@ function doFirstJump() {
 
         doSecondJump();
       });
     } else {
       ok(false, "We jumped in a bowl of hot lava (aka WRONG MATCH). That was bad for us.");
     }
   });
   executeSoon(function() {
-    EventUtils.sendKey("DOWN");
+    EventUtils.sendKey("DOWN", gDebugger);
   });
 }
 
 function doSecondJump() {
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + aEvent.detail.url + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = aEvent.detail.url;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
@@ -152,23 +152,23 @@ function doSecondJump() {
 
         doWrapAroundJump();
       });
     } else {
       ok(false, "We jumped in a bowl of hot lava (aka WRONG MATCH). That was bad for us.");
     }
   });
   executeSoon(function() {
-    EventUtils.sendKey("RETURN");
+    EventUtils.sendKey("RETURN", gDebugger);
   });
 }
 
 function doWrapAroundJump() {
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + aEvent.detail.url + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = aEvent.detail.url;
     if (url.indexOf("-01.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 4 &&
@@ -179,23 +179,23 @@ function doWrapAroundJump() {
 
         doBackwardsWrapAroundJump();
       });
     } else {
       ok(false, "We jumped in a bowl of hot lava (aka WRONG MATCH). That was bad for us.");
     }
   });
   executeSoon(function() {
-    EventUtils.sendKey("ENTER");
+    EventUtils.sendKey("ENTER", gDebugger);
   });
 }
 
 function doBackwardsWrapAroundJump() {
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + aEvent.detail.url + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = aEvent.detail.url;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
@@ -206,23 +206,23 @@ function doBackwardsWrapAroundJump() {
 
         testSearchTokenEmpty();
       });
     } else {
       ok(false, "We jumped in a bowl of hot lava (aka WRONG MATCH). That was bad for us.");
     }
   });
   executeSoon(function() {
-    EventUtils.sendKey("UP");
+    EventUtils.sendKey("UP", gDebugger);
   });
 }
 
 function testSearchTokenEmpty() {
-  window.addEventListener("Debugger:GlobalSearch:TokenEmpty", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:GlobalSearch:TokenEmpty", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
@@ -254,25 +254,25 @@ function clear() {
 
 function write(text) {
   clear();
   append(text);
 }
 
 function backspace(times) {
   for (let i = 0; i < times; i++) {
-    EventUtils.sendKey("BACK_SPACE")
+    EventUtils.sendKey("BACK_SPACE", gDebugger);
   }
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
   info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
--- a/browser/devtools/debugger/test/browser_dbg_scripts-searching-05.js
+++ b/browser/devtools/debugger/test/browser_dbg_scripts-searching-05.js
@@ -25,33 +25,33 @@ function test()
 
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     gDebugger.SourceResults.prototype.alwaysExpand = false;
 
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+      let url = aEvent.detail.url;
+      if (url.indexOf("-02.js") != -1) {
+        scriptShown = true;
+        gDebugger.removeEventListener(aEvent.type, _onEvent);
+        runTest();
+      }
+    });
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       runTest();
     });
 
     gDebuggee.firstCall();
   });
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    let url = aEvent.detail.url;
-    if (url.indexOf("-02.js") != -1) {
-      scriptShown = true;
-      window.removeEventListener(aEvent.type, _onEvent);
-      runTest();
-    }
-  });
-
   function runTest()
   {
     if (scriptShown && framesAdded) {
       Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
     }
   }
 }
 
@@ -69,18 +69,18 @@ function testScriptSearching() {
 function doSearch() {
   is(gSearchView._container._list.childNodes.length, 0,
     "The global search pane shouldn't have any child nodes yet.");
   is(gSearchView._container._parent.hidden, true,
     "The global search pane shouldn't be visible yet.");
   is(gSearchView._splitter.hidden, true,
     "The global search pane splitter shouldn't be visible yet.");
 
-  window.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
@@ -113,32 +113,32 @@ function testLocationChange()
   let cacheCleared = false;
 
   function _maybeFinish() {
     if (viewCleared && cacheCleared) {
       closeDebuggerAndFinish();
     }
   }
 
-  window.addEventListener("Debugger:GlobalSearch:ViewCleared", function _onViewCleared(aEvent) {
-    window.removeEventListener(aEvent.type, _onViewCleared);
+  gDebugger.addEventListener("Debugger:GlobalSearch:ViewCleared", function _onViewCleared(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onViewCleared);
 
     is(gSearchView._container._list.childNodes.length, 0,
       "The global search pane shouldn't have any child nodes after a page navigation.");
     is(gSearchView._container._parent.hidden, true,
       "The global search pane shouldn't be visible after a page navigation.");
     is(gSearchView._splitter.hidden, true,
       "The global search pane splitter shouldn't be visible after a page navigation.");
 
     viewCleared = true;
     _maybeFinish();
   });
 
-  window.addEventListener("Debugger:GlobalSearch:CacheCleared", function _onCacheCleared(aEvent) {
-    window.removeEventListener(aEvent.type, _onCacheCleared);
+  gDebugger.addEventListener("Debugger:GlobalSearch:CacheCleared", function _onCacheCleared(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onCacheCleared);
 
     is(gSearchView._cache.size, 0,
       "The scripts sources cache for global searching should be cleared after a page navigation.")
 
     cacheCleared = true;
     _maybeFinish();
   });
 
@@ -154,17 +154,17 @@ function write(text) {
   clear();
   append(text);
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
   info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
--- a/browser/devtools/debugger/test/browser_dbg_scripts-searching-06.js
+++ b/browser/devtools/debugger/test/browser_dbg_scripts-searching-06.js
@@ -25,33 +25,33 @@ function test()
 
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     gDebugger.SourceResults.prototype.alwaysExpand = false;
 
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+      let url = aEvent.detail.url;
+      if (url.indexOf("-02.js") != -1) {
+        scriptShown = true;
+        gDebugger.removeEventListener(aEvent.type, _onEvent);
+        runTest();
+      }
+    });
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       runTest();
     });
 
     gDebuggee.firstCall();
   });
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    let url = aEvent.detail.url;
-    if (url.indexOf("-02.js") != -1) {
-      scriptShown = true;
-      window.removeEventListener(aEvent.type, _onEvent);
-      runTest();
-    }
-  });
-
   function runTest()
   {
     if (scriptShown && framesAdded) {
       Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
     }
   }
 }
 
@@ -62,18 +62,18 @@ function testScriptSearching() {
     gSearchView = gDebugger.DebuggerView.GlobalSearch;
     gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
 
     doSearch();
   });
 }
 
 function doSearch() {
-  window.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
@@ -89,18 +89,18 @@ function doSearch() {
     }
   });
   executeSoon(function() {
     write("!eval");
   });
 }
 
 function testSearchMatchNotFound() {
-  window.addEventListener("Debugger:GlobalSearch:MatchNotFound", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:GlobalSearch:MatchNotFound", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
@@ -127,17 +127,17 @@ function write(text) {
   clear();
   append(text);
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
   info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
--- a/browser/devtools/debugger/test/browser_dbg_scripts-searching-07.js
+++ b/browser/devtools/debugger/test/browser_dbg_scripts-searching-07.js
@@ -26,33 +26,33 @@ function test()
 
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     gDebugger.SourceResults.prototype.alwaysExpand = false;
 
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+      let url = aEvent.detail.url;
+      if (url.indexOf("-02.js") != -1) {
+        scriptShown = true;
+        gDebugger.removeEventListener(aEvent.type, _onEvent);
+        runTest();
+      }
+    });
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       runTest();
     });
 
     gDebuggee.firstCall();
   });
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    let url = aEvent.detail.url;
-    if (url.indexOf("-02.js") != -1) {
-      scriptShown = true;
-      window.removeEventListener(aEvent.type, _onEvent);
-      runTest();
-    }
-  });
-
   function runTest()
   {
     if (scriptShown && framesAdded) {
       Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
     }
   }
 }
 
@@ -63,18 +63,18 @@ function testScriptSearching() {
     gSearchView = gDebugger.DebuggerView.GlobalSearch;
     gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
 
     doSearch();
   });
 }
 
 function doSearch() {
-  window.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         continueTest();
       });
@@ -165,18 +165,18 @@ function testClickLineToJump(scriptResul
   let targetResults = scriptResults[0];
   let firstHeader = targetResults.querySelector(".dbg-results-header");
   let firstHeaderItem = gDebugger.SourceResults.getItemForElement(firstHeader);
   firstHeaderItem.instance.expand()
 
   is(firstHeaderItem.instance.expanded, true,
     "The first script results should be expanded after direct function call.");
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + aEvent.detail.url + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = aEvent.detail.url;
     if (url.indexOf("-01.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 0 &&
@@ -200,18 +200,18 @@ function testClickMatchToJump(scriptResu
   let targetResults = scriptResults[1];
   let secondHeader = targetResults.querySelector(".dbg-results-header");
   let secondHeaderItem = gDebugger.SourceResults.getItemForElement(secondHeader);
   secondHeaderItem.instance.expand()
 
   is(secondHeaderItem.instance.expanded, true,
     "The second script results should be expanded after direct function call.");
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + aEvent.detail.url + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = aEvent.detail.url;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 5 &&
@@ -241,17 +241,17 @@ function write(text) {
   clear();
   append(text);
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
   info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
--- a/browser/devtools/debugger/test/browser_dbg_scripts-searching-08.js
+++ b/browser/devtools/debugger/test/browser_dbg_scripts-searching-08.js
@@ -25,33 +25,33 @@ function test()
 
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     gDebugger.SourceResults.prototype.alwaysExpand = false;
 
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+      let url = aEvent.detail.url;
+      if (url.indexOf("-02.js") != -1) {
+        scriptShown = true;
+        gDebugger.removeEventListener(aEvent.type, _onEvent);
+        runTest();
+      }
+    });
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       runTest();
     });
 
     gDebuggee.firstCall();
   });
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    let url = aEvent.detail.url;
-    if (url.indexOf("-02.js") != -1) {
-      scriptShown = true;
-      window.removeEventListener(aEvent.type, _onEvent);
-      runTest();
-    }
-  });
-
   function runTest()
   {
     if (scriptShown && framesAdded) {
       Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
     }
   }
 }
 
@@ -65,18 +65,18 @@ function testScriptSearching() {
     doSearch();
   });
 }
 
 function doSearch() {
   is(gSearchView._container._parent.hidden, true,
     "The global search pane shouldn't be visible yet.");
 
-  window.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         testFocusLost();
       });
@@ -89,18 +89,18 @@ function doSearch() {
   });
 }
 
 function testFocusLost()
 {
   is(gSearchView._container._parent.hidden, false,
     "The global search pane should be visible after a search.");
 
-  window.addEventListener("Debugger:GlobalSearch:ViewCleared", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:GlobalSearch:ViewCleared", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         reshowSearch();
       });
@@ -112,18 +112,18 @@ function testFocusLost()
     gDebugger.DebuggerView.editor.focus();
   });
 }
 
 function reshowSearch() {
   is(gSearchView._container._parent.hidden, true,
     "The global search pane shouldn't be visible after the search was stopped.");
 
-  window.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         testEscape();
       });
@@ -136,18 +136,18 @@ function reshowSearch() {
   });
 }
 
 function testEscape()
 {
   is(gSearchView._container._parent.hidden, false,
     "The global search pane should be visible after a re-search.");
 
-  window.addEventListener("Debugger:GlobalSearch:ViewCleared", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("Debugger:GlobalSearch:ViewCleared", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("-02.js") != -1) {
       executeSoon(function() {
         finalCheck();
       });
@@ -175,29 +175,29 @@ function clear() {
 
 function write(text) {
   clear();
   append(text);
 }
 
 function sendEnter() {
   gSearchBox.focus();
-  EventUtils.sendKey("ENTER");
+  EventUtils.sendKey("ENTER", gDebugger);
 }
 
 function sendEscape() {
   gSearchBox.focus();
-  EventUtils.sendKey("ESCAPE");
+  EventUtils.sendKey("ESCAPE", gDebugger);
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
   info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
--- a/browser/devtools/debugger/test/browser_dbg_scripts-searching-files_ui.js
+++ b/browser/devtools/debugger/test/browser_dbg_scripts-searching-files_ui.js
@@ -20,37 +20,38 @@ var gMenulist = null;
 
 function test()
 {
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
+
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
+      Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
+    });
   });
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
-    Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
-  });
 }
 
 function testScriptSearching() {
   gEditor = gDebugger.DebuggerView.editor;
   gScripts = gDebugger.DebuggerView.Sources;
   gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
   gFilteredSources = gDebugger.DebuggerView.FilteredSources;
   gMenulist = gScripts._container;
 
   firstSearch();
 }
 
 function firstSearch() {
-  window.addEventListener("popupshown", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("popupshown", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     is(gFilteredSources.totalItems, 3,
       "The filtered sources view should have 3 items available.");
     is(gFilteredSources.visibleItems.length, 3,
       "The filtered sources view should have 3 items visible.");
 
@@ -102,23 +103,23 @@ function firstSearch() {
   write(".");
 }
 
 function secondSearch() {
   let sourceshown = false;
   let popupshown = false;
   let proceeded = false;
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent1(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent1);
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent1(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent1);
     sourceshown = true;
     executeSoon(proceed);
   });
-  window.addEventListener("popupshown", function _onEvent2(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent2);
+  gDebugger.addEventListener("popupshown", function _onEvent2(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent2);
     popupshown = true;
     executeSoon(proceed);
   });
 
   function proceed() {
     if (!sourceshown || !popupshown || proceeded) {
       return;
     }
@@ -179,23 +180,23 @@ function secondSearch() {
   append("-0")
 }
 
 function thirdSearch() {
   let sourceshown = false;
   let popupshown = false;
   let proceeded = false;
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent1(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent1);
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent1(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent1);
     sourceshown = true;
     executeSoon(proceed);
   });
-  window.addEventListener("popupshown", function _onEvent2(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent2);
+  gDebugger.addEventListener("popupshown", function _onEvent2(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent2);
     popupshown = true;
     executeSoon(proceed);
   });
 
   function proceed() {
     if (!sourceshown || !popupshown || proceeded) {
       return;
     }
@@ -252,17 +253,17 @@ function thirdSearch() {
     } else {
       ok(false, "How did you get here?");
     }
   }
   backspace(1)
 }
 
 function goDown() {
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     is(gFilteredSources.totalItems, 3,
       "The filtered sources view should have 3 items available.");
     is(gFilteredSources.visibleItems.length, 3,
       "The filtered sources view should have 3 items visible.");
 
@@ -270,37 +271,37 @@ function goDown() {
        gDebugger.SourceUtils.trimUrlLength(gScripts.selectedValue),
       "The correct item should be selected in the filtered sources view");
     is(gFilteredSources.selectedLabel,
        gDebugger.SourceUtils.trimUrlLength(gScripts.selectedLabel),
       "The correct item should be selected in the filtered sources view");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("test-editor-mode") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
 
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 0 &&
            gEditor.getCaretPosition().col == 0,
           "The editor didn't jump to the correct line.");
         is(gScripts.visibleItems.length, 3,
           "Not all the correct scripts are shown after the search.");
 
         goDownAgain();
       });
     } else {
       ok(false, "How did you get here?");
     }
   });
-  EventUtils.sendKey("DOWN");
+  EventUtils.sendKey("DOWN", gDebugger);
 }
 
 function goDownAgain() {
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     is(gFilteredSources.totalItems, 3,
       "The filtered sources view should have 3 items available.");
     is(gFilteredSources.visibleItems.length, 3,
       "The filtered sources view should have 3 items visible.");
 
@@ -308,37 +309,37 @@ function goDownAgain() {
        gDebugger.SourceUtils.trimUrlLength(gScripts.selectedValue),
       "The correct item should be selected in the filtered sources view");
     is(gFilteredSources.selectedLabel,
        gDebugger.SourceUtils.trimUrlLength(gScripts.selectedLabel),
       "The correct item should be selected in the filtered sources view");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("test-script-switching-01.js") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
 
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 0 &&
            gEditor.getCaretPosition().col == 0,
           "The editor didn't jump to the correct line.");
         is(gScripts.visibleItems.length, 3,
           "Not all the correct scripts are shown after the search.");
 
         goDownAndWrap();
       });
     } else {
       ok(false, "How did you get here?");
     }
   });
-  EventUtils.synthesizeKey("g", { metaKey: true });
+  EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger);
 }
 
 function goDownAndWrap() {
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     is(gFilteredSources.totalItems, 3,
       "The filtered sources view should have 3 items available.");
     is(gFilteredSources.visibleItems.length, 3,
       "The filtered sources view should have 3 items visible.");
 
@@ -346,37 +347,37 @@ function goDownAndWrap() {
        gDebugger.SourceUtils.trimUrlLength(gScripts.selectedValue),
       "The correct item should be selected in the filtered sources view");
     is(gFilteredSources.selectedLabel,
        gDebugger.SourceUtils.trimUrlLength(gScripts.selectedLabel),
       "The correct item should be selected in the filtered sources view");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("update-editor-mode.html") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
 
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 0 &&
            gEditor.getCaretPosition().col == 0,
           "The editor didn't jump to the correct line.");
         is(gScripts.visibleItems.length, 3,
           "Not all the correct scripts are shown after the search.");
 
         goUpAndWrap();
       });
     } else {
       ok(false, "How did you get here?");
     }
   });
-  EventUtils.synthesizeKey("n", { ctrlKey: true });
+  EventUtils.synthesizeKey("n", { ctrlKey: true }, gDebugger);
 }
 
 function goUpAndWrap() {
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     is(gFilteredSources.totalItems, 3,
       "The filtered sources view should have 3 items available.");
     is(gFilteredSources.visibleItems.length, 3,
       "The filtered sources view should have 3 items visible.");
 
@@ -384,37 +385,37 @@ function goUpAndWrap() {
        gDebugger.SourceUtils.trimUrlLength(gScripts.selectedValue),
       "The correct item should be selected in the filtered sources view");
     is(gFilteredSources.selectedLabel,
        gDebugger.SourceUtils.trimUrlLength(gScripts.selectedLabel),
       "The correct item should be selected in the filtered sources view");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("test-script-switching-01.js") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
 
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 0 &&
            gEditor.getCaretPosition().col == 0,
           "The editor didn't jump to the correct line.");
         is(gScripts.visibleItems.length, 3,
           "Not all the correct scripts are shown after the search.");
 
         clickAndSwitch();
       });
     } else {
       ok(false, "How did you get here?");
     }
   });
-  EventUtils.sendKey("UP");
+  EventUtils.sendKey("UP", gDebugger);
 }
 
 function clickAndSwitch() {
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     is(gFilteredSources.totalItems, 3,
       "The filtered sources view should have 3 items available.");
     is(gFilteredSources.visibleItems.length, 3,
       "The filtered sources view should have 3 items visible.");
 
@@ -422,17 +423,17 @@ function clickAndSwitch() {
        gDebugger.SourceUtils.trimUrlLength(gScripts.selectedValue),
       "The correct item should be selected in the filtered sources view");
     is(gFilteredSources.selectedLabel,
        gDebugger.SourceUtils.trimUrlLength(gScripts.selectedLabel),
       "The correct item should be selected in the filtered sources view");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("update-editor-mode.html") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
 
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 0 &&
            gEditor.getCaretPosition().col == 0,
           "The editor didn't jump to the correct line.");
         is(gScripts.visibleItems.length, 3,
           "Not all the correct scripts are shown after the search.");
@@ -442,17 +443,17 @@ function clickAndSwitch() {
     } else {
       ok(false, "How did you get here?");
     }
   });
   EventUtils.sendMouseEvent({ type: "click" }, gFilteredSources.visibleItems[0].target);
 }
 
 function clickAndSwitchAgain() {
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     is(gFilteredSources.totalItems, 3,
       "The filtered sources view should have 3 items available.");
     is(gFilteredSources.visibleItems.length, 3,
       "The filtered sources view should have 3 items visible.");
 
@@ -460,17 +461,17 @@ function clickAndSwitchAgain() {
        gDebugger.SourceUtils.trimUrlLength(gScripts.selectedValue),
       "The correct item should be selected in the filtered sources view");
     is(gFilteredSources.selectedLabel,
        gDebugger.SourceUtils.trimUrlLength(gScripts.selectedLabel),
       "The correct item should be selected in the filtered sources view");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("test-script-switching-01.js") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
 
       executeSoon(function() {
         info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
         ok(gEditor.getCaretPosition().line == 0 &&
            gEditor.getCaretPosition().col == 0,
           "The editor didn't jump to the correct line.");
         is(gScripts.visibleItems.length, 3,
           "Not all the correct scripts are shown after the search.");
@@ -480,18 +481,18 @@ function clickAndSwitchAgain() {
     } else {
       ok(false, "How did you get here?");
     }
   });
   EventUtils.sendMouseEvent({ type: "click" }, gFilteredSources.visibleItems[2].target);
 }
 
 function switchFocusWithEscape() {
-  window.addEventListener("popuphidden", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("popuphidden", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
 
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("test-script-switching-01.js") != -1) {
 
       executeSoon(function() {
@@ -503,22 +504,22 @@ function switchFocusWithEscape() {
           "Not all the correct scripts are shown after the search.");
 
         focusAgainAfterEscape();
       });
     } else {
       ok(false, "How did you get here?");
     }
   });
-  EventUtils.sendKey("ESCAPE");
+  EventUtils.sendKey("ESCAPE", gDebugger);
 }
 
 function focusAgainAfterEscape() {
-  window.addEventListener("popupshown", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("popupshown", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
 
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("test-script-switching-01.js") != -1) {
 
       executeSoon(function() {
@@ -534,18 +535,18 @@ function focusAgainAfterEscape() {
     } else {
       ok(false, "How did you get here?");
     }
   });
   append("0");
 }
 
 function switchFocusWithReturn() {
-  window.addEventListener("popuphidden", function _onEvent(aEvent) {
-    window.removeEventListener(aEvent.type, _onEvent);
+  gDebugger.addEventListener("popuphidden", function _onEvent(aEvent) {
+    gDebugger.removeEventListener(aEvent.type, _onEvent);
 
     info("Current script url:\n" + gScripts.selectedValue + "\n");
     info("Debugger editor text:\n" + gEditor.getText() + "\n");
 
     let url = gScripts.selectedValue;
     if (url.indexOf("test-script-switching-01.js") != -1) {
 
       executeSoon(function() {
@@ -557,40 +558,40 @@ function switchFocusWithReturn() {
           "Not all the correct scripts are shown after the search.");
 
         closeDebuggerAndFinish();
       });
     } else {
       ok(false, "How did you get here?");
     }
   });
-  EventUtils.sendKey("RETURN");
+  EventUtils.sendKey("RETURN", gDebugger);
 }
 
 function clear() {
   gSearchBox.focus();
   gSearchBox.value = "";
 }
 
 function write(text) {
   clear();
   append(text);
 }
 
 function backspace(times) {
   for (let i = 0; i < times; i++) {
-    EventUtils.sendKey("BACK_SPACE")
+    EventUtils.sendKey("BACK_SPACE", gDebugger);
   }
 }
 
 function append(text) {
   gSearchBox.focus();
 
   for (let i = 0; i < text.length; i++) {
-    EventUtils.sendChar(text[i]);
+    EventUtils.sendChar(text[i], gDebugger);
   }
   info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
 }
 
 registerCleanupFunction(function() {
   removeTab(gTab);
   gPane = null;
   gTab = null;
--- a/browser/devtools/debugger/test/browser_dbg_stack-05.js
+++ b/browser/devtools/debugger/test/browser_dbg_stack-05.js
@@ -19,33 +19,33 @@ function test() {
   let framesAdded = false;
 
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
 
+    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+      let url = aEvent.detail.url;
+      if (url.indexOf("-02.js") != -1) {
+        scriptShown = true;
+        gDebugger.removeEventListener(aEvent.type, _onEvent);
+        runTest();
+      }
+    });
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       runTest();
     });
 
     gDebuggee.firstCall();
   });
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
-    let url = aEvent.detail.url;
-    if (url.indexOf("-02.js") != -1) {
-      scriptShown = true;
-      window.removeEventListener(aEvent.type, _onEvent);
-      runTest();
-    }
-  });
-
   function runTest()
   {
     if (scriptShown && framesAdded) {
       Services.tm.currentThread.dispatch({ run: testRecurse }, 0);
     }
   }
 }
 
--- a/browser/devtools/debugger/test/browser_dbg_update-editor-mode.js
+++ b/browser/devtools/debugger/test/browser_dbg_update-editor-mode.js
@@ -28,37 +28,37 @@ function test()
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.panelWin;
     gScripts = gDebugger.DebuggerView.Sources._container;
     resumed = true;
 
+    gDebugger.addEventListener("Debugger:SourceShown", onScriptShown);
+
     gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
       framesAdded = true;
       executeSoon(startTest);
     });
 
     executeSoon(function() {
       gDebuggee.firstCall();
     });
   });
 
   function onScriptShown(aEvent) {
     scriptShown = aEvent.detail.url.indexOf("test-editor-mode") != -1;
     executeSoon(startTest);
   }
 
-  window.addEventListener("Debugger:SourceShown", onScriptShown);
-
   function startTest()
   {
     if (scriptShown && framesAdded && resumed && !testStarted) {
-      window.removeEventListener("Debugger:SourceShown", onScriptShown);
+      gDebugger.removeEventListener("Debugger:SourceShown", onScriptShown);
       testStarted = true;
       Services.tm.currentThread.dispatch({ run: testScriptsDisplay }, 0);
     }
   }
 }
 
 function testScriptsDisplay() {
   is(gDebugger.DebuggerController.activeThread.state, "paused",
@@ -68,20 +68,20 @@ function testScriptsDisplay() {
     "Found the expected number of scripts.");
 
   is(gDebugger.editor.getMode(), SourceEditor.MODES.TEXT,
      "Found the expected editor mode.");
 
   ok(gDebugger.editor.getText().search(/debugger/) != -1,
     "The correct script was loaded initially.");
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     let url = aEvent.detail.url;
     if (url.indexOf("switching-01.js") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
       testSwitchPaused1();
     }
   });
 
   let url = gDebuggee.document.querySelector("script").src;
   gDebugger.DebuggerView.Sources.selectedValue = url;
 }
 
@@ -97,20 +97,20 @@ function testSwitchPaused1()
     "The second script is no longer displayed.");
 
   ok(gDebugger.editor.getText().search(/firstCall/) != -1,
     "The first script is displayed.");
 
   is(gDebugger.editor.getMode(), SourceEditor.MODES.JAVASCRIPT,
      "Found the expected editor mode.");
 
-  window.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
+  gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
     let url = aEvent.detail.url;
     if (url.indexOf("update-editor-mode") != -1) {
-      window.removeEventListener(aEvent.type, _onEvent);
+      gDebugger.removeEventListener(aEvent.type, _onEvent);
       testSwitchPaused2();
     }
   });
 
   let label = "browser_dbg_update-editor-mode.html";
   gDebugger.DebuggerView.Sources.selectedLabel = label;
 }