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

MozReview-Commit-ID: 8gF9T6qeYR3

--HG--
extra : rebase_source : e5a107e97e1dc660947e87d02111e86aac2f3c8d
This commit is contained in:
J. Ryan Stinnett 2018-04-23 19:17:20 -05:00
Родитель ab5790eaca
Коммит a3794d7c9e
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. /* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */ * http://creativecommons.org/publicdomain/zero/1.0/ */
var target; add_task(async function() {
function test() {
waitForExplicitFinish();
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); 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."); 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); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
} await hidden;
function onHidden() {
ok(true, "Hidden event received"); ok(true, "Hidden event received");
target.once("visible", onVisible);
let visible = once(target, "visible");
gBrowser.removeCurrentTab(); gBrowser.removeCurrentTab();
} await visible;
function onVisible() {
ok(true, "Visible event received"); 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, () => { ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
content.location = "data:text/html,<meta charset='utf8'/>test navigation"; content.location = "data:text/html,<meta charset='utf8'/>test navigation";
}); });
} await willNavigate;
async function onWillNavigate() {
ok(true, "will-navigate event received"); ok(true, "will-navigate event received");
target.on("navigate", onNavigate); await navigate;
}
function onNavigate() {
ok(true, "navigate event received"); ok(true, "navigate event received");
target.off("navigate", onNavigate);
target.once("close", onClose); let close = once(target, "close");
gBrowser.removeCurrentTab(); gBrowser.removeCurrentTab();
} await close;
function onClose() {
ok(true, "close event received"); ok(true, "close event received");
});
target = null;
finish();
}