Write a spec for downloading from the webview tag.
This commit is contained in:
Родитель
0d30a8d70c
Коммит
b369d4991e
|
@ -87,23 +87,43 @@ describe 'session module', ->
|
|||
res.end mockPDF
|
||||
downloadServer.close()
|
||||
|
||||
it 'can download successfully', (done) ->
|
||||
assertDownload = (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port) ->
|
||||
assert.equal state, 'completed'
|
||||
assert.equal filename, 'mock.pdf'
|
||||
assert.equal url, "http://127.0.0.1:#{port}/"
|
||||
assert.equal mimeType, 'application/pdf'
|
||||
assert.equal receivedBytes, mockPDF.length
|
||||
assert.equal totalBytes, mockPDF.length
|
||||
assert.equal disposition, contentDisposition
|
||||
assert fs.existsSync downloadFilePath
|
||||
fs.unlinkSync downloadFilePath
|
||||
|
||||
it 'can download using BrowserWindow.loadURL', (done) ->
|
||||
downloadServer.listen 0, '127.0.0.1', ->
|
||||
{port} = downloadServer.address()
|
||||
ipcRenderer.sendSync 'set-download-option', false
|
||||
w.loadURL "#{url}:#{port}"
|
||||
ipcRenderer.once 'download-done', (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) ->
|
||||
assert.equal state, 'completed'
|
||||
assert.equal filename, 'mock.pdf'
|
||||
assert.equal url, "http://127.0.0.1:#{port}/"
|
||||
assert.equal mimeType, 'application/pdf'
|
||||
assert.equal receivedBytes, mockPDF.length
|
||||
assert.equal totalBytes, mockPDF.length
|
||||
assert.equal disposition, contentDisposition
|
||||
assert fs.existsSync downloadFilePath
|
||||
fs.unlinkSync downloadFilePath
|
||||
assertDownload event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port
|
||||
done()
|
||||
|
||||
it 'can download using WebView.downloadURL', (done) ->
|
||||
downloadServer.listen 0, '127.0.0.1', ->
|
||||
{port} = downloadServer.address()
|
||||
ipcRenderer.sendSync 'set-download-option', false
|
||||
|
||||
webview = new WebView
|
||||
webview.src = "file://#{fixtures}/api/blank.html"
|
||||
webview.addEventListener 'did-finish-load', ->
|
||||
webview.downloadURL "#{url}:#{port}/"
|
||||
|
||||
ipcRenderer.once 'download-done', (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) ->
|
||||
assertDownload event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port
|
||||
document.body.removeChild(webview)
|
||||
done()
|
||||
|
||||
document.body.appendChild webview
|
||||
|
||||
it 'can cancel download', (done) ->
|
||||
downloadServer.listen 0, '127.0.0.1', ->
|
||||
{port} = downloadServer.address()
|
||||
|
|
Загрузка…
Ссылка в новой задаче