Skip to content

Commit

Permalink
chore: fix chromium-spec.js
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 committed Jan 8, 2019
1 parent 80adc68 commit 9f71fc2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
22 changes: 9 additions & 13 deletions spec/chromium-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,19 +1005,11 @@ describe('chromium feature', () => {
})

it('cannot access localStorage', (done) => {
contents.on('crashed', (event, killed) => {
// Site isolation ON: process is killed for trying to access resources without permission.
if (process.platform !== 'win32') {
// Chromium on Windows does not set this flag correctly.
assert.strictEqual(killed, true, 'Process should\'ve been killed')
}
done()
})
ipcMain.once('local-storage-response', (event, message) => {
// Site isolation OFF: access is refused.
assert.strictEqual(
message,
'Failed to read the \'localStorage\' property from \'Window\': Access is denied for this document.')
done()
})
contents.loadURL(protocolName + '://host/localStorage')
})
Expand All @@ -1036,23 +1028,27 @@ describe('chromium feature', () => {
ipcMain.once('web-sql-response', (event, error) => {
assert.strictEqual(
error,
'An attempt was made to break through the security policy of the user agent.')
'Failed to execute \'openDatabase\' on \'Window\': Access to the WebDatabase API is denied in this context.')
done()
})
contents.loadURL(`${protocolName}://host/WebSQL`)
})

it('cannot access indexedDB', (done) => {
ipcMain.once('indexed-db-response', (event, error) => {
assert.strictEqual(error, 'The user denied permission to access the database.')
assert.strictEqual(
error,
'Failed to execute \'open\' on \'IDBFactory\': access to the Indexed Database API is denied in this context.')
done()
})
contents.loadURL(`${protocolName}://host/indexedDB`)
})

it('cannot access cookie', (done) => {
ipcMain.once('cookie-response', (event, cookie) => {
assert(!cookie)
ipcMain.once('cookie-response', (event, error) => {
assert.strictEqual(
error,
'Failed to set the \'cookie\' property on \'Document\': Access is denied for this document.')
done()
})
contents.loadURL(`${protocolName}://host/cookie`)
Expand Down
9 changes: 6 additions & 3 deletions spec/fixtures/pages/storage/cookie.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<script>
const {ipcRenderer} = require('electron')
document.cookie = "test=123"
ipcRenderer.send('cookie-response', document.cookie)
try {
document.cookie = "test=123"
} catch (e) {
const {ipcRenderer} = require('electron')
ipcRenderer.send('cookie-response', e.message)
}
</script>
7 changes: 4 additions & 3 deletions spec/fixtures/pages/storage/indexed_db.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script>
let req = window.indexedDB.open('test')
req.onerror = function (event) {
try {
let req = window.indexedDB.open('test')
} catch (e) {
const {ipcRenderer} = require('electron')
ipcRenderer.send('indexed-db-response', event.target.error.message)
ipcRenderer.send('indexed-db-response', e.message)
}
</script>
7 changes: 2 additions & 5 deletions spec/fixtures/pages/storage/local_storage.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<script>
const {ipcRenderer} = require('electron')

let message = 'Ok'
try {
window.localStorage
} catch (e) {
message = e.message
const {ipcRenderer} = require('electron')
ipcRenderer.send('local-storage-response', e.message)
}
ipcRenderer.send('local-storage-response', message)
</script>

0 comments on commit 9f71fc2

Please sign in to comment.