Write a spec for downloading from the webview tag.
This commit is contained in:
parent
0d30a8d70c
commit
b369d4991e
1 changed files with 30 additions and 10 deletions
|
@ -87,23 +87,43 @@ describe 'session module', ->
|
||||||
res.end mockPDF
|
res.end mockPDF
|
||||||
downloadServer.close()
|
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', ->
|
downloadServer.listen 0, '127.0.0.1', ->
|
||||||
{port} = downloadServer.address()
|
{port} = downloadServer.address()
|
||||||
ipcRenderer.sendSync 'set-download-option', false
|
ipcRenderer.sendSync 'set-download-option', false
|
||||||
w.loadURL "#{url}:#{port}"
|
w.loadURL "#{url}:#{port}"
|
||||||
ipcRenderer.once 'download-done', (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) ->
|
ipcRenderer.once 'download-done', (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) ->
|
||||||
assert.equal state, 'completed'
|
assertDownload event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename, port
|
||||||
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
|
|
||||||
done()
|
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) ->
|
it 'can cancel download', (done) ->
|
||||||
downloadServer.listen 0, '127.0.0.1', ->
|
downloadServer.listen 0, '127.0.0.1', ->
|
||||||
{port} = downloadServer.address()
|
{port} = downloadServer.address()
|
||||||
|
|
Loading…
Reference in a new issue