add basic spec
This commit is contained in:
parent
3aba23b471
commit
a4400dc549
4 changed files with 49 additions and 5 deletions
|
@ -65,7 +65,6 @@ void HandleExternalProtocolInUI(
|
|||
|
||||
void OnPdfStreamCreated(
|
||||
std::unique_ptr<content::StreamInfo> stream,
|
||||
int64_t expected_content_size,
|
||||
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
|
||||
int render_process_id,
|
||||
int render_frame_id) {
|
||||
|
@ -150,7 +149,6 @@ void AtomResourceDispatcherHostDelegate::OnStreamCreated(
|
|||
content::BrowserThread::PostTask(
|
||||
BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&OnPdfStreamCreated, base::Passed(&stream),
|
||||
request->GetExpectedContentSize(),
|
||||
info->GetWebContentsGetterForRequest(), info->GetChildID(),
|
||||
info->GetRenderFrameID()));
|
||||
}
|
||||
|
|
|
@ -276,8 +276,8 @@ void AtomRendererClient::RenderFrameCreated(
|
|||
blink::resetPluginCache();
|
||||
|
||||
// Allow access to file scheme from pdf viewer.
|
||||
blink::WebSecurityPolicy::addOriginAccessWhitelistEntry(GURL(kPdfPluginPath),
|
||||
"file", "", true);
|
||||
blink::WebSecurityPolicy::addOriginAccessWhitelistEntry(
|
||||
GURL(kPdfViewerUIOrigin), "file", "", true);
|
||||
|
||||
// Parse --secure-schemes=scheme1,scheme2
|
||||
std::vector<std::string> secure_schemes_list =
|
||||
|
|
|
@ -3,7 +3,7 @@ const http = require('http')
|
|||
const path = require('path')
|
||||
const ws = require('ws')
|
||||
const url = require('url')
|
||||
const {ipcRenderer, remote} = require('electron')
|
||||
const {ipcRenderer, remote, webFrame} = require('electron')
|
||||
const {closeWindow} = require('./window-helpers')
|
||||
|
||||
const {app, BrowserWindow, ipcMain, protocol, session, webContents} = remote
|
||||
|
@ -802,4 +802,50 @@ describe('chromium feature', function () {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('PDF Viewer', function () {
|
||||
let w = null
|
||||
const pdfSource = `file://${fixtures}/assets/pdf.pdf`
|
||||
|
||||
beforeEach(function () {
|
||||
w = new BrowserWindow({
|
||||
show: false
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
return closeWindow(w).then(function () { w = null })
|
||||
})
|
||||
|
||||
it('opens when loading a pdf resource as top level navigation', function (done) {
|
||||
w.webContents.on('did-finish-load', function () {
|
||||
const parsedURL = url.parse(w.webContents.getURL(), true)
|
||||
assert.equal(parsedURL.protocol, 'chrome:')
|
||||
assert.equal(parsedURL.hostname, 'pdf-viewer')
|
||||
assert.equal(parsedURL.query.src, pdfSource)
|
||||
assert(!!parsedURL.query.streamId.length)
|
||||
})
|
||||
w.webContents.on('page-title-updated', function () {
|
||||
assert.equal(w.webContents.getTitle(), 'PDF')
|
||||
done()
|
||||
})
|
||||
w.webContents.loadURL(pdfSource)
|
||||
})
|
||||
|
||||
it('should not open when pdf is requested as sub resource', function (done) {
|
||||
webFrame.registerURLSchemeAsPrivileged('file', {
|
||||
secure: false,
|
||||
bypassCSP: false,
|
||||
allowServiceWorkers: false,
|
||||
corsEnabled: false
|
||||
})
|
||||
fetch(pdfSource).then(function (res) {
|
||||
assert.equal(res.status, 200)
|
||||
assert.notEqual(document.title, 'PDF')
|
||||
done()
|
||||
}).catch(function (e) {
|
||||
done(e)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
BIN
spec/fixtures/assets/pdf.pdf
vendored
Normal file
BIN
spec/fixtures/assets/pdf.pdf
vendored
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue