Bug 1456274 - Rewrite browser_target_events in async style. r=ochameau
☠☠ backed out by e43c1c2ce413 ☠ ☠
authorJ. Ryan Stinnett <jryans@gmail.com>
Mon, 23 Apr 2018 19:17:20 -0500
changeset 469119 97e8882d03431bdb47e706925ac526061966389c
parent 469118 7cf34fe2036ec2ac76111b54e409aa98a39232e6
child 469120 707d5e397407bdee7cdfbb5ee6ff644126b778a9
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1456274
milestone61.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 1456274 - Rewrite browser_target_events in async style. r=ochameau MozReview-Commit-ID: 8gF9T6qeYR3
devtools/client/framework/test/browser_target_events.js
--- a/devtools/client/framework/test/browser_target_events.js
+++ b/devtools/client/framework/test/browser_target_events.js
@@ -1,56 +1,35 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-var target;
-
-function test() {
-  waitForExplicitFinish();
-
+add_task(async function() {
   gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
-  BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(onLoad);
-}
+  await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
 
-function onLoad() {
-  target = TargetFactory.forTab(gBrowser.selectedTab);
-
+  let target = TargetFactory.forTab(gBrowser.selectedTab);
   is(target.tab, gBrowser.selectedTab, "Target linked to the right tab.");
 
-  target.once("hidden", onHidden);
+  let hidden = once(target, "hidden");
   gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
-}
-
-function onHidden() {
+  await hidden;
   ok(true, "Hidden event received");
-  target.once("visible", onVisible);
-  gBrowser.removeCurrentTab();
-}
 
-function onVisible() {
+  let visible = once(target, "visible");
+  gBrowser.removeCurrentTab();
+  await visible;
   ok(true, "Visible event received");
-  target.once("will-navigate", onWillNavigate);
 
+  let willNavigate = once(target, "will-navigate");
+  let navigate = once(target, "navigate");
   ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
     content.location = "data:text/html,<meta charset='utf8'/>test navigation";
   });
-}
-
-async function onWillNavigate() {
+  await willNavigate;
   ok(true, "will-navigate event received");
-  target.on("navigate", onNavigate);
-}
-
-function onNavigate() {
+  await navigate;
   ok(true, "navigate event received");
-  target.off("navigate", onNavigate);
-  target.once("close", onClose);
+
+  let close = once(target, "close");
   gBrowser.removeCurrentTab();
-}
-
-function onClose() {
+  await close;
   ok(true, "close event received");
-
-  target = null;
-  finish();
-}
+});