Bug 967873 - Fix some recently enabled tests
authorBill McCloskey <billm@mozilla.com>
Sun, 08 Nov 2015 21:50:10 -0800
changeset 272159 2f3625e34e063228a65439ac388f10a71cba9b1f
parent 272158 b0d7da69ec7b293088fb06c78b7f8a0fef791283
child 272160 cdb6a1c38b89dd372111e2097a49553fc5f3279a
push id67896
push userwmccloskey@mozilla.com
push dateThu, 12 Nov 2015 00:24:39 +0000
treeherdermozilla-inbound@2f3625e34e06 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs967873
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 967873 - Fix some recently enabled tests
docshell/test/browser/browser_bug134911.js
docshell/test/browser/browser_bug234628-1.js
docshell/test/browser/browser_bug234628-10.js
docshell/test/browser/browser_bug234628-11.js
docshell/test/browser/browser_bug234628-2.js
docshell/test/browser/browser_bug234628-3.js
docshell/test/browser/browser_bug234628-4.js
docshell/test/browser/browser_bug234628-5.js
docshell/test/browser/browser_bug234628-6.js
docshell/test/browser/browser_bug234628-7.js
docshell/test/browser/browser_bug234628-8.js
docshell/test/browser/browser_bug234628-9.js
docshell/test/browser/browser_bug673467.js
docshell/test/browser/browser_bug852909.js
docshell/test/browser/browser_bug92473.js
docshell/test/browser/head.js
toolkit/mozapps/extensions/test/browser/browser_globalinformations.js
toolkit/mozapps/extensions/test/browser/browser_purchase.js
--- a/docshell/test/browser/browser_bug134911.js
+++ b/docshell/test/browser/browser_bug134911.js
@@ -1,38 +1,41 @@
-/* The test text decoded correctly as Shift_JIS */
-const rightText="\u30E6\u30CB\u30B3\u30FC\u30C9\u306F\u3001\u3059\u3079\u3066\u306E\u6587\u5B57\u306B\u56FA\u6709\u306E\u756A\u53F7\u3092\u4ED8\u4E0E\u3057\u307E\u3059";
+const TEXT = {
+  /* The test text decoded correctly as Shift_JIS */
+  rightText: "\u30E6\u30CB\u30B3\u30FC\u30C9\u306F\u3001\u3059\u3079\u3066\u306E\u6587\u5B57\u306B\u56FA\u6709\u306E\u756A\u53F7\u3092\u4ED8\u4E0E\u3057\u307E\u3059",
 
-const enteredText1="The quick brown fox jumps over the lazy dog";
-const enteredText2="\u03BE\u03B5\u03C3\u03BA\u03B5\u03C0\u03AC\u03B6\u03C9\u0020\u03C4\u1F74\u03BD\u0020\u03C8\u03C5\u03C7\u03BF\u03C6\u03B8\u03CC\u03C1\u03B1\u0020\u03B2\u03B4\u03B5\u03BB\u03C5\u03B3\u03BC\u03AF\u03B1";
+  enteredText1: "The quick brown fox jumps over the lazy dog",
+  enteredText2: "\u03BE\u03B5\u03C3\u03BA\u03B5\u03C0\u03AC\u03B6\u03C9\u0020\u03C4\u1F74\u03BD\u0020\u03C8\u03C5\u03C7\u03BF\u03C6\u03B8\u03CC\u03C1\u03B1\u0020\u03B2\u03B4\u03B5\u03BB\u03C5\u03B3\u03BC\u03AF\u03B1",
+};
 
 function test() {
   waitForExplicitFinish();
 
   var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
   gBrowser.selectedTab = gBrowser.addTab(rootDir + "test-form_sjis.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(afterOpen);
 }
 
 function afterOpen() {
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
-  gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true);
+  BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(afterChangeCharset);
 
-  gBrowser.contentDocument.getElementById("testtextarea").value = enteredText1;
-  gBrowser.contentDocument.getElementById("testinput").value = enteredText2;
+  ContentTask.spawn(gBrowser.selectedBrowser, TEXT, function(TEXT) {
+    content.document.getElementById("testtextarea").value = TEXT.enteredText1;
+    content.document.getElementById("testinput").value = TEXT.enteredText2;
+  }).then(() => {
+    /* Force the page encoding to Shift_JIS */
+    BrowserSetForcedCharacterSet("Shift_JIS");
+  });
+}
 
