Skip to content

Commit

Permalink
Saving a document doesn't show correct origin Fix brave#8698. Auditors
Browse files Browse the repository at this point in the history
  • Loading branch information
kumarrishav committed May 10, 2017
1 parent 9b85662 commit c2de975
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/renderer/components/downloadItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class DownloadItem extends ImmutableComponent {
}
render () {
const origin = getOrigin(this.props.download.get('url'))
const localFileOrigins = ['file:', 'blob:', 'data:', 'chrome-extension:', 'chrome:']
const localFile = localFileOrigins.some((localFileOrigin) => origin.startsWith(localFileOrigin))
const progressStyle = {
width: downloadUtil.getPercentageComplete(this.props.download)
}
Expand Down Expand Up @@ -160,7 +162,7 @@ class DownloadItem extends ImmutableComponent {
? <span className='fa fa-unlock isInsecure' />
: null
}
<span title={origin}>{origin}</span>
<span title={origin}>{localFile ? 'Local file' : origin}</span>
</div>
: null
}
Expand Down
34 changes: 34 additions & 0 deletions test/unit/app/renderer/downloadItemTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require('../../braveUnit')

const savePath = path.join(require('os').tmpdir(), 'mostHatedPrimes.txt')
const downloadUrl = 'http://www.bradrichter.com/mostHatedPrimes.txt'
const localFileDownloadUrl = 'file:///Users/foobar/Library/abc.txt'
const newDownload = (state) => Immutable.fromJS({
startTime: new Date().getTime(),
filename: 'mostHatedPrimes.txt',
Expand All @@ -28,6 +29,16 @@ const newDownload = (state) => Immutable.fromJS({
deleteConfirmationVisible: false,
state
})
const newDownloadLocalFile = (state) => Immutable.fromJS({
startTime: new Date().getTime(),
filename: 'abc.txt',
savePath,
url: localFileDownloadUrl,
totalBytes: 104729,
receivedBytes: 96931,
deleteConfirmationVisible: false,
state
})

describe('downloadItem component', function () {
before(function () {
Expand All @@ -45,6 +56,29 @@ describe('downloadItem component', function () {
mockery.disable()
})

Object.values(downloadStates).forEach(function (state) {
describe(`${state} download local item`, function () {
before(function () {
this.downloadId = uuid.v4()
this.download = newDownloadLocalFile(state)
this.result = mount(
<DownloadItem
downloadId={this.downloadId}
download={this.download}
deleteConfirmationVisible={this.download.get('deleteConfirmationVisible')} />
)
})

it('filename exists and matches download filename', function () {
assert.equal(this.result.find('.downloadFilename').text(), this.download.get('filename'))
})

it('has local origin i.e file: and matches to "Local file" origin', function () {
assert.equal(this.result.find('.downloadOrigin').text(), 'Local file')
})
})
})

Object.values(downloadStates).forEach(function (state) {
describe(`${state} download item`, function () {
before(function () {
Expand Down

0 comments on commit c2de975

Please sign in to comment.