From ae297760affd631aa4f011b597f933eae4ad109b Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 24 Aug 2016 06:53:14 +0530 Subject: [PATCH] add spec and docs --- docs/api/protocol.md | 7 ++++--- spec/api-protocol-spec.js | 15 ++++++++++++++- spec/fixtures/pages/filesystem.html | 24 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 spec/fixtures/pages/filesystem.html diff --git a/docs/api/protocol.md b/docs/api/protocol.md index 97e37d3c4b..7000b4f2a8 100644 --- a/docs/api/protocol.md +++ b/docs/api/protocol.md @@ -47,9 +47,10 @@ non-standard schemes can not recognize relative URLs: ``` - -So if you want to register a custom protocol to replace the `http` protocol, you -have to register it as standard scheme: +Registering a scheme as standard, will allow access of files through +the FileSystem API. Otherwise the renderer will throw a security error for the +scheme. So in general if you want to register a custom protocol to replace the +`http` protocol, you have to register it as standard scheme: ```javascript const {app, protocol} = require('electron') diff --git a/spec/api-protocol-spec.js b/spec/api-protocol-spec.js index b27663590a..5caec61620 100644 --- a/spec/api-protocol-spec.js +++ b/spec/api-protocol-spec.js @@ -4,7 +4,7 @@ const path = require('path') const qs = require('querystring') const {closeWindow} = require('./window-helpers') const remote = require('electron').remote -const {BrowserWindow, protocol, webContents} = remote +const {BrowserWindow, ipcMain, protocol, webContents} = remote describe('protocol module', function () { var protocolName = 'sp' @@ -965,5 +965,18 @@ describe('protocol module', function () { w.loadURL(origin) }) }) + + it('can access files through FileSystem API', function (done) { + let filePath = path.join(__dirname, 'fixtures', 'pages', 'filesystem.html') + const handler = function (request, callback) { + callback({path: filePath}) + } + protocol.registerFileProtocol(standardScheme, handler, function (error) { + if (error) return done(error) + w.loadURL(origin) + }) + ipcMain.once('file-system-error', (event, err) => done(err)) + ipcMain.once('file-system-write-end', () => done()) + }) }) }) diff --git a/spec/fixtures/pages/filesystem.html b/spec/fixtures/pages/filesystem.html new file mode 100644 index 0000000000..f8555c5634 --- /dev/null +++ b/spec/fixtures/pages/filesystem.html @@ -0,0 +1,24 @@ +