-  /* Force the page encoding to Shift_JIS */
-  BrowserSetForcedCharacterSet("Shift_JIS");
-}
-  
 function afterChangeCharset() {
-  gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true);
-
-  is(gBrowser.contentDocument.getElementById("testpar").innerHTML, rightText,
-     "encoding successfully changed");
-  is(gBrowser.contentDocument.getElementById("testtextarea").value, enteredText1,
-     "text preserved in <textarea>");
-  is(gBrowser.contentDocument.getElementById("testinput").value, enteredText2,
-     "text preserved in <input>");
-
-  gBrowser.removeCurrentTab();
-  finish();
+  ContentTask.spawn(gBrowser.selectedBrowser, TEXT, function(TEXT) {
+    is(content.document.getElementById("testpar").innerHTML, TEXT.rightText,
+       "encoding successfully changed");
+    is(content.document.getElementById("testtextarea").value, TEXT.enteredText1,
+       "text preserved in <textarea>");
+    is(content.document.getElementById("testinput").value, TEXT.enteredText2,
+       "text preserved in <input>");
+  }).then(() => {
+    gBrowser.removeCurrentTab();
+    finish();
+  });
 }
--- a/docshell/test/browser/browser_bug234628-1.js
+++ b/docshell/test/browser/browser_bug234628-1.js
@@ -1,39 +1,18 @@
 function test() {
-  waitForExplicitFinish();
-
   var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
-  gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug234628-1.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  runCharsetTest(rootDir + "file_bug234628-1.html", afterOpen, "windows-1251", afterChangeCharset);
 }
 
-function afterOpen(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
+function afterOpen() {
+  is(content.document.documentElement.textContent.indexOf('\u20AC'), 129, "Parent doc should be windows-1252 initially");
 
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
-  gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true);
-
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u20AC'), 129, "Parent doc should be windows-1252 initially");
-
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 85, "Child doc should be windows-1252 initially");  
-
-  BrowserSetForcedCharacterSet("windows-1251");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 85, "Child doc should be windows-1252 initially");
 }
-  
-function afterChangeCharset(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-
-  gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true);
 
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u0402'), 129, "Parent doc should decode as windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u0402'), 85, "Child doc should decode as windows-1251 subsequently");  
+function afterChangeCharset() {
+  is(content.document.documentElement.textContent.indexOf('\u0402'), 129, "Parent doc should decode as windows-1251 subsequently");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u0402'), 85, "Child doc should decode as windows-1251 subsequently");
 
-  is(gBrowser.contentDocument.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.characterSet, "windows-1251", "Child doc should report windows-1251 subsequently");
-
-  gBrowser.removeCurrentTab();
-  finish();
+  is(content.document.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
+  is(content.frames[0].document.characterSet, "windows-1251", "Child doc should report windows-1251 subsequently");
 }
--- a/docshell/test/browser/browser_bug234628-10.js
+++ b/docshell/test/browser/browser_bug234628-10.js
@@ -1,39 +1,18 @@
 function test() {
-  waitForExplicitFinish();
-
   var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
-  gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug234628-10.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  runCharsetTest(rootDir + "file_bug234628-10.html", afterOpen, "windows-1251", afterChangeCharset);
 }
 
-function afterOpen(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
+function afterOpen() {
+  is(content.document.documentElement.textContent.indexOf('\u20AC'), 151, "Parent doc should be windows-1252 initially");
 
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
-  gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true);
-
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u20AC'), 151, "Parent doc should be windows-1252 initially");
-
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 71, "Child doc should be utf-8 initially");
-
-  BrowserSetForcedCharacterSet("windows-1251");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 71, "Child doc should be utf-8 initially");
 }
-  
-function afterChangeCharset(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-
-  gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true);
 
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u0402'), 151, "Parent doc should decode as windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 71, "Child doc should decode as utf-8 subsequently");  
+function afterChangeCharset() {
+  is(content.document.documentElement.textContent.indexOf('\u0402'), 151, "Parent doc should decode as windows-1251 subsequently");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 71, "Child doc should decode as utf-8 subsequently");
 
-  is(gBrowser.contentDocument.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.characterSet, "UTF-8", "Child doc should report UTF-8 subsequently");
-
-  gBrowser.removeCurrentTab();
-  finish();
+  is(content.document.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
+  is(content.frames[0].document.characterSet, "UTF-8", "Child doc should report UTF-8 subsequently");
 }
--- a/docshell/test/browser/browser_bug234628-11.js
+++ b/docshell/test/browser/browser_bug234628-11.js
@@ -1,39 +1,18 @@
 function test() {
-  waitForExplicitFinish();
-
   var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
-  gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug234628-11.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  runCharsetTest(rootDir + "file_bug234628-11.html", afterOpen, "windows-1251", afterChangeCharset);
 }
 
