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 24, 2016
1 parent c834103 commit 21d28f1
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 32 deletions.
63 changes: 40 additions & 23 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 @@ -141,41 +143,41 @@ let generateBraveManifest = () => {
}

module.exports.init = () => {
const installedExtensions = {}
const loadedExtensions = {}
const registeredExtensions = {}
browserActions.init()

const defaultSession = require('electron').session.defaultSession
defaultSession.updateClient.on('component-checking-for-updates', () => {
const {componentUpdater} = require('electron')
componentUpdater.on('component-checking-for-updates', () => {
// console.log('checking for update')
})
defaultSession.updateClient.on('component-update-found', () => {
componentUpdater.on('component-update-found', () => {
// console.log('update-found')
})
defaultSession.updateClient.on('component-update-ready', () => {
componentUpdater.on('component-update-ready', () => {
// console.log('update-ready')
})
defaultSession.updateClient.on('component-update-updated', (e, extensionId, version) => {
componentUpdater.on('component-update-updated', (e, extensionId, version) => {
// console.log('update-updated', extensionId, version)
})
defaultSession.updateClient.on('component-ready', (e, extensionId, extensionPath) => {
componentUpdater.on('component-ready', (e, extensionId, extensionPath) => {
// console.log('component-ready', extensionId, extensionPath)
// Re-setup the installedExtensions info if it exists
delete installedExtensions[extensionId]
installExtension(extensionId, extensionPath)
// Re-setup the loadedExtensions info if it exists
delete loadedExtensions[extensionId]
loadExtension(extensionId, extensionPath)
})
defaultSession.updateClient.on('component-not-updated', () => {
componentUpdater.on('component-not-updated', () => {
// console.log('update-not-updated')
})
defaultSession.updateClient.on('component-registered', (e, extensionId) => {
componentUpdater.on('component-registered', (e, extensionId) => {
// console.log('component-registered')
const extensions = extensionState.getExtensions(appStore.getState())
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)
componentUpdater.checkNow(extensionId)
} else {
installExtension(extensionId, extensionPath)
loadExtension(extensionId, extensionPath)
}
})

Expand All @@ -185,31 +187,46 @@ module.exports.init = () => {
// TODO(bridiver) extensionActions.extensionInstallFailed
return
}
installedExtensions[installInfo.id] = installInfo
loadedExtensions[installInfo.id] = installInfo
installInfo.filePath = installInfo.base_path
installInfo.base_path = fileUrl(installInfo.base_path)
extensionActions.extensionInstalled(installInfo.id, installInfo)
enableExtension(installInfo.id)
}

let installExtension = (extensionId, path, options = {}) => {
if (!installedExtensions[extensionId]) {
process.emit('load-extension', path, options, extensionInstalled)
let loadExtension = (extensionId, extensionPath, options = {}) => {
if (!loadedExtensions[extensionId]) {
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 loadedExtensions[extensionId]
componentUpdater.checkNow(extensionId)
}
})
} else {
enableExtension(extensionId)
}
}

let enableExtension = (extensionId) => {
var installInfo = installedExtensions[extensionId]
var installInfo = loadedExtensions[extensionId]
if (installInfo) {
process.emit('enable-extension', installInfo.id)
extensionActions.extensionEnabled(installInfo.id)
}
}

let disableExtension = (extensionId) => {
var installInfo = installedExtensions[extensionId]
var installInfo = loadedExtensions[extensionId]
if (installInfo) {
process.emit('disable-extension', installInfo.id)
extensionActions.extensionDisabled(installInfo.id)
Expand All @@ -219,20 +236,20 @@ module.exports.init = () => {
let registerExtension = (extensionId) => {
const extensions = extensionState.getExtensions(appStore.getState())
if (!registeredExtensions[extensionId]) {
defaultSession.updateClient.registerComponent(extensionId)
componentUpdater.registerComponent(extensionId)
registeredExtensions[extensionId] = true
} else {
const extensionPath = extensions.getIn([extensionId, 'filePath'])
if (extensionPath) {
// Otheriwse just install it
installExtension(extensionId, extensionPath)
loadExtension(extensionId, extensionPath)
}
}
}

// Manually install only the braveExtension
registeredExtensions[config.braveExtensionId] = true
installExtension(config.braveExtensionId, getExtensionsPath('brave'), {manifest_location: 'component', manifest: generateBraveManifest()})
loadExtension(config.braveExtensionId, getExtensionsPath('brave'), {manifest_location: 'component', manifest: generateBraveManifest()})

let registerExtensions = () => {
if (getSetting(settings.PDFJS_ENABLED)) {
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 21d28f1

Please sign in to comment.