Skip to content

Commit

Permalink
adding protectionsState to breakage form (#2313)
Browse files Browse the repository at this point in the history
Co-authored-by: Shane Osbourne <sosbourne@duckduckgo.com>
  • Loading branch information
shakyShane and Shane Osbourne committed Nov 2, 2023
1 parent 54b5b27 commit 8e765d9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion shared/js/background/broken-site-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export function breakageReportForTab ({
urlParametersRemoved,
ctlYouTube,
ctlFacebookPlaceholderShown,
ctlFacebookLogin
ctlFacebookLogin,
protectionsState: tab.site.isFeatureEnabled('contentBlocking') ? '1' : '0'
})

for (const [key, value] of Object.entries(requestCategories)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,61 @@ for (const setName of Object.keys(testSets)) {
})
})
}

describe('Broken Site Reporting tests / protections state', () => {
function submit (tab) {
const loadPixelSpy = spyOn(loadPixel, 'url').and.returnValue(null)
breakageReportForTab({
tab,
tds: 'abc123',
remoteConfigEtag: 'abd142',
remoteConfigVersion: '1234',
category: 'content',
description: 'test'
})
const requestURLString = loadPixelSpy.calls.argsFor(0)[0]
return new URL(requestURLString).searchParams
}
it('sends 1 when protections are enabled', () => {
const tab = new Tab({ url: 'https://example.com' })
spyOnProperty(tab.site, 'enabledFeatures').and.returnValue(['contentBlocking'])

const params = submit(tab)
expect(params.get('protectionsState')).toEqual('1')
})
it('sends 1 when site is denylisted', () => {
const tab = new Tab({ url: 'https://example.com' })

spyOnProperty(tab.site, 'enabledFeatures').and.returnValue([])
spyOnProperty(tab.site, 'denylisted').and.returnValue(true)

const params = submit(tab)
expect(params.get('protectionsState')).toEqual('1')
})
it('sends 0 when site is allowlisted', () => {
const tab = new Tab({ url: 'https://example.com' })
spyOnProperty(tab.site, 'enabledFeatures').and.returnValue(['contentBlocking'])
spyOnProperty(tab.site, 'allowlisted').and.returnValue(true)

const params = submit(tab)
expect(params.get('protectionsState')).toEqual('0')
})
it('sends 0 when contentBlocking is not enabled', () => {
const tab = new Tab({ url: 'https://example.com' })

// missing `contentBlocking`
spyOnProperty(tab.site, 'enabledFeatures').and.returnValue([])

const params = submit(tab)
expect(params.get('protectionsState')).toEqual('0')
})
it('sends 0 when domain is in unprotectedTemporary', () => {
const tab = new Tab({ url: 'https://example.com' })

spyOnProperty(tab.site, 'enabledFeatures').and.returnValue(['contentBlocking'])
spyOnProperty(tab.site, 'isBroken').and.returnValue(true)

const params = submit(tab)
expect(params.get('protectionsState')).toEqual('0')
})
})

0 comments on commit 8e765d9

Please sign in to comment.