-function afterOpen(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
+function afterOpen() {
+  is(content.document.documentElement.textContent.indexOf('\u20AC'), 193, "Parent doc should be windows-1252 initially");
 
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
-  gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true);
-
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u20AC'), 193, "Parent doc should be windows-1252 initially");
-
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 107, "Child doc should be utf-8 initially");
-
-  BrowserSetForcedCharacterSet("windows-1251");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 107, "Child doc should be utf-8 initially");
 }
-  
-function afterChangeCharset(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-
-  gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true);
 
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u0402'), 193, "Parent doc should decode as windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 107, "Child doc should decode as utf-8 subsequently");  
+function afterChangeCharset() {
+  is(content.document.documentElement.textContent.indexOf('\u0402'), 193, "Parent doc should decode as windows-1251 subsequently");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 107, "Child doc should decode as utf-8 subsequently");
 
-  is(gBrowser.contentDocument.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.characterSet, "UTF-8", "Child doc should report UTF-8 subsequently");
-
-  gBrowser.removeCurrentTab();
-  finish();
+  is(content.document.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
+  is(content.frames[0].document.characterSet, "UTF-8", "Child doc should report UTF-8 subsequently");
 }
--- a/docshell/test/browser/browser_bug234628-2.js
+++ b/docshell/test/browser/browser_bug234628-2.js
@@ -1,39 +1,18 @@
 function test() {
-  waitForExplicitFinish();
-
   var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
-  gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug234628-2.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  runCharsetTest(rootDir + "file_bug234628-2.html", afterOpen, "windows-1251", afterChangeCharset);
 }
 
-function afterOpen(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
+function afterOpen() {
+  is(content.document.documentElement.textContent.indexOf('\u20AC'), 129, "Parent doc should be windows-1252 initially");
 
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
-  gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true);
-
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u20AC'), 129, "Parent doc should be windows-1252 initially");
-
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u00E2\u201A\u00AC'), 78, "Child doc should be windows-1252 initially");  
-
-  BrowserSetForcedCharacterSet("windows-1251");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u00E2\u201A\u00AC'), 78, "Child doc should be windows-1252 initially");
 }
-  
-function afterChangeCharset(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-
-  gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true);
 
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u0402'), 129, "Parent doc should decode as windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u0432\u201A\u00AC'), 78, "Child doc should decode as windows-1251 subsequently");  
+function afterChangeCharset() {
+  is(content.document.documentElement.textContent.indexOf('\u0402'), 129, "Parent doc should decode as windows-1251 subsequently");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u0432\u201A\u00AC'), 78, "Child doc should decode as windows-1251 subsequently");
 
-  is(gBrowser.contentDocument.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.characterSet, "windows-1251", "Child doc should report windows-1251 subsequently");
-
-  gBrowser.removeCurrentTab();
-  finish();
+  is(content.document.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
+  is(content.frames[0].document.characterSet, "windows-1251", "Child doc should report windows-1251 subsequently");
 }
--- a/docshell/test/browser/browser_bug234628-3.js
+++ b/docshell/test/browser/browser_bug234628-3.js
@@ -1,39 +1,18 @@
 function test() {
-  waitForExplicitFinish();
-
   var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
-  gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug234628-3.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  runCharsetTest(rootDir + "file_bug234628-3.html", afterOpen, "windows-1251", afterChangeCharset);
 }
 
-function afterOpen(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
+function afterOpen() {
+  is(content.document.documentElement.textContent.indexOf('\u20AC'), 118, "Parent doc should be windows-1252 initially");
 
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
-  gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true);
-
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u20AC'), 118, "Parent doc should be windows-1252 initially");
-
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 73, "Child doc should be utf-8 initially");
-
-  BrowserSetForcedCharacterSet("windows-1251");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 73, "Child doc should be utf-8 initially");
 }
-  
-function afterChangeCharset(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-
-  gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true);
 
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u0402'), 118, "Parent doc should decode as windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u0432\u201A\u00AC'), 73, "Child doc should decode as windows-1251 subsequently");  
+function afterChangeCharset() {
+  is(content.document.documentElement.textContent.indexOf('\u0402'), 118, "Parent doc should decode as windows-1251 subsequently");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u0432\u201A\u00AC'), 73, "Child doc should decode as windows-1251 subsequently");
 
-  is(gBrowser.contentDocument.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.characterSet, "windows-1251", "Child doc should report windows-1251 subsequently");
-
-  gBrowser.removeCurrentTab();
-  finish();
+  is(content.document.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
+  is(content.frames[0].document.characterSet, "windows-1251", "Child doc should report windows-1251 subsequently");
 }
--- a/docshell/test/browser/browser_bug234628-4.js
+++ b/docshell/test/browser/browser_bug234628-4.js
@@ -1,39 +1,18 @@
 function test() {
-  waitForExplicitFinish();
-
   var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
-  gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug234628-4.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  runCharsetTest(rootDir + "file_bug234628-4.html", afterOpen, "windows-1251", afterChangeCharset);
 }
 
-function afterOpen(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
+function afterOpen() {
+  is(content.document.documentElement.textContent.indexOf('\u20AC'), 132, "Parent doc should be windows-1252 initially");
 
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
-  gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true);
-
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u20AC'), 132, "Parent doc should be windows-1252 initially");
-
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 79, "Child doc should be utf-8 initially");
-
-  BrowserSetForcedCharacterSet("windows-1251");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 79, "Child doc should be utf-8 initially");
 }
