зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1633328 - support tabs.goForward() and tabs.goBack() for Android r=zombie,geckoview-reviewers,agi
Differential Revision: https://phabricator.services.mozilla.com/D73010
This commit is contained in:
Родитель
3140cd5e25
Коммит
0feacb38f7
|
@ -507,6 +507,16 @@ this.tabs = class extends ExtensionAPI {
|
|||
|
||||
return tab.removeCSS(context, details);
|
||||
},
|
||||
|
||||
goForward(tabId) {
|
||||
const { browser } = getTabOrActive(tabId);
|
||||
browser.goForward();
|
||||
},
|
||||
|
||||
goBack(tabId) {
|
||||
const { browser } = getTabOrActive(tabId);
|
||||
browser.goBack();
|
||||
},
|
||||
},
|
||||
};
|
||||
return self;
|
||||
|
|
|
@ -1065,6 +1065,48 @@
|
|||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "goForward",
|
||||
"type": "function",
|
||||
"description": "Navigate to next page in tab's history, if available.",
|
||||
"async": "callback",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "tabId",
|
||||
"minimum": 0,
|
||||
"optional": true,
|
||||
"description": "The ID of the tab to navigate forward."
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"name": "callback",
|
||||
"optional": true,
|
||||
"parameters": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "goBack",
|
||||
"type": "function",
|
||||
"description": "Navigate to previous page in tab's history, if available.",
|
||||
"async": "callback",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "tabId",
|
||||
"minimum": 0,
|
||||
"optional": true,
|
||||
"description": "The ID of the tab to navigate backward."
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"name": "callback",
|
||||
"optional": true,
|
||||
"parameters": []
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"events": [
|
||||
|
|
|
@ -28,6 +28,7 @@ skip-if = !is_fennec # times out; bug 1534640 webextension url
|
|||
[test_ext_tabs_executeScript_runAt.html]
|
||||
[test_ext_tabs_get.html]
|
||||
[test_ext_tabs_getCurrent.html]
|
||||
[test_ext_tabs_goBack_goForward.html]
|
||||
skip-if = !is_fennec # times out
|
||||
[test_ext_tabs_insertCSS.html]
|
||||
[test_ext_tabs_lastAccessed.html]
|
||||
|
|
|
@ -25,6 +25,8 @@ let expectedBackgroundApisTargetSpecific = [
|
|||
"tabs.executeScript",
|
||||
"tabs.get",
|
||||
"tabs.getCurrent",
|
||||
"tabs.goBack",
|
||||
"tabs.goForward",
|
||||
"tabs.insertCSS",
|
||||
"tabs.onActivated",
|
||||
"tabs.onAttached",
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Tabs goBack and goForward Test</title>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="/tests/SimpleTest/SimpleTest.js"
|
||||
></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="/tests/SimpleTest/ExtensionTestUtils.js"
|
||||
></script>
|
||||
<script type="text/javascript" src="head.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
|
||||
add_task(async function test_tabs_goBack_goForward() {
|
||||
const extension = ExtensionTestUtils.loadExtension({
|
||||
useAddonManager: "permanent",
|
||||
manifest: {
|
||||
applications: {
|
||||
gecko: { id: "goBack-goForward@tests.mozilla.org" },
|
||||
},
|
||||
permissions: ["tabs"],
|
||||
},
|
||||
|
||||
files: {
|
||||
"tab1.html": `<head>
|
||||
<meta charset=UTF-8">
|
||||
<title>tab1</title>
|
||||
</head>`,
|
||||
"tab2.html": `<head>
|
||||
<meta charset=UTF-8">
|
||||
<title>tab2</title>
|
||||
</head>`,
|
||||
},
|
||||
|
||||
async background() {
|
||||
let tabUpdatedCount = 0;
|
||||
let tab = {};
|
||||
|
||||
browser.tabs.onUpdated.addListener(
|
||||
async (tabId, changeInfo, tabInfo) => {
|
||||
if (
|
||||
changeInfo.status !== "complete" ||
|
||||
tabId !== tab.id ||
|
||||
tabInfo.url === "about:blank"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
tabUpdatedCount++;
|
||||
switch (tabUpdatedCount) {
|
||||
case 1:
|
||||
browser.test.assertEq(
|
||||
"tab1",
|
||||
tabInfo.title,
|
||||
"tab1 is found as expected"
|
||||
);
|
||||
browser.tabs.update(tabId, { url: "tab2.html" });
|
||||
break;
|
||||
|
||||
case 2:
|
||||
browser.test.assertEq(
|
||||
"tab2",
|
||||
tabInfo.title,
|
||||
"tab2 is found as expected"
|
||||
);
|
||||
browser.tabs.update(tabId, { url: "tab1.html" });
|
||||
break;
|
||||
|
||||
case 3:
|
||||
browser.test.assertEq(
|
||||
"tab1",
|
||||
tabInfo.title,
|
||||
"tab1 is found as expected"
|
||||
);
|
||||
browser.tabs.goBack();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
browser.test.assertEq(
|
||||
"tab2",
|
||||
tabInfo.title,
|
||||
"tab2 is found after navigating backward with empty parameter"
|
||||
);
|
||||
browser.tabs.goBack(tabId);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
browser.test.assertEq(
|
||||
"tab1",
|
||||
tabInfo.title,
|
||||
"tab1 is found after navigating backward with tabId as parameter"
|
||||
);
|
||||
browser.tabs.goForward();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
browser.test.assertEq(
|
||||
"tab2",
|
||||
tabInfo.title,
|
||||
"tab2 is found after navigating forward with empty parameter"
|
||||
);
|
||||
browser.tabs.goForward(tabId);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
browser.test.assertEq(
|
||||
"tab1",
|
||||
tabInfo.title,
|
||||
"tab1 is found after navigating forward with tabId as parameter"
|
||||
);
|
||||
await browser.tabs.remove(tabId);
|
||||
browser.test.notifyPass("tabs.goBack.goForward");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
tab = await browser.tabs.create({ url: "tab1.html", active: true });
|
||||
},
|
||||
});
|
||||
|
||||
await extension.startup();
|
||||
await extension.awaitFinish("tabs.goBack.goForward");
|
||||
await extension.unload();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче