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

Commit 85fdcfa

Browse files
committed
Call show paste options in context menu (if clipboard has contents)
This was a regression that I unintentionally introduced with 40fc107 Fixes #8000 Auditors: @lukemulks, @alexwykoff Test Plan: 1. Visit a page with a text box (ex: create an issue on browser-laptop) 2. Type text into a textbox 3. Use the mouse to select and cut the text 4. Right click to open a context menu inside the textbox 5. You should now see paste again
1 parent 7c2e101 commit 85fdcfa

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

js/contextMenus.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ function getMisspelledSuggestions (selection, isMisspelled, suggestions) {
650650
}
651651

652652
function getEditableItems (selection, editFlags, hasFormat) {
653-
const hasSelection = selection.length > 0
653+
const hasSelection = selection && selection.length > 0
654654
const hasClipboard = clipboard.readText().length > 0
655655
const template = []
656656

@@ -1026,10 +1026,7 @@ function mainTemplateInit (nodeProps, frame, tab) {
10261026
}
10271027
}
10281028

1029-
const editableItems = nodeProps.selectionText
1030-
? getEditableItems(nodeProps.selectionText, nodeProps.editFlags, true)
1031-
: []
1032-
1029+
const editableItems = getEditableItems(nodeProps.selectionText, nodeProps.editFlags, true)
10331030
template.push(...misspelledSuggestions, {
10341031
label: locale.translation('undo'),
10351032
accelerator: 'CmdOrCtrl+Z',

test/unit/js/contextMenusTest.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
const mockery = require('mockery')
77
const assert = require('assert')
88
const sinon = require('sinon')
9+
const fakeElectron = require('../lib/fakeElectron')
910
let fakeElectronMenu
1011
let contextMenus
1112
require('../braveUnit')
@@ -21,7 +22,7 @@ describe('Context menu module unit tests', function () {
2122
warnOnUnregistered: false,
2223
useCleanCache: true
2324
})
24-
mockery.registerMock('electron', require('../lib/fakeElectron'))
25+
mockery.registerMock('electron', fakeElectron)
2526
mockery.registerMock('../js/l10n', fakeLocale)
2627
contextMenus = require('../../../js/contextMenus')
2728
fakeElectronMenu = require('../lib/fakeElectronMenu')
@@ -33,16 +34,35 @@ describe('Context menu module unit tests', function () {
3334

3435
describe('onMainContextMenu', function () {
3536
describe('when calling mainTemplateInit', function () {
37+
let clipboardReadTextSpy
38+
let menuBuildFromTemplateSpy
3639
let menuPopupSpy
3740
let menuDestroySpy
3841

3942
before(function () {
43+
clipboardReadTextSpy = sinon.spy(fakeElectron.remote.clipboard, 'readText')
44+
menuBuildFromTemplateSpy = sinon.spy(fakeElectron.remote.Menu, 'buildFromTemplate')
4045
menuPopupSpy = sinon.spy(fakeElectronMenu, 'popup')
4146
menuDestroySpy = sinon.spy(fakeElectronMenu, 'destroy')
4247
})
4348

4449
after(function () {
50+
clipboardReadTextSpy.restore()
51+
menuBuildFromTemplateSpy.restore()
4552
menuPopupSpy.restore()
53+
menuDestroySpy.restore()
54+
})
55+
56+
it('calls clipboard.readText', function () {
57+
clipboardReadTextSpy.reset()
58+
contextMenus.onMainContextMenu()
59+
assert.equal(clipboardReadTextSpy.calledOnce, true)
60+
})
61+
62+
it('calls Menu.buildFromTemplate', function () {
63+
menuBuildFromTemplateSpy.reset()
64+
contextMenus.onMainContextMenu()
65+
assert.equal(menuBuildFromTemplateSpy.calledOnce, true)
4666
})
4767

4868
it('calls menu.popup', function () {

test/unit/lib/fakeElectron.js

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const fakeElectron = {
1515
on: function () {
1616
}
1717
},
18+
clipboard: {
19+
readText: function () { return '' }
20+
},
1821
getCurrentWindow: function () {
1922
return {
2023
on: () => {},

0 commit comments

Comments
 (0)