-  
-function afterChangeCharset(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-
-  gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true);
 
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u0402'), 132, "Parent doc should decode as windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 79, "Child doc should decode as utf-8 subsequently");  
+function afterChangeCharset() {
+  is(content.document.documentElement.textContent.indexOf('\u0402'), 132, "Parent doc should decode as windows-1251 subsequently");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 79, "Child doc should decode as utf-8 subsequently");
 
-  is(gBrowser.contentDocument.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.characterSet, "UTF-8", "Child doc should report UTF-8 subsequently");
-
-  gBrowser.removeCurrentTab();
-  finish();
+  is(content.document.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
+  is(content.frames[0].document.characterSet, "UTF-8", "Child doc should report UTF-8 subsequently");
 }
--- a/docshell/test/browser/browser_bug234628-5.js
+++ b/docshell/test/browser/browser_bug234628-5.js
@@ -1,39 +1,18 @@
 function test() {
-  waitForExplicitFinish();
-
   var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
-  gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug234628-5.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  runCharsetTest(rootDir + "file_bug234628-5.html", afterOpen, "windows-1251", afterChangeCharset);
 }
 
-function afterOpen(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
+function afterOpen() {
+  is(content.document.documentElement.textContent.indexOf('\u20AC'), 146, "Parent doc should be windows-1252 initially");
 
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
-  gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true);
-
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u20AC'), 146, "Parent doc should be windows-1252 initially");
-
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 87, "Child doc should be utf-16 initially");
-
-  BrowserSetForcedCharacterSet("windows-1251");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 87, "Child doc should be utf-16 initially");
 }
-  
-function afterChangeCharset(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-
-  gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true);
 
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u0402'), 146, "Parent doc should decode as windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 87, "Child doc should decode as utf-16 subsequently");  
+function afterChangeCharset() {
+  is(content.document.documentElement.textContent.indexOf('\u0402'), 146, "Parent doc should decode as windows-1251 subsequently");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 87, "Child doc should decode as utf-16 subsequently");
 
-  is(gBrowser.contentDocument.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.characterSet, "UTF-16LE", "Child doc should report UTF-16LE subsequently");
-
-  gBrowser.removeCurrentTab();
-  finish();
+  is(content.document.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
+  is(content.frames[0].document.characterSet, "UTF-16LE", "Child doc should report UTF-16LE subsequently");
 }
--- a/docshell/test/browser/browser_bug234628-6.js
+++ b/docshell/test/browser/browser_bug234628-6.js
@@ -1,39 +1,18 @@
 function test() {
-  waitForExplicitFinish();
-
   var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
-  gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug234628-6.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  runCharsetTest(rootDir + "file_bug234628-6.html", afterOpen, "windows-1251", afterChangeCharset);
 }
 
-function afterOpen(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
+function afterOpen() {
+  is(content.document.documentElement.textContent.indexOf('\u20AC'), 190, "Parent doc should be windows-1252 initially");
 
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
-  gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true);
-
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u20AC'), 190, "Parent doc should be windows-1252 initially");
-
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 109, "Child doc should be utf-16 initially");
-
-  BrowserSetForcedCharacterSet("windows-1251");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 109, "Child doc should be utf-16 initially");
 }
-  
-function afterChangeCharset(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-
-  gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true);
 
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u0402'), 190, "Parent doc should decode as windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 109, "Child doc should decode as utf-16 subsequently");  
+function afterChangeCharset() {
+  is(content.document.documentElement.textContent.indexOf('\u0402'), 190, "Parent doc should decode as windows-1251 subsequently");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 109, "Child doc should decode as utf-16 subsequently");
 
