Skip to content

Commit

Permalink
Merge pull request #2039 from brave/ca-3805-62
Browse files Browse the repository at this point in the history
[0.62.x] block default chrome url in topsites list
  • Loading branch information
cezaraugusto authored Mar 29, 2019
2 parents b37d2f5 + de36c33 commit 71e776c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
12 changes: 6 additions & 6 deletions components/brave_new_tab_ui/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { bindActionCreators } from 'redux'
import * as newTabActions from './actions/new_tab_actions'
import { debounce } from '../common/debounce'
import store from './store'
import { isHttpOrHttps } from './helpers/newTabUtils'

let actions: any

Expand Down Expand Up @@ -53,14 +52,15 @@ export const fetchBookmarkInfo = (url: string) => {
export const getGridSites = (state: NewTab.State, checkBookmarkInfo?: boolean) => {
const sizeToCount = { large: 18, medium: 12, small: 6 }
const count = sizeToCount[state.gridLayoutSize || 'small']
const defaultChromeUrl = 'https://chrome.google.com/webstore?hl=en'

// Start with top sites with filtered out ignored sites and pinned sites
let gridSites = state.topSites.slice()
.filter((site) =>
!state.ignoredTopSites.find((ignoredSite) => ignoredSite.url === site.url) &&
!state.pinnedTopSites.find((pinnedSite) => pinnedSite.url === site.url) &&
!isHttpOrHttps(site.url)
)
.filter((site) =>
!state.ignoredTopSites.find((ignoredSite) => ignoredSite.url === site.url) &&
!state.pinnedTopSites.find((pinnedSite) => pinnedSite.url === site.url) &&
site.url !== defaultChromeUrl
)

// Then add in pinned sites at the specified index, these need to be added in the same
// order as the index they are.
Expand Down
52 changes: 52 additions & 0 deletions components/test/brave_new_tab_ui/api_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* global describe, it */
/* 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/. */

import { getGridSites } from '../../brave_new_tab_ui/api'

describe('new tab api tests', () => {
const defaultState = {
topSites: [],
ignoredTopSites: [],
pinnedTopSites: [],
bookmarks: {}
}
describe('getGridSites', () => {
it('allows http sites', () => {
const url = 'http://cezaraugusto.net'
const newState = {
...defaultState,
topSites: [
{ url }
]
}
const assertion = getGridSites(newState, true)
expect(assertion[0]).toBe(newState.topSites[0])
expect(assertion[0].url).toBe(url)
})
it('allows https sites', () => {
const url = 'https://cezaraugusto.net'
const newState = {
...defaultState,
topSites: [
{ url }
]
}
const assertion = getGridSites(newState, true)
expect(assertion[0]).toBe(newState.topSites[0])
expect(assertion[0].url).toBe(url)
})
it('do not allow the default chrome topSites url', () => {
const url = 'https://chrome.google.com/webstore?hl=en'
const newState = {
...defaultState,
topSites: [
{ url }
]
}
const assertion = getGridSites(newState, true)
expect(assertion[0]).toBe(undefined)
})
})
})
13 changes: 13 additions & 0 deletions components/test/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ export const getMockChrome = () => {
},
braveRewards: {
getPublisherData: (id: number, url: string, favicon: string) => undefined
},
extension: {
inIncognitoContext: new ChromeEvent()
},
topSites: {
get: function () {
return
}
},
bookmarks: {
search: function () {
return
}
}
}
}
Expand Down

0 comments on commit 71e776c

Please sign in to comment.