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

Fixes publisher not added to the ledger #11592

Merged
merged 2 commits into from
Oct 23, 2017

Conversation

NejcZdovc
Copy link
Contributor

@NejcZdovc NejcZdovc commented Oct 18, 2017

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.

Resolves #11553 - Publishers auto-included even with auto-include switch disabled
Resolves #11575 - Page data refactor
Resolves #11273 - Ledger table doesn't auto populate the publishers
Resolves #11274 - Site not added to publisher list even after spending ~10 mins on the site

Auditors:

Test Plan:

for every test plan you need to clean your profile and enable payments

Plan A

  • open preferences, go to payments
  • open a new tab
  • load a site
  • stay on that site for 15s
  • switch to preference tab and site should be added

Plan B

  • open preferences, go to payments
  • open a new tab
  • load a site
  • stay on that site for 15s
  • open a a new tab
  • switch to preference tab and site should be added

Plan C
- do plan B
- switch to the site tab and stay on it for 15s
- open new tab and visit different site for 15s
- switch to preference tab and new site should be added and old site should have 2 visits
Plan C is not valid, please check plan E

Plan D

  • open preferences, go to payments
  • change min visit time to 1min
  • open new tab
  • load a site stay on that site for 15s
  • open another app (so that focus will be out)
  • click back on opened site in brave and wait for 1m
  • switch to preference tab and site should be added

Plan E

  • do plan B
  • go back to site tab and stay on that site for 15s
  • switch to preference tab and site should have 1 visit, but 20+ seconds visit time

Plan F

  • Open preferences, go to payments
  • Disable auto-include settings
  • Visit some random sites so that the sites are added to the ledger table
  • Ensure no site is auto included that gets added to the table

Plan G

  • open preferences, go to payments
  • open a new tab
  • load a site stay on that site for 15s
  • open a private tab
  • load a new site stay on that site for 15s
  • switch to preference tab and table should only contain site visited in normal tab and not from private tab

Plan H

  • do plan A
  • disable payments
  • visit few more sites in new tabs
  • switch to preference tab and ledger table should only have site from plan A

Reviewer Checklist:

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

@codecov-io
Copy link

codecov-io commented Oct 18, 2017

Codecov Report

Merging #11592 into master will decrease coverage by 0.28%.
The diff coverage is 22.78%.

@@            Coverage Diff             @@
##           master   #11592      +/-   ##
==========================================
- Coverage   52.54%   52.26%   -0.29%     
==========================================
  Files         268      268              
  Lines       25296    25311      +15     
  Branches     4032     4034       +2     
==========================================
- Hits        13293    13228      -65     
- Misses      12003    12083      +80
Flag Coverage Δ
#unittest 52.26% <22.78%> (-0.29%) ⬇️
Impacted Files Coverage Δ
app/sessionStore.js 76.12% <ø> (ø) ⬆️
app/browser/reducers/pageDataReducer.js 100% <ø> (ø) ⬆️
app/common/state/pageDataState.js 79.54% <100%> (-8.6%) ⬇️
app/common/lib/ledgerUtil.js 84.87% <100%> (-0.74%) ⬇️
app/browser/api/ledger.js 31% <15.9%> (-0.3%) ⬇️
app/browser/reducers/ledgerReducer.js 43.76% <18.64%> (-4.8%) ⬇️

@NejcZdovc
Copy link
Contributor Author

I am done with an initial work. I am waiting for some feedback regarding what is visit, then I will do final clenup

@NejcZdovc NejcZdovc force-pushed the refactor/#11575-pageData branch 3 times, most recently from 30e33b5 to f7b1813 Compare October 23, 2017 08:05
@NejcZdovc
Copy link
Contributor Author

PR is ready for the review

@@ -3,6 +3,8 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const Immutable = require('immutable')
const electron = require('electron')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine but I think preferred style is const {BrowserWindow} = require('electron')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it was moved code, so feel free to leave as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (!lastActiveTabId || tabId === lastActiveTabId) {
state = ledgerApi.pageDataChanged(state, {
location: pageUrl,
tabId: tabId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit on style:
just tabId instead of tabId: tabId

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -1,5 +1,6 @@
chrome.idle.setDetectionInterval(15 * 60)
chrome.idle.onStateChanged.addListener((idleState) => {
// uses appConstants.APP_IDLE_STATE_CHANGED action constant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: start comment with capital and end in period.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

afterEach(function () {
pageDataChangedSpy.restore()
})
it('doesnt calls ledgerApi.pageDataChanged when no idle state is provided', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: does not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assert(pageDataChangedSpy.withArgs(appState).calledOnce)
})
it('calls ledgerApi.addVisit', function () {
assert(addVisitSpy.calledOnce)
it('doesnt calls ledgerApi.pageDataChanged when in idleState', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit does not or doesn't

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* @return {boolean} true if page should have usage collected, false if not
*/
const shouldTrackView = (view, responseList) => {
if (view == null) {
const shouldTrackView = (tab) => {
Copy link
Member

@bbondy bbondy Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please rename this to tabValue because we usually use tab as the webContents in code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (location === currentUrl) {
return state
}

state = setLocation(state, timestamp, tabId)
/*
Save previous recorder page
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: * to align with other stars

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const aboutUrl = getSourceAboutUrl(lastUrl) || lastUrl
if (aboutUrl && aboutUrl.match(/^about/)) {
state = pageDataState.resetInfo(state)
// add visit to the ledger when we are not in a private tab
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit comment style

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


currentUrl = (location && location.match(/^about/)) ? locationDefault : location
currentTimestamp = timestamp
// update to the latest view
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit comment style

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@NejcZdovc NejcZdovc merged commit 3cf6a50 into brave:master Oct 23, 2017
NejcZdovc added a commit that referenced this pull request Oct 23, 2017
Fixes publisher not added to the ledger
NejcZdovc added a commit that referenced this pull request Oct 23, 2017
Fixes publisher not added to the ledger
NejcZdovc added a commit that referenced this pull request Oct 23, 2017
Fixes publisher not added to the ledger
@NejcZdovc
Copy link
Contributor Author

master 3cf6a50
0.21 2fa2f88
0.20 820ed5b
0.19 61c92a8

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants