Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Avoid page reloads on Android desktop back https://github.com/siyuan-note/siyuan/issues/20390

Danield3887d16fc4f
diff --git a/app/guide/20210808180117-6v0mkxr/20240113110040-7sgw8kl.sy b/app/guide/20210808180117-6v0mkxr/20240113110040-7sgw8kl.sy
index f120d988bd..8f4c15f151 100644
--- a/app/guide/20210808180117-6v0mkxr/20240113110040-7sgw8kl.sy
+++ b/app/guide/20210808180117-6v0mkxr/20240113110040-7sgw8kl.sy
@@ -7,7 +7,7 @@
"id": "20240113110040-7sgw8kl",
"title": "Mobile App",
"type": "doc",
- "updated": "20261012014930"
+ "updated": "20261020133924"
},
"Children": [
{
@@ -62,7 +62,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20261012014537-535lvyo",
- "updated": "20261012014859"
+ "updated": "20261020133924"
},
"Children": [
{
@@ -118,12 +118,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261010114821-igdube1",
- "updated": "20261010114821"
+ "updated": "20261020133924"
},
"Children": [
{
"Type": "NodeText",
- "Data": "When using desktop layout on Android, the system Back button first closes the topmost dialog, menu, editing overlay, image preview or floating drawer. Each press closes one layer and preserves the browsing state underneath. With no dismissible layer open, Back performs the original page navigation."
+ "Data": "When using desktop layout on Android, the system Back button first closes the topmost dialog, menu, editing overlay, image preview or floating drawer. Each press closes one layer and preserves the browsing state underneath. With no dismissible layer open, Back follows the app's document history without reloading the interface. At the start of the history, a prompt appears; press Back again while the prompt is visible to return to the system home screen."
}
]
},
diff --git a/app/guide/20210808180117-czj9bvb/20240113102857-c63dmo5.sy b/app/guide/20210808180117-czj9bvb/20240113102857-c63dmo5.sy
index d199a6bda6..5207966ae4 100644
--- a/app/guide/20210808180117-czj9bvb/20240113102857-c63dmo5.sy
+++ b/app/guide/20210808180117-czj9bvb/20240113102857-c63dmo5.sy
@@ -7,7 +7,7 @@
"id": "20240113102857-c63dmo5",
"title": "移动端 App",
"type": "doc",
- "updated": "20261012014930"
+ "updated": "20261020133924"
},
"Children": [
{
@@ -62,7 +62,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20261012014537-ygn9gm0",
- "updated": "20261012014859"
+ "updated": "20261020133924"
},
"Children": [
{
@@ -118,12 +118,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261010114821-9zssb7v",
- "updated": "20261010114821"
+ "updated": "20261020133924"
},
"Children": [
{
"Type": "NodeText",
- "Data": "在 Android 上使用桌面布局时,系统返回键会先关闭当前最上层的弹窗、菜单、编辑浮层、图片预览或浮动抽屉,每次只关闭一层并保留底层浏览状态。没有可关闭的浮层时,才执行原有的页面返回行为。"
+ "Data": "在 Android 上使用桌面布局时,系统返回键会先关闭当前最上层的弹窗、菜单、编辑浮层、图片预览或浮动抽屉,每次只关闭一层并保留底层浏览状态。没有可关闭的浮层时,沿应用内文档历史返回,不会重新加载整个界面。到达历史起点后会提示再次返回,提示显示期间再按一次返回键即可回到系统桌面。"
}
]
},
diff --git a/app/guide/20211226090932-5lcq56f/20240113110500-dz2ae4n.sy b/app/guide/20211226090932-5lcq56f/20240113110500-dz2ae4n.sy
index f44d7b4bdd..b20f743683 100644
--- a/app/guide/20211226090932-5lcq56f/20240113110500-dz2ae4n.sy
+++ b/app/guide/20211226090932-5lcq56f/20240113110500-dz2ae4n.sy
@@ -7,7 +7,7 @@
"id": "20240113110500-dz2ae4n",
"title": "行動端 App",
"type": "doc",
- "updated": "20261012014930"
+ "updated": "20261020133924"
},
"Children": [
{
@@ -62,7 +62,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20261012014537-f76dj41",
- "updated": "20261012014859"
+ "updated": "20261020133924"
},
"Children": [
{
@@ -118,12 +118,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261010114821-z8mdm4l",
- "updated": "20261010114821"
+ "updated": "20261020133924"
},
"Children": [
{
"Type": "NodeText",
- "Data": "在 Android 上使用桌面佈局時,系統返回鍵會先關閉目前最上層的對話框、選單、編輯浮層、圖片預覽或浮動抽屜,每次只關閉一層並保留底層瀏覽狀態。沒有可關閉的浮層時,才執行原有的頁面返回行為。"
+ "Data": "在 Android 上使用桌面佈局時,系統返回鍵會先關閉目前最上層的對話框、選單、編輯浮層、圖片預覽或浮動抽屜,每次只關閉一層並保留底層瀏覽狀態。沒有可關閉的浮層時,沿應用程式內的文件歷史返回,不會重新載入整個介面。到達歷史起點後會提示再次返回,提示顯示期間再按一次返回鍵即可回到系統桌面。"
}
]
},
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-e6z5okf.sy b/app/guide/20240530133126-axarxgx/20240530101000-e6z5okf.sy
index 2cb679936b..ce1c090ab8 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-e6z5okf.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-e6z5okf.sy
@@ -8,7 +8,7 @@
"id": "20240530101000-e6z5okf",
"title": "モバイルアプリ",
"type": "doc",
- "updated": "20261016202856"
+ "updated": "20261020133924"
},
"Children": [
{
@@ -46,7 +46,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20261012014537-e3i64fc",
- "updated": "20261012014859"
+ "updated": "20261020133924"
},
"Children": [
{
@@ -102,12 +102,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261010114821-jcdqygo",
- "updated": "20261010114821"
+ "updated": "20261020133924"
},
"Children": [
{
"Type": "NodeText",
- "Data": "Android でデスクトップレイアウトを使用する場合、システムの戻るボタンは最上位のダイアログ、メニュー、編集用の浮動画面、画像プレビューまたはフローティングドロワーを先に閉じます。1 回の操作で 1 つの画面だけを閉じ、背後の閲覧状態を保持します。閉じられる浮動画面がない場合に、従来のページ移動を行います。"
+ "Data": "Android でデスクトップレイアウトを使用する場合、システムの戻るボタンは最上位のダイアログ、メニュー、編集用の浮動画面、画像プレビューまたはフローティングドロワーを先に閉じます。1 回の操作で 1 つの画面だけを閉じ、背後の閲覧状態を保持します。閉じられる浮動画面がない場合は、画面全体を再読み込みせず、アプリ内のドキュメント履歴を戻ります。履歴の先頭では確認メッセージが表示され、表示中にもう一度戻るボタンを押すとシステムのホーム画面に戻ります。"
}
]
},
diff --git a/app/src/boot/globalEvent/nativeBack.test.ts b/app/src/boot/globalEvent/nativeBack.test.ts
index 7d6a48dfca..85ababa8ae 100644
--- a/app/src/boot/globalEvent/nativeBack.test.ts
+++ b/app/src/boot/globalEvent/nativeBack.test.ts
@@ -2,14 +2,18 @@ import {test} from "node:test";
import * as assert from "node:assert/strict";
import {readFileSync} from "node:fs";
import {runInNewContext} from "node:vm";
-import {ModuleKind, ScriptTarget, transpileModule} from "typescript";
+import {createSourceFile, isVariableStatement, ModuleKind, ScriptTarget, transpileModule} from "typescript";
+import type {App} from "../../index";
const code = transpileModule(readFileSync("src/boot/globalEvent/nativeBack.ts", "utf8"), {
compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},
}).outputText;
-const setup = (android = true) => {
+const setup = (android = true, navigation?: Pick<typeof import("../../util/backForward"), "goBack" | "hasBackHistory">) => {
const closed: string[] = [];
+ const messages: string[] = [];
+ const errors: unknown[] = [];
+ let exitTipVisible = false;
const elements: Record<string, ReturnType<typeof element>[]> = {};
const element = (name: string, zIndex: number, hidden = false) => ({
name, isConnected: true, parentElement: null as HTMLElement | null, dataset: {} as Record<string, string>,
@@ -27,20 +31,42 @@ const setup = (android = true) => {
const dock = element("drawer", 100);
let drawerOpen = true;
let floating = true;
- const siyuan = {dialogs, blockPanels: panels,
+ const siyuan = {dialogs, blockPanels: panels, isReady: true,
+ languages: {returnDesktop: "Press back again to return to desktop"},
menus: {menu: {element: element("menu", 50, true), remove: () => { closed.push("menu"); }}},
layout: {rightDock: {layout: {element: dock}, isFloating: () => floating,
isPanelVisible: () => drawerOpen, togglePanel: (visible: boolean) => { drawerOpen = visible; closed.push("drawer"); }}},
viewer: {destroyed: true, viewer: element("viewer", 300), hide: () => { closed.push("viewer-hidden"); siyuan.viewer.destroyed = true; }},
};
- const window = {siyuan, JSAndroid: android ? {} : undefined, history: {back: () => closed.push("history")},
+ const window = {siyuan, JSAndroid: android ? {returnDesktop: () => closed.push("return-desktop")} : undefined,
+ history: {back: () => assert.fail("native back must never navigate browser history")},
goBack: undefined as (() => void) | undefined};
+ const app = {} as App;
const api = {} as typeof import("./nativeBack");
- runInNewContext(code, {exports: api, window, document: {
+ runInNewContext(code, {exports: api, window, console: {error: (error: unknown) => errors.push(error)}, document: {
querySelectorAll: (selector: string) => elements[selector] || [], activeElement: null,
+ querySelector: (selector: string) => {
+ assert.equal(selector, '#message [data-id="exitTip"]:not(.b3-snackbar--hide)');
+ return exitTipVisible ? {} : null;
+ },
}, getComputedStyle: (item: ReturnType<typeof element>) => ({display: "block", visibility: "visible", ...item.style}),
CustomEvent: class { constructor(public type: string) {} }, require: (name: string) => ({
"../../util/zIndex": {getZIndex: (item: ReturnType<typeof element>) => Number(item.style.zIndex)},
+ "../../util/backForward": navigation || {hasBackHistory: () => true, goBack: async (value: App) => {
+ assert.equal(value, app);
+ closed.push("document-back");
+ }},
+ "../../dialog/message": {
+ showMessage: (text: string, timeout: number, type: string, id: string) => {
+ assert.equal(text, siyuan.languages.returnDesktop);
+ assert.equal(timeout, 3000);
+ assert.equal(type, "info");
+ assert.equal(id, "exitTip");
+ messages.push(text);
+ exitTipVisible = true;
+ },
+ hideMessage: (id: string) => { assert.equal(id, "exitTip"); exitTipVisible = false; },
+ },
"../../protyle/render/av/cellEditor": {AV_CELL_EDITOR_CLOSE_EVENT: "cell-close"},
"../../protyle/render/av/richTextEditor": {destroyAVRichTextEditor: (save: boolean) => {
assert.equal(save, true); closed.push("rich-text-saved"); elements[".av__mask"] = [];
@@ -53,11 +79,12 @@ const setup = (android = true) => {
dialogs.push(item);
return item;
};
- return {api, window, siyuan, element, elements, closed, addDialog, dock,
+ return {api, app, window, siyuan, element, elements, closed, messages, errors, addDialog, dock,
+ expireTip() { exitTipVisible = false; },
setFloating(value: boolean) { floating = value; }, setDrawer(value: boolean) { drawerOpen = value; }};
};
-test("Android desktop back closes the highest menu, dialog and drawer one at a time, then uses history", () => {
+test("Android desktop back closes the highest menu, dialog and drawer one at a time, then uses document history", () => {
const state = setup();
state.addDialog("first-dialog", 150);
state.addDialog("top-dialog", 200);
@@ -65,9 +92,9 @@ test("Android desktop back closes the highest menu, dialog and drawer one at a t
state.siyuan.menus.menu.remove = () => {
state.closed.push("menu"); state.siyuan.menus.menu.element.isConnected = false;
};
- state.api.registerDesktopBackNavigation();
+ state.api.registerDesktopBackNavigation(state.app);
for (let i = 0; i < 5; i++) state.window.goBack();
- assert.deepEqual(state.closed, ["menu", "top-dialog", "first-dialog", "drawer", "history"]);
+ assert.deepEqual(state.closed, ["menu", "top-dialog", "first-dialog", "drawer", "document-back"]);
});
test("a higher dialog closes ahead of an older menu regardless of array order", () => {
@@ -97,9 +124,9 @@ test("image previews run hidden cleanup and ordinary dock panels do not consume
state.api.closeDesktopBackLayer();
assert.deepEqual(state.closed, ["viewer-hidden"]);
assert.equal(state.api.closeDesktopBackLayer(), false);
- state.api.registerDesktopBackNavigation();
+ state.api.registerDesktopBackNavigation(state.app);
state.window.goBack();
- assert.deepEqual(state.closed, ["viewer-hidden", "history"]);
+ assert.deepEqual(state.closed, ["viewer-hidden", "document-back"]);
});
test("a popup inherits its parent's layer and hidden overlays do not consume back", () => {
@@ -144,6 +171,123 @@ test("closing dialogs consume repeated back presses and a plain browser keeps it
dialog.element.dataset.dialogClosing = "true";
dialog.element.querySelector = (): null => null;
assert.equal(state.api.closeDesktopBackLayer(), true);
- state.api.registerDesktopBackNavigation();
+ state.api.registerDesktopBackNavigation(state.app);
assert.equal(state.window.goBack, undefined);
});
+
+test("at the history start Back prompts before returning to the system desktop, and expired tips do not confirm", () => {
+ const state = setup(true, {hasBackHistory: () => false, goBack: async () => assert.fail("no history")});
+ state.setDrawer(false);
+ state.api.registerDesktopBackNavigation(state.app);
+ state.window.goBack();
+ assert.equal(state.messages.length, 1);
+ assert.deepEqual(state.closed, []);
+ state.expireTip();
+ state.window.goBack();
+ assert.equal(state.messages.length, 2);
+ assert.deepEqual(state.closed, []);
+ state.window.goBack();
+ assert.deepEqual(state.closed, ["return-desktop"]);
+ state.window.goBack();
+ assert.equal(state.messages.length, 3);
+ assert.deepEqual(state.closed, ["return-desktop"]);
+});
+
+test("closing an overlay cancels the previous return-to-desktop confirmation", () => {
+ const state = setup(true, {hasBackHistory: () => false, goBack: async () => assert.fail("no history")});
+ state.setDrawer(false);
+ state.api.registerDesktopBackNavigation(state.app);
+ state.window.goBack();
+ state.addDialog("new-dialog", 200);
+ state.window.goBack();
+ state.window.goBack();
+ assert.deepEqual(state.closed, ["new-dialog"]);
+ assert.equal(state.messages.length, 2);
+});
+
+test("document navigation consumes rapid Back presses but still permits closing a newly opened overlay", async () => {
+ let hasHistory = false;
+ let finish: () => void;
+ let navigations = 0;
+ const state = setup(true, {hasBackHistory: () => hasHistory, goBack: () => {
+ navigations++;
+ hasHistory = false;
+ return new Promise<void>(resolve => { finish = resolve; });
+ }});
+ state.setDrawer(false);
+ state.api.registerDesktopBackNavigation(state.app);
+ state.window.goBack();
+ hasHistory = true;
+ state.window.goBack();
+ state.window.goBack();
+ assert.equal(navigations, 1);
+ assert.equal(state.messages.length, 1);
+ state.addDialog("loading-dialog", 200);
+ state.window.goBack();
+ assert.deepEqual(state.closed, ["loading-dialog"]);
+ finish();
+ await new Promise(setImmediate);
+ state.window.goBack();
+ assert.equal(state.messages.length, 2);
+ assert.deepEqual(state.closed, ["loading-dialog"]);
+});
+
+test("Back is consumed while the desktop is still initializing", () => {
+ const state = setup();
+ state.setDrawer(false);
+ state.siyuan.isReady = false;
+ state.api.registerDesktopBackNavigation(state.app);
+ state.window.goBack();
+ assert.deepEqual(state.closed, []);
+ assert.deepEqual(state.messages, []);
+});
+
+test("a failed history navigation releases the Back guard without falling through to the system desktop", async () => {
+ const error = new Error("history lookup failed");
+ let navigations = 0;
+ const state = setup(true, {hasBackHistory: () => true, goBack: async () => {
+ navigations++;
+ throw error;
+ }});
+ state.setDrawer(false);
+ state.api.registerDesktopBackNavigation(state.app);
+ state.window.goBack();
+ await new Promise(setImmediate);
+ assert.deepEqual(state.errors, [error]);
+ assert.deepEqual(state.closed, []);
+ assert.deepEqual(state.messages, []);
+ state.window.goBack();
+ await new Promise(setImmediate);
+ assert.equal(navigations, 2);
+});
+
+test("native Back follows the actual desktop history stack and stops at its first document", async () => {
+ const source = createSourceFile("backForward.ts", readFileSync("src/util/backForward.ts", "utf8"), ScriptTarget.ES2021, true);
+ const names = ["goBack", "hasBackHistory", "forwardStack", "previousIsBack"];
+ const declarations = source.statements.filter(statement => isVariableStatement(statement) &&
+ statement.declarationList.declarations.some(item => names.includes(item.name.getText(source))));
+ const code = transpileModule(declarations.map(item => item.getText(source)).join("\n"), {
+ compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},
+ }).outputText;
+ const visited: string[] = [];
+ const navigation = {} as Pick<typeof import("../../util/backForward"), "goBack" | "hasBackHistory">;
+ runInNewContext(code, {exports: navigation,
+ window: {siyuan: {backStack: ["first", "second", "third"].map(id => ({id, protyle: {element: {}}}))}},
+ document: {contains: () => true, querySelector: (): null => null}, saveBackScroll: () => {},
+ focusStack: async (_app: App, stack: {id: string}) => { visited.push(stack.id); return true; },
+ });
+ const state = setup(true, navigation);
+ state.setDrawer(false);
+ state.api.registerDesktopBackNavigation(state.app);
+ for (let i = 0; i < 2; i++) {
+ state.window.goBack();
+ await new Promise(setImmediate);
+ }
+ assert.deepEqual(visited, ["second", "first"]);
+ assert.equal(state.messages.length, 0);
+ state.window.goBack();
+ assert.deepEqual(visited, ["second", "first"]);
+ assert.equal(state.messages.length, 1);
+ state.window.goBack();
+ assert.deepEqual(state.closed, ["return-desktop"]);
+});
diff --git a/app/src/boot/globalEvent/nativeBack.ts b/app/src/boot/globalEvent/nativeBack.ts
index f5c83b96c5..813d19b711 100644
--- a/app/src/boot/globalEvent/nativeBack.ts
+++ b/app/src/boot/globalEvent/nativeBack.ts
@@ -1,6 +1,9 @@
import {destroyAVRichTextEditor} from "../../protyle/render/av/richTextEditor";
import {AV_CELL_EDITOR_CLOSE_EVENT} from "../../protyle/render/av/cellEditor";
import {getZIndex} from "../../util/zIndex";
+import type {App} from "../../index";
+import {goBack, hasBackHistory} from "../../util/backForward";
+import {hideMessage, showMessage} from "../../dialog/message";
// Android 桌面布局按实际层级关闭一个浮层,保留底层文档和面板的浏览状态。
export const closeDesktopBackLayer = () => {
@@ -77,11 +80,38 @@ export const closeDesktopBackLayer = () => {
return siyuan.dialogs?.some(dialog => dialog.element.dataset.dialogClosing === "true") ?? false;
};
-export const registerDesktopBackNavigation = () => {
+export const registerDesktopBackNavigation = (app: App) => {
if (window.JSAndroid) {
+ let navigating = false;
+ let exitTipArmed = false;
+ const resetExitTip = () => {
+ if (exitTipArmed) {
+ exitTipArmed = false;
+ hideMessage("exitTip");
+ }
+ };
window.goBack = () => {
- if (!closeDesktopBackLayer()) {
- window.history.back();
+ if (closeDesktopBackLayer()) {
+ resetExitTip();
+ return;
+ }
+ if (navigating || !window.siyuan.isReady) {
+ return;
+ }
+ if (hasBackHistory()) {
+ resetExitTip();
+ navigating = true;
+ void goBack(app).catch(console.error).finally(() => {
+ navigating = false;
+ });
+ return;
+ }
+ if (exitTipArmed && document.querySelector('#message [data-id="exitTip"]:not(.b3-snackbar--hide)')) {
+ resetExitTip();
+ window.JSAndroid.returnDesktop();
+ } else {
+ exitTipArmed = true;
+ showMessage(window.siyuan.languages.returnDesktop, 3000, "info", "exitTip");
}
};
}
diff --git a/app/src/index.ts b/app/src/index.ts
index fda355f72e..331db58237 100644
--- a/app/src/index.ts
+++ b/app/src/index.ts
@@ -411,7 +411,7 @@ window.openFileByURL = (openURL) => {
};
/// #if BROWSER
-registerDesktopBackNavigation();
+registerDesktopBackNavigation(siyuanApp);
window.showKeyboardToolbar = () => {
// 防止 Pad 端报错
};
diff --git a/app/src/util/backForward.ts b/app/src/util/backForward.ts
index 3d2144feeb..48014a49c9 100644
--- a/app/src/util/backForward.ts
+++ b/app/src/util/backForward.ts
@@ -326,6 +326,13 @@ const focusStack = async (app: App, stack: IBackStack) => {
}
};
+export const hasBackHistory = () => {
+ const stacks = window.siyuan.backStack;
+ const last = stacks[stacks.length - 1];
+ // 后退后当前记录位于前进栈;未后退时,已关闭的当前页签也可作为返回目标。
+ return Boolean(last && (previousIsBack || stacks.length > 1 || !document.contains(last.protyle.element)));
+};
+
export const goBack = async (app: App) => {
const current = previousIsBack ? forwardStack[forwardStack.length - 1] :
window.siyuan.backStack[window.siyuan.backStack.length - 1];
diff --git a/app/src/util/backForwardState.test.ts b/app/src/util/backForwardState.test.ts
index d95de38b63..0235b1c990 100644
--- a/app/src/util/backForwardState.test.ts
+++ b/app/src/util/backForwardState.test.ts
@@ -5,11 +5,11 @@ import {runInNewContext} from "node:vm";
import {createSourceFile, isVariableStatement, ScriptTarget, transpileModule} from "typescript";
const source = createSourceFile("backForward.ts", readFileSync("src/util/backForward.ts", "utf8"), ScriptTarget.ES2021, true);
-const names = ["pushBack", "goBack", "goForward", "forwardStack", "previousIsBack"];
+const names = ["pushBack", "goBack", "goForward", "hasBackHistory", "forwardStack", "previousIsBack"];
const declarations = source.statements.filter(statement => isVariableStatement(statement) &&
statement.declarationList.declarations.some(item => names.includes(item.name.getText(source))));
const compiled = transpileModule(declarations.map(item => item.getText(source).replace(/^export /, "")).join("\n") +
- "\nglobalThis.history = {pushBack, goBack, goForward};", {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;
+ "\nglobalThis.history = {pushBack, goBack, goForward, hasBackHistory};", {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;
const setup = () => {
const stacks: any[] = [];
@@ -88,3 +88,37 @@ test("an invalid navigation record does not discard forward history", async () =
await history.goForward({});
assert.equal(visited.at(-1).protyle, c);
});
+
+test("back availability follows document history through back, forward and new navigation", async () => {
+ const {tabs: [a, b, c], push, history} = setup();
+ assert.equal(history.hasBackHistory(), false);
+ push(a);
+ assert.equal(history.hasBackHistory(), false);
+ push(b);
+ assert.equal(history.hasBackHistory(), true);
+ push(c);
+ await history.goBack({});
+ assert.equal(history.hasBackHistory(), true);
+ await history.goBack({});
+ assert.equal(history.hasBackHistory(), false);
+ await history.goForward({});
+ assert.equal(history.hasBackHistory(), true);
+ await history.goBack({});
+ push(c);
+ assert.equal(history.hasBackHistory(), true);
+ await history.goBack({});
+ assert.equal(history.hasBackHistory(), false);
+});
+
+test("a closed current tab remains a back destination and deleted records can exhaust history", async () => {
+ const {tabs: [a, b], context, push, history} = setup();
+ push(a);
+ context.document.contains = () => false;
+ assert.equal(history.hasBackHistory(), true);
+ await history.goBack({});
+ assert.equal(history.hasBackHistory(), false);
+ push(b);
+ context.focusStack = async () => false;
+ await history.goBack({});
+ assert.equal(history.hasBackHistory(), false);
+});