Skip to content

Commit

Permalink
spec: add tests for app.set/getUserAgentFallback
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Apr 30, 2019
1 parent 3b39b6e commit e50aa19
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 1 addition & 2 deletions atom/browser/api/atom_api_app.cc
Expand Up @@ -1456,8 +1456,7 @@ void App::BuildPrototype(v8::Isolate* isolate,
#if defined(OS_MACOSX)
.SetProperty("dock", &App::GetDockAPI)
#endif
.SetMethod("setUserAgentFallback", &App::SetUserAgentFallback)
.SetMethod("getUserAgentFallback", &App::GetUserAgentFallback)
.SetProperty("userAgentFallback", &App::GetUserAgentFallback, &App::SetUserAgentFallback)
.SetMethod("enableSandbox", &App::EnableSandbox);
}

Expand Down
9 changes: 9 additions & 0 deletions docs/api/app.md
Expand Up @@ -1373,6 +1373,15 @@ On macOS, setting this with any nonzero integer shows on the dock icon. On Linux
**Note:** Unity launcher requires the existence of a `.desktop` file to work,
for more information please read [Desktop Environment Integration][unity-requirement].

### `app.userAgentFallback`

A `String` which is the user agent string Electron will use as a global fallback.

This is the user agent that will be used when no user agent is set at the
`webContents` or `session` level. Useful for ensuring your entire
app has the same user agent. Set to a custom value as early as possible
in your apps initialization to ensure that your overridden value is used.

### `app.isPackaged`

A `Boolean` property that returns `true` if the app is packaged, `false` otherwise. For many apps, this property can be used to distinguish development and production environments.
Expand Down
24 changes: 24 additions & 0 deletions spec-main/api-app-spec.ts
Expand Up @@ -1310,6 +1310,30 @@ describe('default behavior', () => {
expect(result).to.equal(true)
})
})

describe('user agent fallback', () => {
let initialValue: string

before(() => {
initialValue = app.userAgentFallback!
})

it('should have a reasonable default', () => {
expect(initialValue).to.include(`Electron/${process.versions.electron}`)
expect(initialValue).to.include(`Chrome/${process.versions.chrome}`)
})

it('should be overridable', () => {
app.userAgentFallback = 'test-agent/123'
expect(app.userAgentFallback).to.equal('test-agent/123')
})

it('should be restorable', () => {
app.userAgentFallback = 'test-agent/123'
app.userAgentFallback = ''
expect(app.userAgentFallback).to.equal(initialValue)
})
})
})

async function runTestApp (name: string, ...args: any[]) {
Expand Down
2 changes: 1 addition & 1 deletion spec-main/index.js
Expand Up @@ -80,6 +80,6 @@ app.whenReady().then(() => {
process.exit(runner.failures)
})
}
const runner = (isCI) ? mocha.run(cb) : mocha.forbidOnly().run(cb)
const runner = (isCI) ? mocha.forbidOnly().run(cb) : mocha.run(cb)
})
})

0 comments on commit e50aa19

Please sign in to comment.