Skip to content

Commit be4bc6b

Browse files
committed
fix docs and update specs
1 parent d2e40d4 commit be4bc6b

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

docs/api/protocol.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The `uploadData` is an array of `data` objects:
9393
* `data` Object
9494
* `bytes` Buffer - Content being sent.
9595
* `file` String - Path of file being uploaded.
96-
* `blobUUId` String - UUID of blob data.
96+
* `blobUUID` String - UUID of blob data.
9797

9898
To handle the `request`, the `callback` should be called with either the file's
9999
path or an object that has a `path` property, e.g. `callback(filePath)` or

docs/api/session.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,13 @@ This doesn't affect existing `WebContents`, and each `WebContents` can use
326326

327327
Returns a `String` representing the user agent for this session.
328328

329-
#### `ses.getBlobDataForUUID(uuid, callback)`
329+
#### `ses.getBlobData(identifier, callback)`
330330

331-
* `uuid` String
331+
* `identifier` String - Valid UUID or public blob URL.
332332
* `callback` Function
333333
* `result` Buffer - Blob data.
334334

335-
Returns the blob data associated with `uuid`.
335+
Returns the blob data associated with the `identifier`.
336336

337337
### Instance Properties
338338

spec/api-session-spec.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,4 +402,68 @@ describe('session module', function () {
402402
})
403403
})
404404
})
405+
406+
describe('ses.getblobData(identifier, callback)', function () {
407+
it('returns blob data for public url', function (done) {
408+
let data = JSON.stringify({
409+
type: 'blob',
410+
value: 'hello'
411+
})
412+
let blob = new Blob([data], {type: 'application/json'})
413+
let blobURL = URL.createObjectURL(blob)
414+
session.defaultSession.getBlobData(blobURL, function (result) {
415+
assert.equal(result.toString(), data)
416+
done()
417+
})
418+
})
419+
420+
it('returns blob data for uuid', function (done) {
421+
const scheme = 'temp'
422+
const protocol = session.defaultSession.protocol
423+
const url = scheme + '://host'
424+
before(function () {
425+
if (w != null) w.destroy()
426+
w = new BrowserWindow({show: false})
427+
})
428+
429+
after(function (done) {
430+
protocol.unregisterProtocol(scheme, () => {
431+
closeWindow(w).then(() => {
432+
w = null
433+
done()
434+
})
435+
})
436+
})
437+
438+
const postData = JSON.stringify({
439+
type: 'blob',
440+
value: 'hello'
441+
})
442+
const content = `<html>
443+
<script>
444+
const {webFrame} = require('electron')
445+
webFrame.registerURLSchemeAsPrivileged('${scheme}')
446+
let fd = new FormData();
447+
fd.append('file', new Blob(['${postData}'], {type:'application/json'}));
448+
fetch('${url}', {method:'POST', body: fd });
449+
</script>
450+
</html>`
451+
452+
protocol.registerStringProtocol(scheme, function (request, callback) {
453+
if (request.method === 'GET') {
454+
callback({data: content, mimeType: 'text/html'})
455+
} else if (request.method === 'POST') {
456+
let uuid = request.uploadData[1].blobUUID
457+
assert(uuid)
458+
session.defaultSession.getBlobData(uuid, function (result) {
459+
assert.equal(result.toString(), postData)
460+
done()
461+
})
462+
}
463+
}, function (error) {
464+
if (error) return done(error)
465+
w.loadURL(url)
466+
})
467+
})
468+
})
405469
})

0 commit comments

Comments
 (0)