diff --git a/app/browser/api/ledger.js b/app/browser/api/ledger.js index 15d739bb539..cf0a25a579d 100644 --- a/app/browser/api/ledger.js +++ b/app/browser/api/ledger.js @@ -714,6 +714,7 @@ const addSiteVisit = (state, timestamp, location, tabId, manualAdd = false) => { return state } + const protocol = urlParse(location).protocol location = pageDataUtil.getInfoKey(location) const minimumVisitTime = getSetting(settings.PAYMENTS_MINIMUM_VISIT_TIME) @@ -753,6 +754,7 @@ const addSiteVisit = (state, timestamp, location, tabId, manualAdd = false) => { return module.exports.saveVisit(state, publisherKey, { duration, + protocol: protocol, revisited: revisitP }) } @@ -771,7 +773,11 @@ const saveVisit = (state, publisherKey, options) => { revisitP: options.revisited, ignoreMinTime: options.ignoreMinTime || false }) + state = ledgerState.setPublisher(state, publisherKey, synopsis.publishers[publisherKey]) + if (options.protocol) { + state = ledgerState.setPublishersProp(state, publisherKey, 'protocol', options.protocol) + } state = updatePublisherInfo(state) state = module.exports.checkVerifiedStatus(state, publisherKey) diff --git a/test/unit/app/browser/api/ledgerTest.js b/test/unit/app/browser/api/ledgerTest.js index 36f37cc2e14..4638ce7be24 100644 --- a/test/unit/app/browser/api/ledgerTest.js +++ b/test/unit/app/browser/api/ledgerTest.js @@ -1163,6 +1163,52 @@ describe('ledger api unit tests', function () { assert(visitsByPublisher['clifton.io']) }) }) + describe('saveVisit', function () { + let setPublishersPropSpy + + before(function () { + setPublishersPropSpy = sinon.spy(ledgerState, 'setPublishersProp') + }) + + beforeEach(function () { + ledgerApi.setSynopsis({ + addPublisher: () => {}, + options: {}, + publishers: {} + }) + }) + + afterEach(function () { + setPublishersPropSpy.reset() + ledgerApi.setSynopsis(undefined) + }) + + after(function () { + setPublishersPropSpy.restore() + }) + + it('sets https as protocol for secure site', function () { + const options = { + duration: 5500, + protocol: 'https:', + revisited: false + } + const result = ledgerApi.saveVisit(defaultAppState, 'brave.com', options) + assert.equal('https:', setPublishersPropSpy.getCall(0).args[3]) + assert.equal('https:', result.getIn(['ledger', 'synopsis', 'publishers', 'brave.com', 'protocol'])) + }) + + it('sets http as protocol for non-secure site', function () { + const options = { + duration: 5500, + protocol: 'http:', + revisited: false + } + const result = ledgerApi.saveVisit(defaultAppState, 'espn.com', options) + assert.equal('http:', setPublishersPropSpy.getCall(0).args[3]) + assert.equal('http:', result.getIn(['ledger', 'synopsis', 'publishers', 'espn.com', 'protocol'])) + }) + }) describe('addNewLocation', function () { const tabIdNone = -1 const keepInfo = false