Skip to content

Commit

Permalink
test: add new openExternal specs for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Dec 22, 2018
1 parent 71dc30b commit feeda28
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 21 deletions.
8 changes: 4 additions & 4 deletions default_app/menu.js
Expand Up @@ -77,27 +77,27 @@ const setDefaultApplicationMenu = () => {
{
label: 'Learn More',
click () {
shell.openExternal('https://electronjs.org')
shell.openExternalSync('https://electronjs.org')
}
},
{
label: 'Documentation',
click () {
shell.openExternal(
shell.openExternalSync(
`https://github.com/electron/electron/tree/v${process.versions.electron}/docs#readme`
)
}
},
{
label: 'Community Discussions',
click () {
shell.openExternal('https://discuss.atom.io/c/electron')
shell.openExternalSync('https://discuss.atom.io/c/electron')
}
},
{
label: 'Search Issues',
click () {
shell.openExternal('https://github.com/electron/electron/issues')
shell.openExternalSync('https://github.com/electron/electron/issues')
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion default_app/renderer.js
Expand Up @@ -19,7 +19,7 @@ function initialize () {

const openLinkExternally = (e) => {
e.preventDefault()
shell.openExternal(url)
shell.openExternalSync(url)
}

link.addEventListener('click', openLinkExternally)
Expand Down
2 changes: 1 addition & 1 deletion docs/api/menu.md
Expand Up @@ -198,7 +198,7 @@ const template = [
submenu: [
{
label: 'Learn More',
click () { require('electron').shell.openExternal('https://electronjs.org') }
click () { require('electron').shell.openExternalSync('https://electronjs.org') }
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions docs/api/promisification.md
Expand Up @@ -8,7 +8,6 @@ When a majority of affected functions are migrated, this flag will be enabled by

### Candidate Functions

- [ ] [app.getFileIcon(path[, options], callback)](https://github.com/electron/electron/blob/master/docs/api/app.md#getFileIcon)
- [ ] [app.importCertificate(options, callback)](https://github.com/electron/electron/blob/master/docs/api/app.md#importCertificate)
- [ ] [request.write(chunk[, encoding][, callback])](https://github.com/electron/electron/blob/master/docs/api/client-request.md#write)
- [ ] [request.end([chunk][, encoding][, callback])](https://github.com/electron/electron/blob/master/docs/api/client-request.md#end)
Expand Down Expand Up @@ -41,7 +40,6 @@ When a majority of affected functions are migrated, this flag will be enabled by
- [ ] [ses.clearHostResolverCache([callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearHostResolverCache)
- [ ] [ses.getBlobData(identifier, callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#getBlobData)
- [ ] [ses.clearAuthCache(options[, callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearAuthCache)
- [ ] [shell.openExternal(url[, options, callback])](https://github.com/electron/electron/blob/master/docs/api/shell.md#openExternal)
- [ ] [contents.executeJavaScript(code[, userGesture, callback])](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#executeJavaScript)
- [ ] [contents.getZoomFactor(callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#getZoomFactor)
- [ ] [contents.getZoomLevel(callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#getZoomLevel)
Expand All @@ -61,4 +59,6 @@ When a majority of affected functions are migrated, this flag will be enabled by

- [ ] [win.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/browser-window.md#capturePage)
- [ ] [webviewTag.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/webview-tag.md#capturePage)
- [ ] [contents.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#capturePage)
- [ ] [contents.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#capturePage)
- [ ] [app.getFileIcon(path[, options], callback)](https://github.com/electron/electron/blob/master/docs/api/app.md#getFileIcon)
- [ ] [shell.openExternal(url[, options, callback])](https://github.com/electron/electron/blob/master/docs/api/shell.md#openExternal)
6 changes: 3 additions & 3 deletions docs/api/shell.md
Expand Up @@ -36,7 +36,7 @@ Open the given file in the desktop's default manner.

### `shell.openExternalSync(url[, options])`

* `url` String - Max 2081 characters on windows, or the function returns false.
* `url` String - Max 2081 characters on Windows, or the function returns false.
* `options` Object (optional)
* `activate` Boolean (optional) - `true` to bring the opened application to the
foreground. The default is `true`. _macOS_
Expand All @@ -48,13 +48,13 @@ Open the given external protocol URL in the desktop's default manner. (For examp

### `shell.openExternal(url[, options])`

* `url` String - Max 2081 characters on windows, or the function returns false.
* `url` String - Max 2081 characters on windows.
* `options` Object (optional)
* `activate` Boolean (optional) - `true` to bring the opened application to the
foreground. The default is `true`. _macOS_
* `workingDirectory` String (optional) - The working directory. _Windows_

Returns `Promise<Any>`
Returns `Promise<void>`

Open the given external protocol URL in the desktop's default manner. (For example, mailto: URLs in the user's default mail agent).

Expand Down
2 changes: 1 addition & 1 deletion docs/api/webview-tag.md
Expand Up @@ -782,7 +782,7 @@ const webview = document.querySelector('webview')
webview.addEventListener('new-window', (e) => {
const protocol = require('url').parse(e.url).protocol
if (protocol === 'http:' || protocol === 'https:') {
shell.openExternal(e.url)
shell.openExternalSync(e.url)
}
})
```
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/security.md
Expand Up @@ -639,7 +639,7 @@ app.on('web-contents-created', (event, contents) => {
// to open this event's url in the default browser.
event.preventDefault()

shell.openExternal(navigationUrl)
shell.openExternalSync(navigationUrl)
})
})
```
Expand Down
4 changes: 3 additions & 1 deletion script/prepare-release.js
Expand Up @@ -60,7 +60,9 @@ async function getReleaseNotes (currentBranch) {
}
console.log(`Generating release notes for ${currentBranch}.`)
const releaseNotes = await releaseNotesGenerator(currentBranch)
if (releaseNotes.warning) console.warn(releaseNotes.warning)
if (releaseNotes.warning) {
console.warn(releaseNotes.warning)
}
return releaseNotes
}

Expand Down
2 changes: 1 addition & 1 deletion spec/api-remote-spec.js
Expand Up @@ -184,7 +184,7 @@ describe('remote module', () => {
assert.strictEqual(typeof remote.app.getPath, 'function')
assert.strictEqual(typeof remote.webContents.getFocusedWebContents, 'function')
assert.strictEqual(typeof remote.clipboard.readText, 'function')
assert.strictEqual(typeof remote.shell.openExternal, 'function')
assert.strictEqual(typeof remote.shell.openExternalSync, 'function')
})

it('returns toString() of original function via toString()', () => {
Expand Down
55 changes: 50 additions & 5 deletions spec/api-shell-spec.js
Expand Up @@ -16,14 +16,55 @@ describe('shell module', () => {
iconIndex: 1
}

// (alexeykuzmin): `.skip()` in `before` doesn't work for nested `describe`s.
beforeEach(function () {
if (process.platform !== 'win32') {
this.skip()
}
describe('shell.openExternal()', () => {
let envVars = {}

beforeEach(() => {
// keep original process.env values to prevent side effect
envVars = {
display: process.env.DISPLAY,
de: process.env.DE,
browser: process.env.BROWSER
}
})

afterEach(() => {
process.env.BROWSER = envVars.browser
process.env.DE = envVars.de
process.env.DISPLAY = envVars.display
})

it('opens an external link asynchronously', function (done) {
if (process.platform !== 'linux') this.skip()

// set env vars for xdg-open
const url = 'http://www.example.com'
process.env.DE = 'generic'
process.env.BROWSER = '/bin/true'
process.env.DISPLAY = ''

shell.openExternal(url).then(() => done())
})

it('opens an external link synchronously', function () {
if (process.platform !== 'linux') this.skip()

// set env vars for xdg-open
const url = 'http://www.example.com'
process.env.DE = 'generic'
process.env.BROWSER = '/bin/true'
process.env.DISPLAY = ''

const success = shell.openExternalSync(url)
assert.strictEqual(true, success)
})
})

describe('shell.readShortcutLink(shortcutPath)', () => {
beforeEach(function () {
if (process.platform !== 'win32') this.skip()
})

it('throws when failed', () => {
assert.throws(() => {
shell.readShortcutLink('not-exist')
Expand All @@ -37,6 +78,10 @@ describe('shell module', () => {
})

describe('shell.writeShortcutLink(shortcutPath[, operation], options)', () => {
beforeEach(function () {
if (process.platform !== 'win32') this.skip()
})

const tmpShortcut = path.join(os.tmpdir(), `${Date.now()}.lnk`)

afterEach(() => {
Expand Down

0 comments on commit feeda28

Please sign in to comment.