Bug 1456274 - Rewrite browser_target_events in async style. r=ochameau

MozReview-Commit-ID: 8gF9T6qeYR3

--HG--
extra : rebase_source : f9e8ccc87fc46741722c35abed4a28389b73091e
This commit is contained in:
J. Ryan Stinnett 2018-04-23 19:17:20 -05:00
Родитель 9346a4827c
Коммит 14cf4ed922
1 изменённых файлов: 16 добавлений и 37 удалений

Просмотреть файл

@ -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,<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();
}
});