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

Commit

Permalink
Fix some failing tests post suggestion changes
Browse files Browse the repository at this point in the history
- search suggestions failing test
- tab tests tab transfer can detach into new windows
  • Loading branch information
bbondy committed May 17, 2017
1 parent c4e1fc8 commit abddb25
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 15 deletions.
6 changes: 5 additions & 1 deletion app/browser/reducers/urlBarSuggestionsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {generateNewSuggestionsList, generateNewSearchXHRResults} = require('../..
const {init, add} = require('../../common/lib/siteSuggestions')
const Immutable = require('immutable')
const {makeImmutable} = require('../../common/state/immutableUtil')
const tabState = require('../../common/state/tabState')

const urlBarSuggestionsReducer = (state, action) => {
switch (action.actionType) {
Expand All @@ -30,7 +31,10 @@ const urlBarSuggestionsReducer = (state, action) => {
break
case appConstants.APP_SEARCH_SUGGESTION_RESULTS_AVAILABLE:
state = state.set('searchResults', makeImmutable(action.searchResults))
generateNewSuggestionsList(state, action.windowId, action.tabId)
if (action.query) {
const windowId = tabState.windowId(state, action.tabId)
generateNewSuggestionsList(state, windowId, action.tabId, action.query)
}
break
}
return state
Expand Down
12 changes: 8 additions & 4 deletions app/common/lib/fetchSearchSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@

const appActions = require('../../../js/actions/appActions')
const {request} = require('../../../js/lib/request')
const debounce = require('../../../js/lib/debounce')

const fetchSearchSuggestions = (windowId, tabId, autocompleteURL, searchTerms) => {
const fetchSearchSuggestions = debounce((windowId, tabId, autocompleteURL, searchTerms) => {
autocompleteURL.replace('{searchTerms}', encodeURIComponent(searchTerms))
request(autocompleteURL.replace('{searchTerms}', encodeURIComponent(searchTerms)), (err, response, body) => {
if (err) {
return
}

let searchResults
let query
try {
searchResults = JSON.parse(body)[1]
const parsed = JSON.parse(body)
query = parsed[0]
searchResults = parsed[1]
} catch (e) {
console.warn(e)
return
}

// Once we have the online suggestions, append them to the others
appActions.searchSuggestionResultsAvailable(tabId, searchResults)
appActions.searchSuggestionResultsAvailable(tabId, query, searchResults)
})
}
}, 10)

module.exports = fetchSearchSuggestions
4 changes: 2 additions & 2 deletions app/common/lib/suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ const generateNewSearchXHRResults = debounce((state, windowId, tabId, input) =>
fetchSearchSuggestions(windowId, tabId, autocompleteURL, input)
} else {
const appActions = require('../../../js/actions/appActions')
appActions.searchSuggestionResultsAvailable(tabId, Immutable.List())
appActions.searchSuggestionResultsAvailable(tabId, undefined, Immutable.List())
}
}, 100)
}, 10)

module.exports = {
sortingPriority,
Expand Down
12 changes: 9 additions & 3 deletions app/renderer/components/navigation/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ class UrlBar extends React.Component {
}, 10)
}

maybeUrlBarTextChanged (value) {
if (value !== this.props.locationValue) {
appActions.urlBarTextChanged(getCurrentWindowId(), this.props.activeTabId, value)
}
}

// restores the url bar to the current location
restore () {
const location = UrlUtil.getDisplayLocation(this.props.location, getSetting(settings.PDFJS_ENABLED))
if (this.urlInput) {
this.setValue(location)
}
appActions.urlBarTextChanged(getCurrentWindowId(), this.props.activeTabId, location)
this.maybeUrlBarTextChanged(location)
}

/**
Expand Down Expand Up @@ -300,7 +306,7 @@ class UrlBar extends React.Component {
if (!this.keyPress) {
// if this is a key press don't sent the update until keyUp so
// showAutocompleteResult can handle the result
appActions.urlBarTextChanged(getCurrentWindowId(), this.props.activeTabId, val)
this.maybeUrlBarTextChanged(val)
}
}
}
Expand All @@ -316,7 +322,7 @@ class UrlBar extends React.Component {
windowActions.setUrlBarSelected(false)
}
this.keyPressed = false
appActions.urlBarTextChanged(getCurrentWindowId(), this.props.activeTabId, this.lastVal)
this.maybeUrlBarTextChanged(this.lastVal)
}

select () {
Expand Down
5 changes: 3 additions & 2 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1365,11 +1365,12 @@ const appActions = {
* @param {number} tabId - the tab id for the action
* @param searchResults The search results for the currently entered URL bar text.
*/
searchSuggestionResultsAvailable: function (tabId, searchResults) {
searchSuggestionResultsAvailable: function (tabId, query, searchResults) {
dispatch({
actionType: appConstants.APP_SEARCH_SUGGESTION_RESULTS_AVAILABLE,
tabId,
searchResults
searchResults,
query
})
},

Expand Down
2 changes: 1 addition & 1 deletion js/dispatcher/appDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ if (process.type === 'browser') {
let queryInfo = payload.queryInfo || payload.frameProps || (payload.queryInfo = {})
queryInfo = queryInfo.toJS ? queryInfo.toJS() : queryInfo
let sender = event.sender
if (!queryInfo.alreadyHandledByRenderer && !sender.isDestroyed()) {
if (!sender.isDestroyed()) {
const hostWebContents = sender.hostWebContents
sender = hostWebContents || sender
const win = require('electron').BrowserWindow.fromWebContents(sender)
Expand Down
3 changes: 2 additions & 1 deletion js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ let windowState = Immutable.fromJS({
closedFrames: [],
ui: {
tabs: {
tabPageIndex: 0
},
mouseInTitlebar: false,
menubar: {
Expand Down Expand Up @@ -796,7 +797,7 @@ const dispatchEventPayload = (e, payload) => {
queryInfo.windowId = getCurrentWindowId()
}
// handle any ipc dispatches that are targeted to this window
if (queryInfo.windowId && queryInfo.windowId === getCurrentWindowId()) {
if (queryInfo.windowId && queryInfo.windowId === getCurrentWindowId() && !queryInfo.alreadyHandledByRenderer) {
doAction(payload)
}
}
Expand Down
17 changes: 16 additions & 1 deletion test/navbar-components/urlBarSuggestionsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,22 @@ describe('search suggestions', function () {
it('Finds search suggestions and performs a search when selected', function * () {
yield this.app.client
.changeSetting(settings.OFFER_SEARCH_SUGGESTIONS, true)
.setInputText(urlInput, 'what is')

// Until a refactor happens with search suggestions,
// they are a bit fragile if you aren't actually typing.
// So this for loop avoids an intermittent failure.
// I also couldn't use .typeText() because the autocomplete makes
// that hang when it checks for the value that was typed.
// The refactor needed is to allow urlbar suggestions to be built
// in parts and then rendered together, so that different suggestion
// types would be combined and rendered together as they are available.
const input = 'what is'
for (let i = 0; i < input.length; i++) {
yield this.app.client
.keys(input[i])
.pause(50)
}
yield this.app.client
.waitForVisible(urlBarSuggestions)
.keys(Brave.keys.DOWN)
.waitForExist(urlBarSuggestions + ' li.suggestionItem[data-index="0"]:not(.selected)')
Expand Down

0 comments on commit abddb25

Please sign in to comment.