Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gh 1239 #131

Merged
merged 5 commits into from Jul 12, 2018
Merged
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Next
GH-1256 update tracker count to respect AdBlock and AntiTrack counts
  • Loading branch information
IAmThePan committed Jul 12, 2018
commit 29720824da505f71ac7dd360df80eaf4fc486d53
@@ -65,17 +65,7 @@ class CliqzFeatures extends React.Component {
if (!this.props.antiTrackingActive) {
return '-';
}
let antiTrackingTotal = 0;
for (const category in this.props.antiTracking) {
if (this.props.antiTracking.hasOwnProperty(category)) {
for (const app in this.props.antiTracking[category]) {
if (this.props.antiTracking[category][app] === 'unsafe') {
antiTrackingTotal++;
}
}
}
}
return antiTrackingTotal;
return this.props.antiTracking && this.props.antiTracking.totalUnsafeCount || 0;
}

/**
@@ -275,6 +275,8 @@ class Summary extends React.Component {
const { abPause } = this.state;
const { is_expert, is_expanded, paused_blocking } = this.props;
const showCondensed = is_expert && is_expanded;
const antiTrackUnsafe = this.props.antiTracking && this.props.antiTracking.totalUnsafeCount || 0;
const adBlockBlocked = this.props.adBlock && this.props.adBlock.totalCount || 0;

const summaryClassNames = ClassNames('', {
expert: is_expert,
@@ -327,7 +329,7 @@ class Summary extends React.Component {
categories={this.props.categories}
renderRedscale={this.props.sitePolicy === 1}
renderGreyscale={this.props.paused_blocking}
totalCount={this.props.trackerCounts.allowed + this.props.trackerCounts.blocked || 0}
totalCount={this.props.trackerCounts.allowed + this.props.trackerCounts.blocked + antiTrackUnsafe + adBlockBlocked || 0}
ghosteryFeatureSelect={this.props.sitePolicy}
isSmall={is_expert}
clickDonut={this.clickDonut}
@@ -351,7 +353,7 @@ class Summary extends React.Component {
<div className={blockedTrackersClassNames} onClick={this.clickTrackersBlocked}>
<span className="text">{t('trackers_blocked')} </span>
<span className="value">
{this.props.trackerCounts.blocked || 0}
{this.props.trackerCounts.blocked + antiTrackUnsafe + adBlockBlocked || 0}
</span>
</div>
<div className={pageLoadClassNames}>
@@ -57,7 +57,9 @@ describe('app/panel/reducers/summary.js', () => {

expect(summaryReducer(initState, action)).toEqual({
adBlock: {},
antiTracking: {},
antiTracking: {
totalUnsafeCount: 0
},
});
});

@@ -51,6 +51,18 @@ export default (state = initialState, action) => {
return Object.assign({}, state, action.data);
}
case GET_CLIQZ_MODULE_DATA: {
const antiTracking = action.data.antitracking;
let totalUnsafeCount = 0;
for (const category in antiTracking) {
if (antiTracking.hasOwnProperty(category)) {
for (const app in antiTracking[category]) {
if (antiTracking[category][app] === 'unsafe') {
totalUnsafeCount++;
}
}
}
}
antiTracking.totalUnsafeCount = totalUnsafeCount;
return Object.assign({}, state, { adBlock: action.data.adblock, antiTracking: action.data.antitracking });
}
case UPDATE_GHOSTERY_PAUSED: {
@@ -15,12 +15,15 @@

import conf from './Conf';
import foundBugs from './FoundBugs';
import cliqz from './Cliqz';
import rewards from './Rewards';
import Policy from './Policy';
import { getTab } from '../utils/utils';
import { log } from '../utils/common';
import globals from './Globals';

const { adblocker, antitracking } = cliqz.modules;

/**
* @class for handling Ghostery button.
* @memberof BackgroundClasses
@@ -140,18 +143,77 @@ class BrowserButton {
// + Ghostery was enabled after the tab started loading
// + or, this is a tab onBeforeRequest doesn't run in (non-http/https page)
trackerCount = '';
} else {
const apps = foundBugs.getAppsCountByIssues(tabId, tabUrl);
trackerCount = apps.all.toString();
alert = (apps.total > 0);
this._setIcon(false, tabId, trackerCount, alert);
return;
}

// gray-out the icon when blocking has been disabled for whatever reason
if (trackerCount === '') {
this._setIcon(false, tabId, trackerCount, alert);
} else {
this._setIcon(!globals.SESSION.paused_blocking && !this.policy.whitelisted(tab.url), tabId, trackerCount, alert);
this._getAntiTrackCount(tabId).then((antiTrackingCount) => {
const { appsCount, appsAlertCount } = this._getTrackerCount(tabId);
const adBlockingCount = this._getAdBlockCount(tabId);

alert = (appsAlertCount > 0);
trackerCount = (appsCount + antiTrackingCount + adBlockingCount).toString();

// gray-out the icon when blocking has been disabled for whatever reason
if (trackerCount === '') {
this._setIcon(false, tabId, trackerCount, alert);
} else {
this._setIcon(!globals.SESSION.paused_blocking && !this.policy.whitelisted(tab.url), tabId, trackerCount, alert);
}
});
}

/**
* Gets tracker count the traditional way, from BugDb
* @param {number} tabId the Tab Id
* @param {string} tabUrl the Tab URL
* @return {Object} the number of total trackers and alerted trackers in an Object
*/
_getTrackerCount(tabId, tabUrl) {
const apps = foundBugs.getAppsCountByIssues(tabId, tabUrl);
return {
appsCount: apps.all,
appsAlertCount: apps.total,
};
}

/**
* Get tracker count for Anti Tracking in a promise
* @param {number} tabId the Tab Id
* @return {Promise} the number of trackers as a Promise
*/
_getAntiTrackCount(tabId) {
return new Promise((resolve, reject) => {
if (!conf.enable_anti_tracking) {
resolve(0);
}
antitracking.background.actions.aggregatedBlockingStats(tabId).then((antiTracking) => {
let totalUnsafeCount = 0;
for (const category in antiTracking) {
if (antiTracking.hasOwnProperty(category)) {
for (const app in antiTracking[category]) {
if (antiTracking[category][app] === 'unsafe') {
totalUnsafeCount++;
}
}
}
}
resolve(totalUnsafeCount);
});
});
}

/**
* Get tracker count for Ad Blocking
* @param {number} tabId the Tab Id
* @return {number} the number of trackers in an object
*/
_getAdBlockCount(tabId) {
if (!conf.enable_ad_block) {
return 0;
}
const adBlocking = adblocker.background.actions.getAdBlockInfoForTab(tabId);
return adBlocking && adBlocking.totalCount || 0;
}
}

@@ -26,6 +26,28 @@ chrome.runtime.getManifest.returns({
debug: true
});

// Create Mock for
jest.mock('../src/classes/Cliqz', () => {
return {
modules: {
adblocker: {
background: {
actions: {
getAdBlockInfoForTab: jest.fn()
}
}
},
antitracking: {
background: {
actions: {
aggregatedBlockingStats: jest.fn()
}
}
}
}
};
});

// Create Mock for the Cliqz dependencies
jest.mock('browser-core', () => {
return { App: class App {} }
ProTip! Use n and p to navigate between commits in a pull request.