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

Commit

Permalink
Merge pull request #8786 from kumarrishav/correctOrigin
Browse files Browse the repository at this point in the history
Saving a document doesn't show correct origin
  • Loading branch information
NejcZdovc authored May 10, 2017
2 parents a602f87 + 277074e commit 57afda7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/extensions/brave/locales/en-US/downloads.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ downloadInProgress=Downloading: {{downloadPercent}}
downloadInProgressUnknownTotal=Downloading…
downloadPaused=Paused: {{downloadPercent}}
downloadDeleteConfirmation=Delete?
downloadLocalFile=Local file

downloadPause.title=Pause Download
downloadResume.title=Resume Download
Expand Down
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 = origin && 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 data-l10n-id={localFile ? 'downloadLocalFile' : null} title={origin}>{localFile ? null : origin}</span>
</div>
: null
}
Expand Down
32 changes: 32 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 @@ -46,6 +57,27 @@ describe('downloadItem component', function () {
})

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(), '')
})
})

describe(`${state} download item`, function () {
before(function () {
this.downloadId = uuid.v4()
Expand Down

0 comments on commit 57afda7

Please sign in to comment.