-  is(gBrowser.contentDocument.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.characterSet, "UTF-16BE", "Child doc should report UTF-16 subsequently");
-
-  gBrowser.removeCurrentTab();
-  finish();
+  is(content.document.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
+  is(content.frames[0].document.characterSet, "UTF-16BE", "Child doc should report UTF-16 subsequently");
 }
--- a/docshell/test/browser/browser_bug234628-7.js
+++ b/docshell/test/browser/browser_bug234628-7.js
@@ -1,39 +1,18 @@
 function test() {
-  waitForExplicitFinish();
-
   var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
-  gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug234628-7.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  runCharsetTest(rootDir + "file_bug234628-7.html", afterOpen, "windows-1251", afterChangeCharset);
 }
 
-function afterOpen(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
+function afterOpen() {
+  is(content.document.documentElement.textContent.indexOf('\u20AC'), 188, "Parent doc should be windows-1252 initially");
 
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
-  gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true);
-
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u20AC'), 188, "Parent doc should be windows-1252 initially");
-
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 107, "Child doc should be utf-8 initially");
-
-  BrowserSetForcedCharacterSet("windows-1251");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 107, "Child doc should be utf-8 initially");
 }
-  
-function afterChangeCharset(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-
-  gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true);
 
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u0402'), 188, "Parent doc should decode as windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u0432\u201A\u00AC'), 107, "Child doc should decode as windows-1251 subsequently");  
+function afterChangeCharset() {
+  is(content.document.documentElement.textContent.indexOf('\u0402'), 188, "Parent doc should decode as windows-1251 subsequently");
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u0432\u201A\u00AC'), 107, "Child doc should decode as windows-1251 subsequently");
 
-  is(gBrowser.contentDocument.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.characterSet, "windows-1251", "Child doc should report windows-1251 subsequently");
-
-  gBrowser.removeCurrentTab();
-  finish();
+  is(content.document.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
+  is(content.frames[0].document.characterSet, "windows-1251", "Child doc should report windows-1251 subsequently");
 }
--- a/docshell/test/browser/browser_bug234628-8.js
+++ b/docshell/test/browser/browser_bug234628-8.js
@@ -1,23 +1,11 @@
 function test() {
-  waitForExplicitFinish();
-
   var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
-  gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug234628-8.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  runCharsetTest(rootDir + "file_bug234628-8.html", afterOpen);
 }
 
-function afterOpen(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
+function afterOpen() {
+  is(content.document.documentElement.textContent.indexOf('\u0402'), 156, "Parent doc should be windows-1251");
 
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u0402'), 156, "Parent doc should be windows-1251");
-
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u0402'), 99, "Child doc should be windows-1251");
-
-  gBrowser.removeCurrentTab();
-  finish();
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u0402'), 99, "Child doc should be windows-1251");
 }
 
--- a/docshell/test/browser/browser_bug234628-9.js
+++ b/docshell/test/browser/browser_bug234628-9.js
@@ -1,23 +1,11 @@
 function test() {
-  waitForExplicitFinish();
-
   var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
-  gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug234628-9.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  runCharsetTest(rootDir + "file_bug234628-9.html", afterOpen);
 }
 
-function afterOpen(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
+function afterOpen() {
+  is(content.document.documentElement.textContent.indexOf('\u20AC'), 145, "Parent doc should be UTF-16");
 
-  is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u20AC'), 145, "Parent doc should be UTF-16");
-
-  is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u20AC'), 96, "Child doc should be windows-1252");
-
-  gBrowser.removeCurrentTab();
-  finish();
+  is(content.frames[0].document.documentElement.textContent.indexOf('\u20AC'), 96, "Child doc should be windows-1252");
 }
 
--- a/docshell/test/browser/browser_bug673467.js
+++ b/docshell/test/browser/browser_bug673467.js
@@ -17,33 +17,35 @@ var doc = "data:text/html,<html><body on
  "</body></html>"
 
 function test() {
   waitForExplicitFinish();
 
   let tab = gBrowser.addTab(doc);
   let tabBrowser = tab.linkedBrowser;
 
-  tabBrowser.addEventListener('load', function(aEvent) {
-    tabBrowser.removeEventListener('load', arguments.callee, true);
+  BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => {
+    return ContentTask.spawn(tab.linkedBrowser, null, () => {
+      return new Promise(resolve => {
+        // The main page has loaded.  Now wait for the iframe to load.
+        let iframe = content.document.getElementById('iframe');
+        iframe.addEventListener('load', function listener(aEvent) {
 
-    // The main page has loaded.  Now wait for the iframe to load.
-    let iframe = tabBrowser.contentWindow.document.getElementById('iframe');
-    iframe.addEventListener('load', function(aEvent) {
-
-      // Wait for the iframe to load the new document, not about:blank.
-      if (!iframe.src)
-        return;
+          // Wait for the iframe to load the new document, not about:blank.
+          if (!iframe.src)
+            return;
 
-      iframe.removeEventListener('load', arguments.callee, true);
-      let shistory = tabBrowser.contentWindow
-                      .QueryInterface(Ci.nsIInterfaceRequestor)
-                      .getInterface(Ci.nsIWebNavigation)
-                      .sessionHistory;
+          iframe.removeEventListener('load', listener, true);
+          let shistory = content
+                          .QueryInterface(Ci.nsIInterfaceRequestor)
+                          .getInterface(Ci.nsIWebNavigation)
+                          .sessionHistory;
 
-      is(shistory.count, 1, 'shistory count should be 1.');
-
-      gBrowser.removeTab(tab);
-      finish();
-
-    }, true);
-  }, true);
+          is(shistory.count, 1, 'shistory count should be 1.');
+          resolve();
+        }, true);
+      });
+    });
+  }).then(() => {
+    gBrowser.removeTab(tab);
+    finish();
+  });
 }
--- a/docshell/test/browser/browser_bug852909.js
+++ b/docshell/test/browser/browser_bug852909.js
@@ -1,33 +1,23 @@
 var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
 
 function test() {
   waitForExplicitFinish();
 
   gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug852909.png");
-  gBrowser.selectedBrowser.addEventListener("load", image, true);
+  BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(image);
 }
 
 function image(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-  gBrowser.selectedBrowser.removeEventListener("load", image, true);
-
   ok(!gBrowser.selectedTab.mayEnableCharacterEncodingMenu, "Docshell should say the menu should be disabled for images.");
 
   gBrowser.removeCurrentTab();
   gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug852909.pdf");
-  gBrowser.selectedBrowser.addEventListener("load", pdf, true);
+  BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(pdf);
 }
 
 function pdf(event) {
-  if (event.target != gBrowser.contentDocument) {
-    return;
-  }
-  gBrowser.selectedBrowser.removeEventListener("load", pdf, true);
-
   ok(!gBrowser.selectedTab.mayEnableCharacterEncodingMenu, "Docshell should say the menu should be disabled for PDF.js.");
 
   gBrowser.removeCurrentTab();
   finish();
 }
--- a/docshell/test/browser/browser_bug92473.js
+++ b/docshell/test/browser/browser_bug92473.js
@@ -1,55 +1,54 @@
 /* The test text as octets for reference
  * %83%86%83%6a%83%52%81%5b%83%68%82%cd%81%41%82%b7%82%d7%82%c4%82%cc%95%b6%8e%9a%82%c9%8c%c5%97%4c%82%cc%94%d4%8d%86%82%f0%95%74%97%5e%82%b5%82%dc%82%b7
  */
 
-/* The test text decoded correctly as Shift_JIS */
-const rightText="\u30E6\u30CB\u30B3\u30FC\u30C9\u306F\u3001\u3059\u3079\u3066\u306E\u6587\u5B57\u306B\u56FA\u6709\u306E\u756A\u53F7\u3092\u4ED8\u4E0E\u3057\u307E\u3059";
-
-/* The test text decoded incorrectly as Windows-1251. This is the "right" wrong
-   text; anything else is unexpected. */
-const wrongText="\u0453\u2020\u0453\u006A\u0453\u0052\u0403\u005B\u0453\u0068\u201A\u041D\u0403\u0041\u201A\u00B7\u201A\u0427\u201A\u0414\u201A\u041C\u2022\u00B6\u040B\u0459\u201A\u0419\u040A\u0415\u2014\u004C\u201A\u041C\u201D\u0424\u040C\u2020\u201A\u0440\u2022\u0074\u2014\u005E\u201A\u00B5\u201A\u042C\u201A\u00B7";
-
 function testContent(text) {
-  is(gBrowser.contentDocument.getElementById("testpar").innerHTML, text,
-     "<p> contains expected text");
-  is(gBrowser.contentDocument.getElementById("testtextarea").innerHTML, text,
-     "<textarea> contains expected text");
-  is(gBrowser.contentDocument.getElementById("testinput").value, text,
-     "<input> contains expected text");
+  return ContentTask.spawn(gBrowser.selectedBrowser, text, text => {
+    is(content.document.getElementById("testpar").innerHTML, text,
+       "<p> contains expected text");
+    is(content.document.getElementById("testtextarea").innerHTML, text,
+       "<textarea> contains expected text");
+    is(content.document.getElementById("testinput").value, text,
+       "<input> contains expected text");
+  });
 }
 
 function afterOpen() {
-  gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
-  gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true);
+  BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(afterChangeCharset);
+
+  /* The test text decoded incorrectly as Windows-1251. This is the "right" wrong
+   text; anything else is unexpected. */
+  const wrongText="\u0453\u2020\u0453\u006A\u0453\u0052\u0403\u005B\u0453\u0068\u201A\u041D\u0403\u0041\u201A\u00B7\u201A\u0427\u201A\u0414\u201A\u041C\u2022\u00B6\u040B\u0459\u201A\u0419\u040A\u0415\u2014\u004C\u201A\u041C\u201D\u0424\u040C\u2020\u201A\u0440\u2022\u0074\u2014\u005E\u201A\u00B5\u201A\u042C\u201A\u00B7";
 
   /* Test that the content on load is the expected wrong decoding */
-  testContent(wrongText);
+  testContent(wrongText).then(() => {
+    BrowserSetForcedCharacterSet("Shift_JIS");
+  });
+}
 
-  /* Force the page encoding to Shift_JIS */
-  BrowserSetForcedCharacterSet("Shift_JIS");
-}
-  
 function afterChangeCharset() {
-  gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true);
+  /* The test text decoded correctly as Shift_JIS */
+  const rightText="\u30E6\u30CB\u30B3\u30FC\u30C9\u306F\u3001\u3059\u3079\u3066\u306E\u6587\u5B57\u306B\u56FA\u6709\u306E\u756A\u53F7\u3092\u4ED8\u4E0E\u3057\u307E\u3059";
 
   /* test that the content is decoded correctly */
