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

Commit

Permalink
fix syncing error when lastAccessedTime is empty
Browse files Browse the repository at this point in the history
Test Plan: unittests should pass
  • Loading branch information
diracdeltas authored and bsclifton committed Apr 29, 2017
1 parent 2450bac commit c37ed6e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
11 changes: 5 additions & 6 deletions js/state/siteUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,14 +603,13 @@ module.exports.isImportedBookmark = function (siteDetail) {
*/
module.exports.isHistoryEntry = function (siteDetail) {
if (siteDetail && typeof siteDetail.get('location') === 'string') {
if (siteDetail.get('location').startsWith('about:')) {
const tags = siteDetail.get('tags')
if (siteDetail.get('location').startsWith('about:') ||
module.exports.isDefaultEntry(siteDetail) ||
isBookmarkFolder(tags)) {
return false
}
if (module.exports.isDefaultEntry(siteDetail)) {
// This is a Brave default newtab site
return false
}
return !!siteDetail.get('lastAccessedTime') && !isBookmarkFolder(siteDetail.get('tags'))
return !!siteDetail.get('lastAccessedTime') || !tags || tags.size === 0
}
return false
}
Expand Down
11 changes: 6 additions & 5 deletions js/state/syncUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports.getSiteDataFromRecord = (record, appState, records) => {
let existingObjectData

if (record.action !== writeActions.CREATE) {
const existingObject = module.exports.getObjectById(objectId, category,
const existingObject = getObjectById(objectId, category,
appState)
existingObjectData = existingObject && existingObject[1]
}
Expand Down Expand Up @@ -237,7 +237,7 @@ module.exports.getExistingObject = (categoryName, syncRecord) => {
const AppStore = require('../stores/appStore')
const appState = AppStore.getState()
const objectId = new Immutable.List(syncRecord.objectId)
const existingObject = module.exports.getObjectById(objectId, categoryName, appState)
const existingObject = getObjectById(objectId, categoryName, appState)
if (!existingObject) { return null }

const existingObjectKeyPath = existingObject[0]
Expand All @@ -256,7 +256,8 @@ module.exports.getExistingObject = (categoryName, syncRecord) => {
throw new Error(`Invalid category: ${categoryName}`)
}
if (!item) {
throw new Error(`Can't create JS from existingObject! ${existingObjectData}`)
console.log(`Warning: Can't create JS from existingObject! ${JSON.stringify(existingObjectData)}`)
return null
}
return {
action: writeActions.CREATE,
Expand Down Expand Up @@ -314,7 +315,7 @@ module.exports.updateSiteCache = (appState, siteDetail) => {
* @param {Immutable.Map=} appState
* @returns {Array} [<Array>, <Immutable.Map>] array is AppStore searchKeyPath e.g. ['sites', 10] for use with updateIn
*/
module.exports.getObjectById = (objectId, category, appState) => {
const getObjectById = (objectId, category, appState) => {
if (!(objectId instanceof Immutable.List)) {
throw new Error('objectId must be an Immutable.List')
}
Expand Down Expand Up @@ -355,7 +356,7 @@ const getFolderIdByObjectId = (objectId, appState, records) => {
return folderIdMap.get(objectId)
}
let folderId
const entry = module.exports.getObjectById(objectId, 'BOOKMARKS', appState)
const entry = getObjectById(objectId, 'BOOKMARKS', appState)
if (entry) {
folderId = entry[1].get('folderId')
} else if (records) {
Expand Down
7 changes: 7 additions & 0 deletions test/unit/state/siteUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,13 @@ describe('siteUtil', function () {
})
assert.equal(siteUtil.isHistoryEntry(siteDetail), false)
})
it('returns true for a history entry with falsey lastAccessedTime', function () {
const siteDetail = Immutable.fromJS({
location: testUrl1,
tags: []
})
assert.equal(siteUtil.isHistoryEntry(siteDetail), true)
})
it('returns false for a bookmarks folder', function () {
const siteDetail = Immutable.fromJS({
location: testUrl1,
Expand Down
26 changes: 26 additions & 0 deletions test/unit/state/syncUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ describe('syncUtil', () => {
}
assert.deepEqual(syncUtil.createSiteData(bookmark), expectedBookmark)
})

it('site without lastAccessedTime', () => {
const site = {
order: 1207,
count: 15,
partitionNumber: 0,
location: 'https://parsecpizzadelivery.com/',
title: "Parsec Pizza Delivery trailer - A pixelated deliver 'em up",
tags: [],
objectId: [0, 63, 197, 156, 48, 17, 112, 109, 247, 175, 79, 57, 151, 123, 29, 198],
themeColor: 'rgb(5, 5, 5)'
}
const expectedSite = {
name: 'historySite',
objectId: [0, 63, 197, 156, 48, 17, 112, 109, 247, 175, 79, 57, 151, 123, 29, 198],
value: {
creationTime: 0,
customTitle: '',
favicon: '',
lastAccessedTime: 0,
location: 'https://parsecpizzadelivery.com/',
title: "Parsec Pizza Delivery trailer - A pixelated deliver 'em up"
}
}
assert.deepEqual(syncUtil.createSiteData(site), expectedSite)
})
})

describe('ipcSafeObject()', () => {
Expand Down

0 comments on commit c37ed6e

Please sign in to comment.