Skip to content

Commit

Permalink
test: initial round
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 committed Mar 23, 2022
1 parent 696f334 commit b8c9cb4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,40 @@ test('isURLPotentiallyTrustworthy', (t) => {
t.notOk(util.isURLPotentiallyTrustworthy(instance))
}
})

test('determineRequestsReferrer', (t) => {
t.plan(4)
t.test('Should handle empty referrerPolicy', (tt) => {
tt.plan(2)
tt.equal(util.determineRequestsReferrer({}), 'no-referrer')
tt.equal(util.determineRequestsReferrer({ referrerPolicy: '' }), 'no-referrer')
})

t.test('Should handle "no-referrer" referrerPolicy', (tt) => {
tt.plan(1)
tt.equal(util.determineRequestsReferrer({ referrerPolicy: 'no-referrer' }), 'no-referrer')
})

t.test('Should return "no-referrer" if request referrer is absent', (tt) => {
tt.plan(1)
tt.equal(util.determineRequestsReferrer({
referrerPolicy: 'origin'
}), 'no-referrer')
})

t.test('Should return "no-referrer" if scheme is local scheme', (tt) => {
tt.plan(4)
const referrerSources = [
new URL('data:something'),
new URL('about:blank'),
new URL('javascript:something'),
new URL('file://path/to/file')]

for (const source of referrerSources) {
tt.equal(util.determineRequestsReferrer({
referrerPolicy: 'origin',
referrer: source
}), 'no-referrer')
}
})
})

0 comments on commit b8c9cb4

Please sign in to comment.