-  testContent(rightText);
-  gBrowser.removeCurrentTab();
-  finish();
+  testContent(rightText).then(() => {
+    gBrowser.removeCurrentTab();
+    finish();
+  });
 }
 
 function test() {
   waitForExplicitFinish();
 
   // Get the local directory. This needs to be a file: URI because chrome: URIs
   // are always UTF-8 (bug 617339) and we are testing decoding from other
   // charsets.
   var jar = getJar(getRootDirectory(gTestPath));
   var dir = jar ?
               extractJarToTmp(jar) :
               getChromeDir(getResolvedURI(gTestPath));
   var rootDir = Services.io.newFileURI(dir).spec;
 
   gBrowser.selectedTab = gBrowser.addTab(rootDir + "test-form_sjis.html");
-  gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
+  BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(afterOpen);
 }
--- a/docshell/test/browser/head.js
+++ b/docshell/test/browser/head.js
@@ -55,8 +55,45 @@ function timelineTestOpenUrl(url) {
     linkedBrowser.addEventListener("load", function onload() {
       linkedBrowser.removeEventListener("load", onload, true);
       resolve(tab);
     }, true);
   });
 
   return Promise.all([tabSwitchPromise, loadPromise]).then(([_, tab]) => tab);
 }
+
+/**
+ * Helper function for charset tests. It loads |url| in a new tab,
+ * runs |check1| in a ContentTask when the page is ready, switches the
+ * charset to |charset|, and then runs |check2| in a ContentTask when
+ * the page has finished reloading.
+ *
+ * |charset| and |check2| can be omitted, in which case the test
+ * finishes when |check1| completes.
+ */
+function runCharsetTest(url, check1, charset, check2) {
+  waitForExplicitFinish();
+
+  BrowserTestUtils.openNewForegroundTab(gBrowser, url, true).then(afterOpen);
+
+  function afterOpen() {
+    if (charset) {
+      BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(afterChangeCharset);
+
+      ContentTask.spawn(gBrowser.selectedBrowser, null, check1).then(() => {
+        BrowserSetForcedCharacterSet(charset);
+      });
+    } else {
+      ContentTask.spawn(gBrowser.selectedBrowser, null, check1).then(() => {
+        gBrowser.removeCurrentTab();
+        finish();
+      });
+    }
+  }
+
+  function afterChangeCharset() {
+    ContentTask.spawn(gBrowser.selectedBrowser, null, check2).then(() => {
+      gBrowser.removeCurrentTab();
+      finish();
+    });
+  }
+}
--- a/toolkit/mozapps/extensions/test/browser/browser_globalinformations.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_globalinformations.js
@@ -32,24 +32,22 @@ add_test(function() {
     EventUtils.synthesizeMouseAtCenter(aManager.document.getElementById("category-plugin"), { }, aManager);
 
     wait_for_view_load(aManager, function(aManager) {
       var button = aManager.document.querySelector("#list-view button.global-info-plugincheck");
       is_element_visible(button, "Plugin Check message button should be visible");
 
       info("Clicking 'Plugin Check' button");
       EventUtils.synthesizeMouseAtCenter(button, { }, aManager);
-      gBrowser.addEventListener("load", function(event) {
-        if (!(event.target instanceof Document) ||
-            event.target.location.href == "about:blank")
-          return;
-        gBrowser.removeEventListener("load", arguments.callee, true);
-
+      function wantLoad(url) {
+        return url != "about:blank";
+      }
+      BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, wantLoad).then(() => {
         is(gBrowser.currentURI.spec, Services.urlFormatter.formatURLPref("plugins.update.url"), "Plugin Check URL should match");
 
         gBrowser.removeCurrentTab();
         close_manager(aManager, function() {
           run_next_test();
         });
-      }, true);
+      });
     });
   });
