зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
9346a4827c
Коммит
14cf4ed922
|
@ -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();
|
|
||||||
}
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче