Merge pull request #7169 from deepak1556/download_defaultname_patch
browser: provide a default filename when unable to generate from download data
This commit is contained in:
Коммит
9dad9478fa
|
@ -135,7 +135,7 @@ std::string DownloadItem::GetFilename() const {
|
|||
std::string(),
|
||||
download_item_->GetSuggestedFilename(),
|
||||
GetMimeType(),
|
||||
std::string()).LossyDisplayName());
|
||||
"download").LossyDisplayName());
|
||||
}
|
||||
|
||||
std::string DownloadItem::GetContentDisposition() const {
|
||||
|
|
|
@ -134,6 +134,7 @@ struct Converter<WindowOpenDisposition> {
|
|||
case NEW_FOREGROUND_TAB: disposition = "foreground-tab"; break;
|
||||
case NEW_BACKGROUND_TAB: disposition = "background-tab"; break;
|
||||
case NEW_POPUP: case NEW_WINDOW: disposition = "new-window"; break;
|
||||
case SAVE_TO_DISK: disposition = "save-to-disk"; break;
|
||||
default: break;
|
||||
}
|
||||
return mate::ConvertToV8(isolate, disposition);
|
||||
|
|
|
@ -60,7 +60,7 @@ void AtomDownloadManagerDelegate::CreateDownloadPath(
|
|||
std::string(),
|
||||
suggested_filename,
|
||||
mime_type,
|
||||
std::string());
|
||||
"download");
|
||||
|
||||
if (!base::PathExists(default_download_path))
|
||||
base::CreateDirectory(default_download_path);
|
||||
|
|
|
@ -144,7 +144,7 @@ Returns:
|
|||
* `url` String
|
||||
* `frameName` String
|
||||
* `disposition` String - Can be `default`, `foreground-tab`, `background-tab`,
|
||||
`new-window` and `other`.
|
||||
`new-window`, `save-to-disk` and `other`.
|
||||
* `options` Object - The options which will be used for creating the new
|
||||
`BrowserWindow`.
|
||||
|
||||
|
|
|
@ -670,7 +670,7 @@ Returns:
|
|||
* `url` String
|
||||
* `frameName` String
|
||||
* `disposition` String - Can be `default`, `foreground-tab`, `background-tab`,
|
||||
`new-window` and `other`.
|
||||
`new-window`, `save-to-disk` and `other`.
|
||||
* `options` Object - The options which should be used for creating the new
|
||||
`BrowserWindow`.
|
||||
|
||||
|
|
|
@ -252,6 +252,9 @@ describe('session module', function () {
|
|||
var contentDisposition = 'inline; filename="mock.pdf"'
|
||||
var downloadFilePath = path.join(fixtures, 'mock.pdf')
|
||||
var downloadServer = http.createServer(function (req, res) {
|
||||
if (req.url === '/?testFilename') {
|
||||
contentDisposition = 'inline'
|
||||
}
|
||||
res.writeHead(200, {
|
||||
'Content-Length': mockPDF.length,
|
||||
'Content-Type': 'application/pdf',
|
||||
|
@ -320,6 +323,23 @@ describe('session module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
it('can generate a default filename', function (done) {
|
||||
downloadServer.listen(0, '127.0.0.1', function () {
|
||||
var port = downloadServer.address().port
|
||||
ipcRenderer.sendSync('set-download-option', true, false)
|
||||
w.loadURL(url + ':' + port + '/?testFilename')
|
||||
ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
|
||||
assert.equal(state, 'cancelled')
|
||||
assert.equal(filename, 'download.pdf')
|
||||
assert.equal(mimeType, 'application/pdf')
|
||||
assert.equal(receivedBytes, 0)
|
||||
assert.equal(totalBytes, mockPDF.length)
|
||||
assert.equal(disposition, contentDisposition)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a save path is specified and the URL is unavailable', function () {
|
||||
it('does not display a save dialog and reports the done state as interrupted', function (done) {
|
||||
ipcRenderer.sendSync('set-download-option', false, false)
|
||||
|
|
Загрузка…
Ссылка в новой задаче