Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Add tests for extensions getting installed
Browse files Browse the repository at this point in the history
Fix #4080
Fix #4081

Test Plan:
- Completely retest each extension from scratch.
- Try cleaning your userProfileDir/Extensions but not the
  session-store-1 file, things should be recoverable / normal
- Try cleaning your session-store-1, things should be recoverable.
- Try manually setting your session-store-1 for 1passwrod from
  4.5.9.90 to 4.4.9.90 (replace all), edit `~/Library/Application\ Support/brave-development/Extensions/aomjjhallfgjeglblehebfpbcfeobpgk/4.5.9.90/manifest.json`
  and set the version inside the manifest to 4.4.9.90.  Move the
  folder to a subfolder called 4.4.9.90 as well.
- Start up and wait 10 minutes, it should update. Or you can run
  `require('electron').remote.session.defaultSession.updateClient.checkNow('aomjjhallfgjeglblehebfpbcfeobpgk')`
  to force the update.  about:extensions should show the new
  version.
  • Loading branch information
bbondy committed Sep 20, 2016
1 parent 8b56866 commit b61fe96
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 12 deletions.
23 changes: 20 additions & 3 deletions app/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const settings = require('../js/constants/settings')
const {passwordManagers, extensionIds} = require('../js/constants/passwordManagers')
const appStore = require('../js/stores/appStore')
const extensionState = require('./common/state/extensionState')
const fs = require('fs')
const path = require('path')

let generateBraveManifest = () => {
let baseManifest = {
Expand Down Expand Up @@ -173,7 +175,7 @@ module.exports.init = () => {
const extensionPath = extensions.getIn([extensionId, 'filePath'])
// If we don't have info on the extension yet, check for an update / install
if (!extensionPath) {
defaultSession.updateClient.install(extensionId)
defaultSession.updateClient.checkNow(extensionId)
} else {
installExtension(extensionId, extensionPath)
}
Expand All @@ -192,9 +194,24 @@ module.exports.init = () => {
enableExtension(installInfo.id)
}

let installExtension = (extensionId, path, options = {}) => {
let installExtension = (extensionId, extensionPath, options = {}) => {
if (!installedExtensions[extensionId]) {
process.emit('load-extension', path, options, extensionInstalled)
if (extensionId === config.braveExtensionId) {
process.emit('load-extension', extensionPath, options, extensionInstalled)
return
}
// Verify we don't have info about an extension which doesn't exist
// on disk anymore. It will crash if it doesn't exist, so this is
// just a safety net.
fs.exists(path.join(extensionPath, 'manifest.json'), (exists) => {
console.log('paht exists', extensionPath, exists)
if (exists) {
process.emit('load-extension', extensionPath, options, extensionInstalled)
} else {
delete installedExtensions[extensionId]
defaultSession.updateClient.checkNow(extensionId)
}
})
} else {
enableExtension(extensionId)
}
Expand Down
1 change: 1 addition & 0 deletions app/renderer/components/browserActionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class BrowserActionButton extends ImmutableComponent {
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center'
}}
dataButtonValue={this.props.extensionId}
onClick={this.onClicked.bind(this, this.props.extensionId, this.props.browserAction.get('title'))} />
}
}
Expand Down
1 change: 1 addition & 0 deletions js/components/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Button extends ImmutableComponent {
return <span disabled={this.props.disabled}
data-l10n-id={this.props.l10nId}
style={this.props.inlineStyles}
data-button-value={this.props.dataButtonValue}
className={cx({
browserButton: true,
fa: true,
Expand Down
66 changes: 57 additions & 9 deletions test/about/extensionsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
const Brave = require('../lib/brave')
const {urlInput} = require('../lib/selectors')
const {getTargetAboutUrl} = require('../../js/lib/appUrlUtil')
const settingsConst = require('../../js/constants/settings')
const {passwordManagers, extensionIds} = require('../../js/constants/passwordManagers')
const aboutExtensionsUrl = getTargetAboutUrl('about:extensions')

describe('about:extensions', function () {
Brave.beforeAll(this)
before(function * () {
const url = getTargetAboutUrl('about:extensions')
yield this.app.client
function * setup (client) {
yield client
.waitUntilWindowLoaded()
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
Expand All @@ -17,11 +18,58 @@ describe('about:extensions', function () {
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('.tab[data-frame-key="1"]')
.tabByIndex(0)
.url(url)
.url(aboutExtensionsUrl)
}
describe('PDFJS', function () {
Brave.beforeAll(this)
before(function * () {
yield setup(this.app.client)
})
it('installs by default', function * () {
yield this.app.client
.waitForVisible('[data-extension-id="oemmndcbldboiebfnladdacbdfmadadm"]')
})
})

it('lists PDFJS', function * () {
yield this.app.client
.waitForVisible('[data-extension-id="oemmndcbldboiebfnladdacbdfmadadm"]')
describe('1Password', function () {
Brave.beforeAll(this)
before(function * () {
yield setup(this.app.client)
})
it('installs when enabled', function * () {
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.changeSetting(settingsConst.ACTIVE_PASSWORD_MANAGER, passwordManagers.ONE_PASSWORD)
.waitForVisible(`.extensionBrowserAction[data-button-value="${extensionIds[passwordManagers.ONE_PASSWORD]}"]`)
.tabByIndex(0)
.waitForVisible(`[data-extension-id="${extensionIds[passwordManagers.ONE_PASSWORD]}"]`)
})
})
describe('Dashlane installs when enabled', function () {
Brave.beforeAll(this)
before(function * () {
yield setup(this.app.client)
})
it('installs', function * () {
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.changeSetting(settingsConst.ACTIVE_PASSWORD_MANAGER, passwordManagers.DASHLANE)
.waitForVisible(`.extensionBrowserAction[data-button-value="${extensionIds[passwordManagers.DASHLANE]}"]`)
.tabByIndex(0)
.waitForVisible(`[data-extension-id="${extensionIds[passwordManagers.DASHLANE]}"]`)
})
})
describe('LastPass installs when enabled', function () {
Brave.beforeAll(this)
before(function * () {
yield setup(this.app.client)
})
it('installs', function * () {
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.changeSetting(settingsConst.ACTIVE_PASSWORD_MANAGER, passwordManagers.LAST_PASS)
.waitForVisible(`.extensionBrowserAction[data-button-value="${extensionIds[passwordManagers.LAST_PASS]}"]`)
.tabByIndex(0)
.waitForVisible(`[data-extension-id="${extensionIds[passwordManagers.LAST_PASS]}"]`)
})
})
})

0 comments on commit b61fe96

Please sign in to comment.