From 1bc13ba06b77a3b0ea99454feb188707cc2a4e24 Mon Sep 17 00:00:00 2001 From: kevinlawler Date: Mon, 25 Sep 2017 14:42:33 -0700 Subject: [PATCH] extension icons should appear (macOS) changes file:// to chrome://brave Issue brave/browser-laptop#11142 Auditors: @bridiver @diracdeltas @darkdh @jonathansampson fix whitespace add unit test --- app/extensions.js | 6 ++++-- js/lib/appUrlUtil.js | 7 +++++++ test/unit/lib/appUrlUtilTest.js | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/extensions.js b/app/extensions.js index 43251873f62..dffa887a095 100644 --- a/app/extensions.js +++ b/app/extensions.js @@ -4,7 +4,7 @@ const extensionActions = require('./common/actions/extensionActions') const config = require('../js/constants/config') const appConfig = require('../js/constants/appConfig') const messages = require('../js/constants/messages') -const {fileUrl} = require('../js/lib/appUrlUtil') +const {chromeUrl} = require('../js/lib/appUrlUtil') const {getExtensionsPath, getBraveExtUrl, getBraveExtIndexHTML} = require('../js/lib/appUrlUtil') const {getSetting} = require('../js/settings') const settings = require('../js/constants/settings') @@ -393,7 +393,9 @@ module.exports.init = () => { extensionInfo.setState(installInfo.id, extensionStates.ENABLED) extensionInfo.setInstallInfo(installInfo.id, installInfo) installInfo.filePath = installInfo.base_path - installInfo.base_path = fileUrl(installInfo.base_path) + + installInfo.base_path = chromeUrl(installInfo.base_path) + extensionActions.extensionInstalled(installInfo.id, installInfo) extensionActions.extensionEnabled(installInfo.id) }) diff --git a/js/lib/appUrlUtil.js b/js/lib/appUrlUtil.js index 7a6f334307d..24f3b7f5cfc 100644 --- a/js/lib/appUrlUtil.js +++ b/js/lib/appUrlUtil.js @@ -24,6 +24,13 @@ module.exports.fileUrl = (filePath) => { return encodeURI('file://' + fileUrlPath) } +module.exports.chromeUrl = (filePath = '') => { + filePath = module.exports.fileUrl(filePath) + filePath = filePath.replace('file://', 'chrome://brave') + + return filePath +} + /** * Gets the URL of a page hosted by the braveExtension or torrentExtension * Returns 'chrome-extension://<...>' diff --git a/test/unit/lib/appUrlUtilTest.js b/test/unit/lib/appUrlUtilTest.js index b4bfb0863fa..083e8f746fc 100644 --- a/test/unit/lib/appUrlUtilTest.js +++ b/test/unit/lib/appUrlUtilTest.js @@ -79,6 +79,14 @@ describe('appUrlUtil test', function () { assert.equal(fileUrl, expected) }) }) + describe('chromeUrl', function () { + it('can convert file paths', function () { + const filePath = '/users/bbondy/space here/tesT.html' + const chromeUrl = appUrlUtil.chromeUrl(filePath) + const expected = 'chrome://brave/users/bbondy/space%20here/tesT.html' + assert.equal(chromeUrl, expected) + }) + }) describe('newFrameUrl', function () { describe('when NEWTAB_MODE = HOMEPAGE', function () { it('returns the configured home page', function () {