diff --git a/app/browser/api/ledger.js b/app/browser/api/ledger.js index 7c5da224cd6..71672b5bb7c 100644 --- a/app/browser/api/ledger.js +++ b/app/browser/api/ledger.js @@ -707,6 +707,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) @@ -746,6 +747,7 @@ const addSiteVisit = (state, timestamp, location, tabId, manualAdd = false) => { return module.exports.saveVisit(state, publisherKey, { duration, + protocol: protocol, revisited: revisitP }) } @@ -764,7 +766,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 44602b9c6ce..4af3527cb1d 100644 --- a/test/unit/app/browser/api/ledgerTest.js +++ b/test/unit/app/browser/api/ledgerTest.js @@ -1162,6 +1162,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