diff --git a/devtools/client/framework/test/browser_target_events.js b/devtools/client/framework/test/browser_target_events.js index 8f8a5820f238..4b8e1919e825 100644 --- 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); -} - -function onLoad() { - target = TargetFactory.forTab(gBrowser.selectedTab); + await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); + 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); + + let visible = once(target, "visible"); gBrowser.removeCurrentTab(); -} - -function onVisible() { + 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,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(); -} +});