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

Commit

Permalink
add privacy controls test
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Oct 30, 2018
1 parent 6816ee4 commit 5a43f95
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/components/braveShields/privacyControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { NoScriptInfo } from '../../types/other/noScriptInfo'
import * as shieldActions from '../../types/actions/shieldsPanelActions'
import { getMessage } from '../../background/api/localeAPI'

interface Props {
export interface Props {
url: string
hostname: string
origin: string
Expand Down Expand Up @@ -158,7 +158,7 @@ export default class PrivacyControls extends React.PureComponent<Props, State> {
}

return (
<>
<div id='braveShieldsPrivacyControls'>
{/* cookies select */}
<SelectGrid hasUserInteraction={false}>
<EmptyButton />
Expand Down Expand Up @@ -203,7 +203,7 @@ export default class PrivacyControls extends React.PureComponent<Props, State> {
: null
}
</SelectGrid>
</>
</div>
)
}
}
6 changes: 3 additions & 3 deletions app/types/actions/shieldsPanelActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ export interface ChangeNoScriptSettings {
(origin: string): ChangeNoScriptSettingsReturn
}

interface BlockAllScriptsReturn {
interface ChangeAllNoScriptSettingsReturn {
type: types.CHANGE_ALL_NO_SCRIPT_SETTINGS,
origin: string,
shouldBlock: boolean
}

export interface ChangeAllNoScriptSettings {
(origin: string, shouldBlock: boolean): BlockAllScriptsReturn
(origin: string, shouldBlock: boolean): ChangeAllNoScriptSettingsReturn
}

export type shieldPanelActions =
Expand All @@ -144,4 +144,4 @@ export type shieldPanelActions =
BlockCookiesReturn |
AllowScriptOriginsOnceReturn |
ChangeNoScriptSettingsReturn |
BlockAllScriptsReturn
ChangeAllNoScriptSettingsReturn
101 changes: 101 additions & 0 deletions test/app/components/braveShields/privacyControlsTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* global describe, it */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import 'mocha'
import * as React from 'react'
import * as assert from 'assert'
import ShieldsPrivacyControls, { Props } from '../../../../app/components/braveShields/privacyControls'
import { BlockJSOptions, BlockCookiesOptions, BlockFPOptions } from '../../../../app/types/other/blockTypes'
import * as actionTypes from '../../../../app/constants/shieldsPanelTypes'
import { shallow } from 'enzyme'
import * as sinon from 'sinon'

const fakeProps: Props = {
url: 'https://brave.com/jobs',
hostname: 'brave.com',
origin: 'https://brave.com',
braveShields: 'allow',
javascript: 'block',
javascriptBlocked: 0,
blockJavaScript: (setting: BlockJSOptions) => ({ type: actionTypes.JAVASCRIPT_TOGGLED, setting }),
javascriptBlockedResources: [],
noScriptInfo: {},
allowScriptOriginsOnce: (origins: Array<string>) => ({ type: actionTypes.ALLOW_SCRIPT_ORIGINS_ONCE, origins }),
changeNoScriptSettings: (origin: string) => ({ type: actionTypes.CHANGE_NO_SCRIPT_SETTINGS, origin }),
changeAllNoScriptSettings: (origin: string, shouldBlock: boolean) => ({ type: actionTypes.CHANGE_ALL_NO_SCRIPT_SETTINGS, origin, shouldBlock }),
fingerprinting: 'block',
fingerprintingBlocked: 0,
blockFingerprinting: (setting: BlockFPOptions) => ({ type: actionTypes.BLOCK_FINGERPRINTING, setting }),
fingerprintingBlockedResources: [],
cookies: 'block',
blockCookies: (setting: BlockCookiesOptions) => ({ type: actionTypes.BLOCK_COOKIES, setting })
}

describe('PrivacyControls component', () => {
const baseComponent = (props: Props) =>
<ShieldsPrivacyControls {...props} />

it('renders the component', () => {
const wrapper = shallow(baseComponent(fakeProps))
const assertion = wrapper.find('#braveShieldsPrivacyControls').length === 1
assert.equal(assertion, true)
})

describe('cookie control', () => {
it('responds to the onChange event', () => {
const value = { target: { value: true } }
const onChangeCookiesControlSelectOptions = sinon.spy()
const newProps = Object.assign(fakeProps, {
blockCookies: onChangeCookiesControlSelectOptions
})

const wrapper = shallow(baseComponent(newProps))
wrapper.find('#blockCookies').simulate('change', value)
assert.equal(onChangeCookiesControlSelectOptions.calledOnce, true)
})
})

describe('scripts control', () => {
it('responds to the onChange event', () => {
const value = { target: { value: true } }
const onChangeScriptControlSelectOptions = sinon.spy()
const newProps = Object.assign(fakeProps, {
blockJavaScript: onChangeScriptControlSelectOptions
})

const wrapper = shallow(baseComponent(newProps))
wrapper.find('#blockScripts').simulate('change', value)
assert.equal(onChangeScriptControlSelectOptions.calledOnce, true)
})

it('shows number of scripts blocked', () => {
const newProps = Object.assign(fakeProps, { javascriptBlocked: 1337 })
const wrapper = shallow(baseComponent(newProps))
const assertion = wrapper.find('#blockScriptsStat').props().children
assert.equal(assertion, 1337)
})
})

describe('fingerprinting control', () => {
it('responds to the onChange event', () => {
const value = { target: { value: true } }
const onChangeFingerprintingProtectionSelectOptions = sinon.spy()
const newProps = Object.assign(fakeProps, {
blockFingerprinting: onChangeFingerprintingProtectionSelectOptions
})

const wrapper = shallow(baseComponent(newProps))
wrapper.find('#blockFingerprinting').simulate('change', value)
assert.equal(onChangeFingerprintingProtectionSelectOptions.calledOnce, true)
})

it('shows number of fingerprinting attempts blocked', () => {
const newProps = Object.assign(fakeProps, { fingerprintingBlocked: 1337 })
const wrapper = shallow(baseComponent(newProps))
const assertion = wrapper.find('#blockFingerprintingStat').props().children
assert.equal(assertion, 1337)
})
})
})

0 comments on commit 5a43f95

Please sign in to comment.