Skip to content

Commit

Permalink
feat(helpers): let openURL support ext based url
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Apr 21, 2018
1 parent 80c38f4 commit e89eb54
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/_helpers/browser-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ export const message = {
/**
* Open a url on new tab or highlight a existing tab if already opened
*/
export function openURL (url: string): Promise<void> {
export function openURL (url: string, self?: boolean): Promise<void> {
if (self) { url = browser.runtime.getURL(url) }
return browser.tabs.query({ url })
// Only Chrome supports tab.highlight for now
.then(tabs => (tabs.length > 0 && typeof browser.tabs.highlight === 'function')
Expand Down
9 changes: 9 additions & 0 deletions test/specs/_helpers/browser-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,5 +848,14 @@ describe('Browser API Wapper', () => {
expect(browser.tabs.create.calledWith({ url })).toBeTruthy()
})
})
it('Concat extension base url', () => {
browser.tabs.query.returns(Promise.resolve([]))
browser.runtime.getURL.returns('test')
return openURL(url, true)
.then(() => {
expect(browser.runtime.getURL.calledWith(url)).toBeTruthy()
expect(browser.tabs.create.calledWith({ url: 'test' })).toBeTruthy()
})
})
})
})

0 comments on commit e89eb54

Please sign in to comment.