feat: duplicate navigation related APIs to contents.navigationHistory
(#41752)
* refactor: move navigation related api to navigationHistory * docs: add deprecation messages to old web content methods * fix: add deprecation warnings to webcontents * fix: add deprecation warnings and make existing naviagation apis internal * Update docs/api/web-contents.md Co-authored-by: Sam Maddock <samuel.maddock@gmail.com> * Update docs/api/web-contents.md Co-authored-by: Sam Maddock <samuel.maddock@gmail.com> * Update docs/api/web-contents.md Co-authored-by: Sam Maddock <samuel.maddock@gmail.com> * Update docs/api/web-contents.md Co-authored-by: Sam Maddock <samuel.maddock@gmail.com> * docs: fix links * docs: add breaking change to 31 * docs: move breaking change to 32 * chore: re-run pipeline --------- Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>
This commit is contained in:
parent
5fb117a7d7
commit
406f644d26
7 changed files with 239 additions and 17 deletions
|
@ -567,6 +567,84 @@ describe('webContents module', () => {
|
|||
w = new BrowserWindow({ show: false });
|
||||
});
|
||||
afterEach(closeAllWindows);
|
||||
describe('navigationHistory.canGoBack and navigationHistory.goBack API', () => {
|
||||
it('should not be able to go back if history is empty', async () => {
|
||||
expect(w.webContents.navigationHistory.canGoBack()).to.be.false();
|
||||
});
|
||||
|
||||
it('should be able to go back if history is not empty', async () => {
|
||||
await w.loadURL(urlPage1);
|
||||
await w.loadURL(urlPage2);
|
||||
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(1);
|
||||
expect(w.webContents.navigationHistory.canGoBack()).to.be.true();
|
||||
w.webContents.navigationHistory.goBack();
|
||||
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigationHistory.canGoForward and navigationHistory.goForward API', () => {
|
||||
it('should not be able to go forward if history is empty', async () => {
|
||||
expect(w.webContents.navigationHistory.canGoForward()).to.be.false();
|
||||
});
|
||||
|
||||
it('should not be able to go forward if current index is same as history length', async () => {
|
||||
await w.loadURL(urlPage1);
|
||||
await w.loadURL(urlPage2);
|
||||
expect(w.webContents.navigationHistory.canGoForward()).to.be.false();
|
||||
});
|
||||
|
||||
it('should be able to go forward if history is not empty and active index is less than history length', async () => {
|
||||
await w.loadURL(urlPage1);
|
||||
await w.loadURL(urlPage2);
|
||||
w.webContents.navigationHistory.goBack();
|
||||
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(0);
|
||||
expect(w.webContents.navigationHistory.canGoForward()).to.be.true();
|
||||
w.webContents.navigationHistory.goForward();
|
||||
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigationHistory.canGoToOffset(index) and navigationHistory.goToOffset(index) API', () => {
|
||||
it('should not be able to go to invalid offset', async () => {
|
||||
expect(w.webContents.navigationHistory.canGoToOffset(-1)).to.be.false();
|
||||
expect(w.webContents.navigationHistory.canGoToOffset(10)).to.be.false();
|
||||
});
|
||||
|
||||
it('should be able to go to valid negative offset', async () => {
|
||||
await w.loadURL(urlPage1);
|
||||
await w.loadURL(urlPage2);
|
||||
await w.loadURL(urlPage3);
|
||||
expect(w.webContents.navigationHistory.canGoToOffset(-2)).to.be.true();
|
||||
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(2);
|
||||
w.webContents.navigationHistory.goToOffset(-2);
|
||||
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(0);
|
||||
});
|
||||
|
||||
it('should be able to go to valid positive offset', async () => {
|
||||
await w.loadURL(urlPage1);
|
||||
await w.loadURL(urlPage2);
|
||||
await w.loadURL(urlPage3);
|
||||
|
||||
w.webContents.navigationHistory.goBack();
|
||||
expect(w.webContents.navigationHistory.canGoToOffset(1)).to.be.true();
|
||||
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(1);
|
||||
w.webContents.navigationHistory.goToOffset(1);
|
||||
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigationHistory.clear API', () => {
|
||||
it('should be able clear history', async () => {
|
||||
await w.loadURL(urlPage1);
|
||||
await w.loadURL(urlPage2);
|
||||
await w.loadURL(urlPage3);
|
||||
|
||||
expect(w.webContents.navigationHistory.length()).to.equal(3);
|
||||
w.webContents.navigationHistory.clear();
|
||||
expect(w.webContents.navigationHistory.length()).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigationHistory.getEntryAtIndex(index) API ', () => {
|
||||
it('should fetch default navigation entry when no urls are loaded', async () => {
|
||||
const result = w.webContents.navigationHistory.getEntryAtIndex(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue