Skip to content

Commit

Permalink
add desktop-gui warning when launching browser
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Jun 6, 2019
1 parent 1101890 commit 890e59a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
26 changes: 26 additions & 0 deletions packages/desktop-gui/cypress/integration/project_nav_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,32 @@ describe "Project Nav", ->
cy.get(".browsers-list")
.find(".dropdown-toggle").should("not.be.visible")

describe "browser has a warning attached", ->
beforeEach ->
@browsers = [{
"name": "chromium",
"displayName": "Chromium",
"family": "chrome",
"version": "49.0.2609.0",
"path": "/Users/bmann/Downloads/chrome-mac/Chromium.app/Contents/MacOS/Chromium",
"majorVersion": "49",
"warnBadPolicy": true
}]

@config.browsers = @browsers
@openProject.resolve(@config)

it "shows warning icon with tooltip", ->
cy.get(".browsers .fa-exclamation-triangle")
.then ($el) ->
$el[0].dispatchEvent(new Event("mouseover", {bubbles: true}))
cy.get(".cy-tooltip")
.should("contain", "Cypress detected policy settings on your system that may interfere with using this browser.")
.get(".browser-info-tooltip a")
.click()
.then =>
expect(@ipc.externalOpen).to.be.calledWith('https://on.cypress.io/error-messages#bad-policy-settings')

describe "custom browser available", ->
beforeEach ->
@config.browsers.push({
Expand Down
6 changes: 6 additions & 0 deletions packages/desktop-gui/src/app/nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@
margin-right: 4px;
}

.nav .browser-warning {
color: $red-primary;
margin-left: 6px;
margin-right: 4px;
}

.browser-info-tooltip {
background: #ececec;
border-color: #c7c7c7;
Expand Down
2 changes: 2 additions & 0 deletions packages/desktop-gui/src/lib/browser-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class Browser {
@observable majorVersion
@observable info
@observable custom
@observable warnBadPolicy
@observable isChosen = false

constructor (browser) {
Expand All @@ -20,6 +21,7 @@ export default class Browser {
this.majorVersion = browser.majorVersion
this.info = browser.info
this.custom = browser.custom
this.warnBadPolicy = browser.warnBadPolicy
}

@computed get icon () {
Expand Down
25 changes: 25 additions & 0 deletions packages/desktop-gui/src/project-nav/browsers.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react'
import ipc from '../lib/ipc'
import { observer } from 'mobx-react'
import Tooltip from '@cypress/react-tooltip'
import Dropdown from '../dropdown/dropdown'
Expand Down Expand Up @@ -73,11 +74,35 @@ export default class Browsers extends Component {
{prefixText}{' '}
{browser.displayName}{' '}
{browser.majorVersion}
{this._warnBadPolicy(browser)}
{this._info(browser)}
</span>
)
}

_warnBadPolicy (browser) {
if (!browser.warnBadPolicy) return null

return (
<span className='browser-warning'>
<Tooltip
title={
<>
Cypress detected policy settings on your system that may interfere with using this browser.
<a onClick={() => ipc.externalOpen('https://on.cypress.io/error-messages#bad-policy-settings')}>
{' '}See the documentation for more info and workarounds.
</a>
</>
}
placement='bottom'
className='browser-info-tooltip cy-tooltip'
>
<i className='fa fa-exclamation-triangle' />
</Tooltip>
</span>
)
}

_info (browser) {
if (!browser.info) return null

Expand Down
9 changes: 7 additions & 2 deletions packages/server/lib/gui/events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,17 @@ handleEvent = (options, bus, event, id, type, arg) ->
onWarning = (warning) ->
bus.emit("project:warning", errors.clone(warning, {html: true}))

chromePolicyCheck.run(onWarning)

browsers.getAllBrowsersWith(options.browser)
.then (browsers = []) ->
options.config = _.assign(options.config, { browsers })
.then ->
chromePolicyCheck.run (err) ->
options.config.browsers.forEach (browser) ->
if browser.family == 'chrome'
browser.warnBadPolicy = true

onWarning(err)

openProject.create(arg, options, {
onFocusTests: onFocusTests
onSpecChanged: onSpecChanged
Expand Down

0 comments on commit 890e59a

Please sign in to comment.