From b61fe9644544069c744de06ba20631f7660da976 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Mon, 19 Sep 2016 04:37:18 -0400 Subject: [PATCH] Add tests for extensions getting installed 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. --- app/extensions.js | 23 ++++++- .../components/browserActionButton.js | 1 + js/components/button.js | 1 + test/about/extensionsTest.js | 66 ++++++++++++++++--- 4 files changed, 79 insertions(+), 12 deletions(-) diff --git a/app/extensions.js b/app/extensions.js index ce530a92172..b2fe1b1ce4a 100644 --- a/app/extensions.js +++ b/app/extensions.js @@ -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 = { @@ -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) } @@ -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) } diff --git a/app/renderer/components/browserActionButton.js b/app/renderer/components/browserActionButton.js index d1a856d1e65..acd42a0fe23 100644 --- a/app/renderer/components/browserActionButton.js +++ b/app/renderer/components/browserActionButton.js @@ -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'))} /> } } diff --git a/js/components/button.js b/js/components/button.js index bd9c2e7974e..bce5a99d10f 100644 --- a/js/components/button.js +++ b/js/components/button.js @@ -12,6 +12,7 @@ class Button extends ImmutableComponent { return