From be4bc6b7efcfd19e4c32cf09caafb03b13eed972 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 23 Aug 2016 11:29:21 +0530 Subject: [PATCH] fix docs and update specs --- docs/api/protocol.md | 2 +- docs/api/session.md | 6 ++--- spec/api-session-spec.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/docs/api/protocol.md b/docs/api/protocol.md index 4605bc7..0f79f0a 100644 --- a/docs/api/protocol.md +++ b/docs/api/protocol.md @@ -93,7 +93,7 @@ The `uploadData` is an array of `data` objects: * `data` Object * `bytes` Buffer - Content being sent. * `file` String - Path of file being uploaded. - * `blobUUId` String - UUID of blob data. + * `blobUUID` String - UUID of blob data. To handle the `request`, the `callback` should be called with either the file's path or an object that has a `path` property, e.g. `callback(filePath)` or diff --git a/docs/api/session.md b/docs/api/session.md index 5fa4ba0..a691cb4 100644 --- a/docs/api/session.md +++ b/docs/api/session.md @@ -326,13 +326,13 @@ This doesn't affect existing `WebContents`, and each `WebContents` can use Returns a `String` representing the user agent for this session. -#### `ses.getBlobDataForUUID(uuid, callback)` +#### `ses.getBlobData(identifier, callback)` -* `uuid` String +* `identifier` String - Valid UUID or public blob URL. * `callback` Function * `result` Buffer - Blob data. -Returns the blob data associated with `uuid`. +Returns the blob data associated with the `identifier`. ### Instance Properties diff --git a/spec/api-session-spec.js b/spec/api-session-spec.js index 1caa08d..91f9777 100644 --- a/spec/api-session-spec.js +++ b/spec/api-session-spec.js @@ -402,4 +402,68 @@ describe('session module', function () { }) }) }) + + describe('ses.getblobData(identifier, callback)', function () { + it('returns blob data for public url', function (done) { + let data = JSON.stringify({ + type: 'blob', + value: 'hello' + }) + let blob = new Blob([data], {type: 'application/json'}) + let blobURL = URL.createObjectURL(blob) + session.defaultSession.getBlobData(blobURL, function (result) { + assert.equal(result.toString(), data) + done() + }) + }) + + it('returns blob data for uuid', function (done) { + const scheme = 'temp' + const protocol = session.defaultSession.protocol + const url = scheme + '://host' + before(function () { + if (w != null) w.destroy() + w = new BrowserWindow({show: false}) + }) + + after(function (done) { + protocol.unregisterProtocol(scheme, () => { + closeWindow(w).then(() => { + w = null + done() + }) + }) + }) + + const postData = JSON.stringify({ + type: 'blob', + value: 'hello' + }) + const content = ` + + ` + + protocol.registerStringProtocol(scheme, function (request, callback) { + if (request.method === 'GET') { + callback({data: content, mimeType: 'text/html'}) + } else if (request.method === 'POST') { + let uuid = request.uploadData[1].blobUUID + assert(uuid) + session.defaultSession.getBlobData(uuid, function (result) { + assert.equal(result.toString(), postData) + done() + }) + } + }, function (error) { + if (error) return done(error) + w.loadURL(url) + }) + }) + }) }) -- 2.7.4