-});
\ No newline at end of file
+});
--- a/toolkit/mozapps/extensions/test/browser/browser_purchase.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_purchase.js
@@ -131,58 +131,60 @@ add_test(function() {
   is(get_node(items[3], "name").value, "Cheap Add-on", "Add-on 3 should be in expected position");
   is(get_node(items[4], "name").value, "Free Add-on", "Add-on 4 should be in expected position");
 
   run_next_test();
 });
 
 // Tests that clicking the buy button works from the list
 add_test(function() {
-  gBrowser.addEventListener("load", function(event) {
-    if (!(event.target instanceof Document) ||
-        event.target.location.href == "about:blank")
-      return;
-    gBrowser.removeEventListener("load", arguments.callee, true);
-
-    is(gBrowser.currentURI.spec, TESTROOT + "releaseNotes.xhtml?addon5", "Should have loaded the right page");
+  gBrowser.tabContainer.addEventListener("TabOpen", function listener(event) {
+    gBrowser.tabContainer.removeEventListener("TabOpen", listener, true);
+    function wantLoad(url) {
+      return url != "about:blank";
+    }
+    BrowserTestUtils.browserLoaded(event.target.linkedBrowser, false, wantLoad).then(() => {
+      is(gBrowser.currentURI.spec, TESTROOT + "releaseNotes.xhtml?addon5", "Should have loaded the right page");
 
-    gBrowser.removeCurrentTab();
+      gBrowser.removeCurrentTab();
 
-    if (gUseInContentUI) {
-      is(gBrowser.currentURI.spec, "about:addons", "Should be back to the add-ons manager");
-      run_next_test();
-    }
-    else {
-      waitForFocus(run_next_test, gManagerWindow);
-    }
+      if (gUseInContentUI) {
+        is(gBrowser.currentURI.spec, "about:addons", "Should be back to the add-ons manager");
+        run_next_test();
+      }
+      else {
+        waitForFocus(run_next_test, gManagerWindow);
+      }
+    });
   }, true);
 
   var list = gManagerWindow.document.getElementById("search-list");
   EventUtils.synthesizeMouseAtCenter(get_purchase_btn(list.firstChild), { }, gManagerWindow);
 });
 
 // Tests that clicking the buy button from the details view works
 add_test(function() {
-  gBrowser.addEventListener("load", function(event) {
-    if (!(event.target instanceof Document) ||
-        event.target.location.href == "about:blank")
-      return;
-    gBrowser.removeEventListener("load", arguments.callee, true);
-
-    is(gBrowser.currentURI.spec, TESTROOT + "releaseNotes.xhtml?addon4", "Should have loaded the right page");
+  gBrowser.tabContainer.addEventListener("TabOpen", function listener(event) {
+    gBrowser.tabContainer.removeEventListener("TabOpen", listener, true);
+    function wantLoad(url) {
+      return url != "about:blank";
+    }
+    BrowserTestUtils.browserLoaded(event.target.linkedBrowser, false, wantLoad).then(() => {
+      is(gBrowser.currentURI.spec, TESTROOT + "releaseNotes.xhtml?addon4", "Should have loaded the right page");
 
-    gBrowser.removeCurrentTab();
+      gBrowser.removeCurrentTab();
 
-    if (gUseInContentUI) {
-      is(gBrowser.currentURI.spec, "about:addons", "Should be back to the add-ons manager");
-      run_next_test();
-    }
-    else {
-      waitForFocus(run_next_test, gManagerWindow);
-    }
+      if (gUseInContentUI) {
+        is(gBrowser.currentURI.spec, "about:addons", "Should be back to the add-ons manager");
+        run_next_test();
+      }
+      else {
+        waitForFocus(run_next_test, gManagerWindow);
+      }
+    });
   }, true);
 
   var list = gManagerWindow.document.getElementById("search-list");
   var item = list.firstChild.nextSibling;
   list.ensureElementIsVisible(item);
   EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow);
   EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow);