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

Commit

Permalink
Ensure non-prefixed active suggestion loads the suggestion when enter…
Browse files Browse the repository at this point in the history
… is hit

Fix #6682

Auditors: @bsclifton
  • Loading branch information
bbondy committed Jan 16, 2017
1 parent d3b0b25 commit 105a1a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/renderer/components/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ class UrlBar extends ImmutableComponent {

get activeIndex () {
if (this.suggestionList === null) {
return 0
return -1
}
return Math.abs(this.selectedIndex % (this.suggestionList.size + 1))
return this.selectedIndex
}

onKeyDown (e) {
Expand All @@ -182,7 +182,7 @@ class UrlBar extends ImmutableComponent {
const isLocationUrl = isUrl(location)
if (!isLocationUrl && e.ctrlKey) {
windowActions.loadUrl(this.activeFrame, `www.${location}.com`)
} else if (this.shouldRenderUrlBarSuggestions && (this.activeIndex > 0 || this.locationValueSuffix && this.autocompleteEnabled)) {
} else if (this.shouldRenderUrlBarSuggestions && (this.activeIndex >= 0 || this.locationValueSuffix && this.autocompleteEnabled)) {
// Hack to make alt enter open a new tab for url bar suggestions when hitting enter on them.
const isDarwin = process.platform === 'darwin'
if (e.altKey) {
Expand Down
10 changes: 10 additions & 0 deletions test/components/urlBarSuggestionsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,14 @@ describe('urlBarSuggestions', function () {
.keys(Brave.keys.CONTROL)
.waitForSelectedText('1.html')
})

it('non-prefixed active suggestion loads the suggestion when enter is pressed', function * () {
yield this.app.client
.setInputText(urlInput, 'pref')
.waitForVisible(urlBarSuggestions)
.keys(Brave.keys.DOWN)
.waitForExist(urlBarSuggestions + ' li.suggestionItem[data-index="0"].selected')
.keys(Brave.keys.ENTER)
.waitForInputText(urlInput, 'about:preferences')
})
})
9 changes: 6 additions & 3 deletions test/lib/brave.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,19 @@ var exports = {
})

this.app.client.addCommand('waitForInputText', function (selector, input) {
this
logVerbose('waitForInputText("' + selector + '", "' + input + '")')
return this
.waitUntil(function () {
return this.getValue(selector).then(function (val) {
return val === input
const ret = val === input
logVerbose('waitForInputText("' + selector + '", "' + input + '") => ' + ret)
return ret
})
})
})

this.app.client.addCommand('setInputText', function (selector, input) {
this
return this
.moveToObject(navigator)
.setValue(selector, input)
.waitForInputText(selector, input)
Expand Down

1 comment on commit 105a1a7

@bsclifton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++! test has me all like 😻

Please sign in to comment.