From 105a1a7ad94cf4d66d464098296ca2cee9e0ef0b Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Mon, 16 Jan 2017 15:41:13 -0500 Subject: [PATCH] Ensure non-prefixed active suggestion loads the suggestion when enter is hit Fix #6682 Auditors: @bsclifton --- app/renderer/components/urlBar.js | 6 +++--- test/components/urlBarSuggestionsTest.js | 10 ++++++++++ test/lib/brave.js | 9 ++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/renderer/components/urlBar.js b/app/renderer/components/urlBar.js index 9f25feed00b..462ea352f25 100644 --- a/app/renderer/components/urlBar.js +++ b/app/renderer/components/urlBar.js @@ -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) { @@ -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) { diff --git a/test/components/urlBarSuggestionsTest.js b/test/components/urlBarSuggestionsTest.js index ac71d3deb00..9381f4f35a6 100644 --- a/test/components/urlBarSuggestionsTest.js +++ b/test/components/urlBarSuggestionsTest.js @@ -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') + }) }) diff --git a/test/lib/brave.js b/test/lib/brave.js index 91578b7090d..db0c3b4a77d 100644 --- a/test/lib/brave.js +++ b/test/lib/brave.js @@ -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)