This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #7144 Fix #7185 Auditors: @bsclifton auxclick is a new event in C55 and up, click is no longer fired for non primary buttons. Unfortunately React doens't have support yet so I had to do it via componentDidUpdate and access to the DOM node.
- Loading branch information
Showing
7 changed files
with
167 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const React = require('react') | ||
const ImmutableComponent = require('../../../js/components/immutableComponent') | ||
const suggestionTypes = require('../../../js/constants/suggestionTypes') | ||
const cx = require('../../../js/lib/classSet') | ||
|
||
class UrlBarSuggestionItem extends ImmutableComponent { | ||
componentDidMount () { | ||
this.node.addEventListener('auxclick', this.props.onClick) | ||
} | ||
componentWillUpdate (nextProps) { | ||
if (!this.props.selected && nextProps.selected) { | ||
this.node.scrollIntoView() | ||
} | ||
} | ||
render () { | ||
return <li data-index={this.props.currentIndex} | ||
onMouseOver={this.props.onMouseOver.bind(this)} | ||
onClick={this.props.onClick} | ||
key={`${this.props.suggestion.location}|${this.props.currentIndex + this.props.i}`} | ||
ref={(node) => { this.node = node }} | ||
className={cx({ | ||
selected: this.props.selected, | ||
suggestionItem: true, | ||
[this.props.suggestion.type]: true | ||
})}> | ||
{ | ||
this.props.suggestion.type !== suggestionTypes.TOP_SITE && this.props.suggestion.title | ||
? <div className='suggestionTitle'>{this.props.suggestion.title}</div> | ||
: null | ||
} | ||
{ | ||
this.props.suggestion.type !== suggestionTypes.SEARCH && this.props.suggestion.type !== suggestionTypes.ABOUT_PAGES | ||
? <div className='suggestionLocation'>{this.props.suggestion.location}</div> | ||
: null | ||
} | ||
</li> | ||
} | ||
} | ||
|
||
module.exports = UrlBarSuggestionItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
test/unit/app/renderer/components/urlBarSuggestionItemTest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
/* global describe, before, after, it */ | ||
|
||
const mockery = require('mockery') | ||
const {mount} = require('enzyme') | ||
const assert = require('assert') | ||
const sinon = require('sinon') | ||
const fakeElectron = require('../../../lib/fakeElectron') | ||
const suggestionTypes = require('../../../../../js/constants/suggestionTypes') | ||
let UrlBarSuggestionItem | ||
require('../../../braveUnit') | ||
|
||
describe('UrlBarSuggestionItem component', function () { | ||
before(function () { | ||
mockery.enable({ | ||
warnOnReplace: false, | ||
warnOnUnregistered: false, | ||
useCleanCache: true | ||
}) | ||
mockery.registerMock('electron', fakeElectron) | ||
UrlBarSuggestionItem = require('../../../../../app/renderer/components/urlBarSuggestionItem') | ||
}) | ||
after(function () { | ||
mockery.disable() | ||
}) | ||
|
||
Object.values(suggestionTypes).forEach((suggestionType) => { | ||
describe(`${suggestionType} suggestion item`, function () { | ||
before(function () { | ||
this.onMouseOver = sinon.spy() | ||
this.onSuggestionClicked = sinon.spy() | ||
this.suggestion = { | ||
title: 'hello', | ||
type: suggestionType, | ||
location: 'http://www.brave.com' | ||
} | ||
this.result = mount(<UrlBarSuggestionItem | ||
suggestion={this.suggestion} | ||
selected | ||
currentIndex={1} | ||
i={0} | ||
onMouseOver={this.onMouseOver} | ||
onClick={this.onSuggestionClicked} | ||
/>) | ||
}) | ||
|
||
it('renders a list item', function () { | ||
assert.equal(this.result.find('li').length, 1) | ||
}) | ||
|
||
it('renders the suggestion title', function () { | ||
if (suggestionType !== suggestionTypes.TOP_SITE) { | ||
assert.equal(this.result.find('.suggestionTitle').length, 1) | ||
assert.equal(this.result.find('.suggestionTitle').text(), this.suggestion.title) | ||
} else { | ||
assert.equal(this.result.find('.suggestionTitle').length, 0) | ||
} | ||
}) | ||
|
||
it('renders a suggestion URL', function () { | ||
if (suggestionType !== suggestionTypes.SEARCH && suggestionType !== suggestionTypes.ABOUT_PAGES) { | ||
assert.equal(this.result.find('.suggestionLocation').length, 1) | ||
assert.equal(this.result.find('.suggestionLocation').text(), this.suggestion.location) | ||
} else { | ||
assert.equal(this.result.find('.suggestionLocation').length, 0) | ||
} | ||
}) | ||
|
||
it('detects mouse moves', function () { | ||
this.result.simulate('click') | ||
assert.ok(this.onSuggestionClicked.calledOnce) | ||
assert.ok(this.onMouseOver.notCalled) | ||
}) | ||
|
||
it('detects mouse moves', function () { | ||
this.result.simulate('mouseover') | ||
assert.ok(this.onMouseOver.calledOnce) | ||
}) | ||
}) | ||
}) | ||
}) |
da801c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of things:
eventUtil
. This is used for cmd + click but also it checks middle click. Some places that may/may not have been missed:Those issues aside, I think routing AuxClick through Click is a great approach 😄
da801c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I grepped for isForSecondaryAction and also for e\.button and got those instances.
da801c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the nodes will be removed from DOM and discarded along with the event listener for that when it isn't needed
da801c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bbondy for example, with the js/contextMenus.js, we only have handlers for click. Are these covered because the only potential caller is js/ContextMenu.js (which you updated to route auxclick => click)?
If those situations are all covered, I think we're good to go 😄 The first one I saw which may have been missed was with regard to menu... not sure if you can middle click menu on macOS
da801c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we only ever supported that in our own custom context menus and those are handled and routed to onClick