diff --git a/app/renderer/components/navigation/urlBar.js b/app/renderer/components/navigation/urlBar.js index 7a5490b404..cdaf97b764 100644 --- a/app/renderer/components/navigation/urlBar.js +++ b/app/renderer/components/navigation/urlBar.js @@ -247,6 +247,13 @@ class UrlBar extends React.Component { this.lastSuffix = '' } + // if there is no selection then we are not in autocomplete + // so make sure that this.lastValue is set to urlInput.value + if (this.urlInput.selectionStart === this.urlInput.selectionEnd) { + this.lastVal = this.urlInput.value + this.lastSuffix = '' + } + const selectionStart = this.urlInput.selectionStart const newValue = [ this.lastVal.slice(0, selectionStart), diff --git a/test/lib/brave.js b/test/lib/brave.js index c87ff33a3b..3014ba71c1 100644 --- a/test/lib/brave.js +++ b/test/lib/brave.js @@ -106,6 +106,8 @@ var exports = { SHIFT: '\ue008', BACKSPACE: '\ue003', DELETE: '\ue017', + LEFT: '\ue012', + RIGHT: '\ue014', DOWN: '\ue015', UP: '\ue013', PAGEDOWN: '\uE00F', diff --git a/test/navbar-components/urlBarTest.js b/test/navbar-components/urlBarTest.js index f1dc807504..7e14665d1e 100644 --- a/test/navbar-components/urlBarTest.js +++ b/test/navbar-components/urlBarTest.js @@ -69,115 +69,262 @@ describe('urlBar tests', function () { .addSite({ location: 'http://uncrate.com' }) }) - it('un does not autocomplete to undefined', function * () { - yield this.app.client - .keys('un') - .waitForInputText(urlInput, 'uncrate.com') + describe('press backspace key', function () { + beforeEach(function * () { + yield this.app.client + .setInputText(urlInput, '') + .keys('br') + .waitForInputText(urlInput, 'brave.com') + .waitForSelectedText('ave.com') + .keys(Brave.keys.BACKSPACE) + }) + + it('clears the selection', function * () { + yield this.app.client + .waitForSelectedText('') + }) + + it('removes the autocomplete value', function * () { + yield this.app.client + .waitForInputText(urlInput, 'br') + }) + + describe('with typing', function () { + beforeEach(function * () { + yield this.app.client + .keys('x') + }) + + it('has no selection', function * () { + yield this.app.client + .waitForSelectedText('') + }) + + it('inserts typing at the current cursor location', function * () { + yield this.app.client + .waitForInputText(urlInput, 'brx') + }) + }) }) - it('autocompletes without protocol', function * () { - // now type something - yield this.app.client - .setInputText(urlInput, '') - .keys('br') - .waitForInputText(urlInput, 'brave.com') + describe('press left arrow key', function () { + beforeEach(function * () { + yield this.app.client + .setInputText(urlInput, '') + .keys('br') + .waitForInputText(urlInput, 'brave.com') + .waitForSelectedText('ave.com') + .keys(Brave.keys.LEFT) + }) + + it('clears the selection', function * () { + yield this.app.client + .waitForSelectedText('') + }) + + it('keeps the autocomplete value', function * () { + yield this.app.client + .waitForInputText(urlInput, 'brave.com') + }) + + describe('with typing', function () { + beforeEach(function * () { + yield this.app.client + .keys('a') + }) + + it('has no selection', function * () { + yield this.app.client + .waitForSelectedText('') + }) + + it('inserts typing at the current cursor location', function * () { + yield this.app.client + .waitForInputText(urlInput, 'braave.com') + }) + }) }) - it('autocompletes with protocol', function * () { - // now type something - yield this.app.client - .keys('https://br') - .waitForInputText(urlInput, 'https://brave.com') + describe('press right arrow key', function () { + beforeEach(function * () { + yield this.app.client + .setInputText(urlInput, '') + .keys('br') + .waitForInputText(urlInput, 'brave.com') + .waitForSelectedText('ave.com') + .keys(Brave.keys.RIGHT) + }) + + it('clears the selection', function * () { + yield this.app.client + .waitForSelectedText('') + }) + + it('keeps the autocomplete value', function * () { + yield this.app.client + .waitForInputText(urlInput, 'brave.com') + }) + + describe('with typing', function () { + beforeEach(function * () { + yield this.app.client + .keys('a') + }) + + it('has no selection', function * () { + yield this.app.client + .waitForSelectedText('') + }) + + it('inserts typing at the current cursor location', function * () { + yield this.app.client + .waitForInputText(urlInput, 'brave.coma') + }) + }) }) - it('autocompletes without www.', function * () { - // now type something - yield this.app.client - .keys('you') - .waitForInputText(urlInput, 'youtube.com') + describe('press escape key', function () { + beforeEach(function * () { + this.page = Brave.server.url('page1.html') + return yield this.app.client + .tabByIndex(0) + .loadUrl(this.page) + .windowByUrl(Brave.browserWindowUrl) + .ipcSend('shortcut-focus-url') + .waitForElementFocus(urlInput) + .setValue(urlInput, 'google') + .waitForExist(urlBarSuggestions + ' li') + .keys(Brave.keys.ESCAPE) + .waitForElementFocus(urlInput) + }) + + it('does select the urlbar text', function * () { + yield selectsText(this.app.client, this.page) + }) + + it('does revert the urlbar text', function * () { + yield this.app.client.waitForInputText(urlInput, this.page) + }) }) - it('autofills from selected suggestion', function * () { - // now type something - yield this.app.client - .keys('https://br') - .waitForInputText(urlInput, 'https://brave.com') - // hit down - .keys(Brave.keys.DOWN) - .waitForInputText(urlInput, 'https://brave.com/test') - // hit up - .keys(Brave.keys.UP) - .waitForInputText(urlInput, 'https://brave.com') + describe('type "un"', function () { + it('un does not autocomplete to undefined', function * () { + yield this.app.client + .keys('un') + .waitForInputText(urlInput, 'uncrate.com') + }) }) - it('autocompletes without losing characters', function * () { - yield this.app.client - .keys('a\uE008\uE008b\uE008\uE008o\uE008\uE008u\uE008\uE008t\uE008\uE008x') - .waitForInputText(urlInput, 'aboutx') + describe('start typing url without protocol', function () { + it('autocompletes without protocol', function * () { + // now type something + yield this.app.client + .setInputText(urlInput, '') + .keys('br') + .waitForInputText(urlInput, 'brave.com') + }) }) - it('does not show suggestions on focus', function * () { - yield this.app.client - .keys('brave') - .waitForVisible(urlBarSuggestions, 1) - .ipcSend('shortcut-focus-url') - .waitForElementFocus(urlInput) - .waitForElementCount(urlBarSuggestions, 0) + describe('start typing url with protocol', function () { + it('autocompletes with protocol', function * () { + // now type something + yield this.app.client + .keys('https://br') + .waitForInputText(urlInput, 'https://brave.com') + }) + }) + + describe('start typing url without wwww', function () { + it('autocompletes without www.', function * () { + // now type something + yield this.app.client + .keys('you') + .waitForInputText(urlInput, 'youtube.com') + }) + }) + + describe('highlight suggestions', function () { + it('autofills from selected suggestion', function * () { + // now type something + yield this.app.client + .keys('https://br') + .waitForInputText(urlInput, 'https://brave.com') + // hit down + .keys(Brave.keys.DOWN) + .waitForInputText(urlInput, 'https://brave.com/test') + // hit up + .keys(Brave.keys.UP) + .waitForInputText(urlInput, 'https://brave.com') + }) + }) + + describe('type non-visible keys', function () { + it('autocompletes without losing characters', function * () { + // ue008 is left shift + yield this.app.client + .keys('a\uE008\uE008b\uE008\uE008o\uE008\uE008u\uE008\uE008t\uE008\uE008x') + .waitForInputText(urlInput, 'aboutx') + }) }) - describe('with scrolling match', function () { - it('typing in the urlbar should override mouse hover for suggestions', function * () { + describe('focus urlbar', function () { + it('does not show suggestions', function * () { yield this.app.client - .addSite({ location: 'https://brave.com/test2' }) - .addSite({ location: 'https://brave.com/test3' }) - .addSite({ location: 'https://brave.com/test4' }) - .addSite({ location: 'https://brianbondy.com/test4' }) - .resizeWindow(500, 300) - .setValue(urlInput, 'b') - .waitForVisible(urlBarSuggestions) - // highlight for autocomplete brianbondy.com - .moveToObject(urlBarSuggestions, 0, 100) - yield selectsText(this.app.client, 'rianbondy.com') - .keys('ra') - .execute(function (urlBarSuggestions) { - document.querySelector(urlBarSuggestions).scrollTop = 200 - }, urlBarSuggestions) - yield selectsText(this.app.client, 've.com') + .keys('brave') + .waitForVisible(urlBarSuggestions, 1) + .ipcSend('shortcut-focus-url') + .waitForElementFocus(urlInput) + .waitForElementCount(urlBarSuggestions, 0) }) }) }) + describe('with scrolling match', function () { + Brave.beforeEach(this) + + it('typing in the urlbar should override mouse hover for suggestions', function * () { + yield this.app.client + .addSite({ location: 'https://brave.com', title: 'Brave' }) + .addSite({ location: 'https://brave.com/test' }) + .addSite({ location: 'https://brave.com/test2' }) + .addSite({ location: 'https://brave.com/test3' }) + .addSite({ location: 'https://brave.com/test4' }) + .addSite({ location: 'https://brianbondy.com/test4' }) + .resizeWindow(500, 300) + .setValue(urlInput, 'b') + .waitForVisible(urlBarSuggestions) + // highlight for autocomplete brianbondy.com + .moveToObject(urlBarSuggestions, 0, 100) + yield selectsText(this.app.client, 'rianbondy.com') + .keys('ra') + .execute(function (urlBarSuggestions) { + document.querySelector(urlBarSuggestions).scrollTop = 200 + }, urlBarSuggestions) + yield selectsText(this.app.client, 've.com') + }) + }) + describe('typing', function () { - Brave.beforeAll(this) + Brave.beforeEach(this) - before(function * () { + beforeEach(function * () { yield setup(this.app.client) yield this.app.client.waitForExist(urlInput) yield this.app.client.waitForElementFocus(urlInput) .waitForInputText(urlInput, '') - - yield this.app.client - .addSite({ location: 'https://brave.com', title: 'Brave' }) - - // now type something - yield this.app.client - .setValue(urlInput, 'b') - .waitForExist(urlBarSuggestions + ' li') + .setValue(urlInput, 'br') }) - it('sets the value to "b"', function * () { - yield this.app.client.waitForInputText(urlInput, 'brave.com') + it('sets the value to "br"', function * () { + yield this.app.client.waitForInputText(urlInput, 'br') }) it('clears the selected text', function * () { - // Since now the first letter will trigger the autocomplete - // expect the selected text to be part of the first suggestion - // in the list - yield selectsText(this.app.client, 'rave.com') + yield selectsText(this.app.client, '') }) describe('shortcut-focus-url', function () { - before(function * () { + beforeEach(function * () { yield this.app.client .ipcSend('shortcut-focus-url') }) @@ -187,9 +334,7 @@ describe('urlBar tests', function () { }) it('selects the text', function * () { - // Since now the first letter will trigger the autocomplete - // expect the selected text to be the first suggestion in the list - yield selectsText(this.app.client, 'brave.com') + yield selectsText(this.app.client, 'br') }) it('has the search icon', function * () { @@ -197,54 +342,71 @@ describe('urlBar tests', function () { }) }) - describe('type escape once with suggestions', function () { - before(function * () { - this.page = Brave.server.url('page1.html') - return yield this.app.client - .tabByIndex(0) - .loadUrl(this.page) - .windowByUrl(Brave.browserWindowUrl) - .ipcSend('shortcut-focus-url') - .waitForElementFocus(urlInput) - .setValue(urlInput, 'google') - .waitForExist(urlBarSuggestions + ' li') - - .keys(Brave.keys.ESCAPE) - .waitForElementFocus(urlInput) + describe('press left arrow key', function () { + beforeEach(function * () { + yield this.app.client + .keys(Brave.keys.LEFT) }) - it('does select the urlbar text', function * () { - yield selectsText(this.app.client, this.page) + + it('clears the selection', function * () { + yield this.app.client + .waitForSelectedText('') }) - it('does revert the urlbar text', function * () { - yield this.app.client.waitForInputText(urlInput, this.page) + describe('with typing', function () { + beforeEach(function * () { + yield this.app.client + .keys('x') + }) + + it('has no selection', function * () { + yield this.app.client + .waitForSelectedText('') + }) + + it('inserts typing at the current cursor location', function * () { + yield this.app.client + .waitForInputText(urlInput, 'bxr') + }) }) }) - describe('type escape once with no suggestions', function () { - before(function * () { - this.page = Brave.server.url('page1.html') - return yield this.app.client - .tabByIndex(0) - .loadUrl(this.page) - .windowByUrl(Brave.browserWindowUrl) - .ipcSend('shortcut-focus-url') - .waitForElementFocus(urlInput) - .setValue(urlInput, 'random-uuid-d63ecb78-eec8-4c08-973b-fb39cb5a6f1a') - .keys(Brave.keys.ESCAPE) - .waitForElementFocus(urlInput) + describe('press backspace key', function () { + beforeEach(function * () { + yield this.app.client + .keys(Brave.keys.BACKSPACE) }) - it('does select the urlbar text', function * () { - yield selectsText(this.app.client, this.page) + + it('clears the selection', function * () { + yield this.app.client + .waitForSelectedText('') }) - it('does revert the urlbar text', function * () { - yield this.app.client.waitForInputText(urlInput, this.page) + it('deletes the last character', function * () { + yield this.app.client + .waitForInputText(urlInput, 'b') + }) + + describe('with typing', function () { + beforeEach(function * () { + yield this.app.client + .keys('x') + }) + + it('has no selection', function * () { + yield this.app.client + .waitForSelectedText('') + }) + + it('inserts typing at the current cursor location', function * () { + yield this.app.client + .waitForInputText(urlInput, 'bx') + }) }) }) - describe('type escape twice', function () { - before(function * () { + describe('press escape', function () { + beforeEach(function * () { this.page = Brave.server.url('page1.html') return yield this.app.client .tabByIndex(0) @@ -252,24 +414,21 @@ describe('urlBar tests', function () { .windowByUrl(Brave.browserWindowUrl) .ipcSend('shortcut-focus-url') .waitForElementFocus(urlInput) - .setValue(urlInput, 'blah') - // hit escape + .setValue(urlInput, 'random-uuid-d63ecb78-eec8-4c08-973b-fb39cb5a6f1a') .keys(Brave.keys.ESCAPE) .waitForElementFocus(urlInput) - .keys(Brave.keys.ESCAPE) }) - - it('selects the urlbar text', function * () { + it('does select the urlbar text', function * () { yield selectsText(this.app.client, this.page) }) - it('sets the urlbar text to the webview src', function * () { + it('does revert the urlbar text', function * () { yield this.app.client.waitForInputText(urlInput, this.page) }) }) describe('submitting by typing a URL', function () { - before(function * () { + beforeEach(function * () { const url = Brave.server.url('page1.html') return yield this.app.client.ipcSend('shortcut-focus-url') .setValue(urlInput, url)