2013-12-27 06:58:13 +00:00
|
|
|
assert = require 'assert'
|
2014-05-08 01:20:01 +00:00
|
|
|
http = require 'http'
|
2015-03-10 07:09:23 +00:00
|
|
|
https = require 'https'
|
2014-03-04 14:04:41 +00:00
|
|
|
path = require 'path'
|
2015-07-14 18:38:30 +00:00
|
|
|
ws = require 'ws'
|
2015-11-12 10:28:04 +00:00
|
|
|
|
|
|
|
{remote} = require 'electron'
|
|
|
|
{BrowserWindow} = remote.require 'electron'
|
2013-12-27 06:58:13 +00:00
|
|
|
|
2013-12-15 16:31:40 +00:00
|
|
|
describe 'chromium feature', ->
|
2014-03-04 14:04:41 +00:00
|
|
|
fixtures = path.resolve __dirname, 'fixtures'
|
|
|
|
|
2015-10-06 07:43:36 +00:00
|
|
|
listener = null
|
|
|
|
afterEach ->
|
|
|
|
if listener?
|
|
|
|
window.removeEventListener 'message', listener
|
|
|
|
listener = null
|
|
|
|
|
2015-08-27 12:21:05 +00:00
|
|
|
xdescribe 'heap snapshot', ->
|
2013-12-06 14:23:02 +00:00
|
|
|
it 'does not crash', ->
|
|
|
|
process.atomBinding('v8_util').takeHeapSnapshot()
|
|
|
|
|
2015-03-18 04:55:44 +00:00
|
|
|
describe 'sending request of http protocol urls', ->
|
2014-05-08 01:20:01 +00:00
|
|
|
it 'does not crash', (done) ->
|
2014-05-07 15:12:24 +00:00
|
|
|
@timeout 5000
|
2015-03-18 04:55:44 +00:00
|
|
|
server = http.createServer (req, res) ->
|
|
|
|
res.end()
|
|
|
|
server.close()
|
|
|
|
done()
|
|
|
|
server.listen 0, '127.0.0.1', ->
|
|
|
|
{port} = server.address()
|
|
|
|
$.get "http://127.0.0.1:#{port}"
|
2013-12-06 14:23:02 +00:00
|
|
|
|
2015-09-22 16:51:49 +00:00
|
|
|
describe 'document.hidden', ->
|
|
|
|
url = "file://#{fixtures}/pages/document-hidden.html"
|
|
|
|
w = null
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
w?.destroy()
|
|
|
|
|
|
|
|
it 'is set correctly when window is not shown', (done) ->
|
|
|
|
w = new BrowserWindow(show:false)
|
2015-10-06 07:43:36 +00:00
|
|
|
w.webContents.on 'ipc-message', (event, args) ->
|
|
|
|
assert.deepEqual args, ['hidden', true]
|
|
|
|
done()
|
2015-11-13 08:03:40 +00:00
|
|
|
w.loadURL url
|
2015-09-22 16:51:49 +00:00
|
|
|
|
2015-12-12 07:32:49 +00:00
|
|
|
xdescribe 'navigator.webkitGetUserMedia', ->
|
2013-12-06 14:23:02 +00:00
|
|
|
it 'calls its callbacks', (done) ->
|
|
|
|
@timeout 5000
|
|
|
|
navigator.webkitGetUserMedia audio: true, video: false,
|
|
|
|
-> done()
|
|
|
|
-> done()
|
2013-12-27 06:58:13 +00:00
|
|
|
|
2014-05-29 12:23:28 +00:00
|
|
|
describe 'navigator.language', ->
|
|
|
|
it 'should not be empty', ->
|
|
|
|
assert.notEqual navigator.language, ''
|
|
|
|
|
2013-12-27 06:58:13 +00:00
|
|
|
describe 'window.open', ->
|
2015-10-06 08:08:32 +00:00
|
|
|
@timeout 10000
|
|
|
|
|
2015-03-04 16:46:45 +00:00
|
|
|
it 'returns a BrowserWindowProxy object', ->
|
2015-09-09 08:11:45 +00:00
|
|
|
b = window.open 'about:blank', '', 'show=no'
|
2015-08-05 08:03:08 +00:00
|
|
|
assert.equal b.closed, false
|
2015-03-04 16:46:45 +00:00
|
|
|
assert.equal b.constructor.name, 'BrowserWindowProxy'
|
2014-10-27 13:56:04 +00:00
|
|
|
b.close()
|
2014-03-04 14:04:41 +00:00
|
|
|
|
2015-09-09 08:11:45 +00:00
|
|
|
it 'accepts "node-integration" as feature', (done) ->
|
|
|
|
listener = (event) ->
|
|
|
|
assert.equal event.data, 'undefined'
|
2015-10-06 07:43:36 +00:00
|
|
|
b.close()
|
2015-09-09 08:11:45 +00:00
|
|
|
done()
|
|
|
|
window.addEventListener 'message', listener
|
2015-11-10 14:23:21 +00:00
|
|
|
b = window.open "file://#{fixtures}/pages/window-opener-node.html", '', 'nodeIntegration=no,show=no'
|
2015-09-09 08:11:45 +00:00
|
|
|
|
2015-09-22 14:36:46 +00:00
|
|
|
it 'inherit options of parent window', (done) ->
|
|
|
|
listener = (event) ->
|
2015-12-02 19:50:44 +00:00
|
|
|
[width, height] = remote.getCurrentWindow().getSize()
|
|
|
|
assert.equal event.data, "size: #{width} #{height}"
|
2015-10-06 07:43:36 +00:00
|
|
|
b.close()
|
2015-09-22 14:36:46 +00:00
|
|
|
done()
|
|
|
|
window.addEventListener 'message', listener
|
|
|
|
b = window.open "file://#{fixtures}/pages/window-open-size.html", '', 'show=no'
|
|
|
|
|
2015-12-02 19:54:52 +00:00
|
|
|
it 'does not override child options', (done) ->
|
|
|
|
size = {width: 350, height: 450}
|
|
|
|
listener = (event) ->
|
|
|
|
assert.equal event.data, "size: #{size.width} #{size.height}"
|
|
|
|
b.close()
|
|
|
|
done()
|
|
|
|
window.addEventListener 'message', listener
|
|
|
|
b = window.open "file://#{fixtures}/pages/window-open-size.html", '', "show=no,width=#{size.width},height=#{size.height}"
|
|
|
|
|
2015-08-04 07:46:59 +00:00
|
|
|
describe 'window.opener', ->
|
2015-10-06 08:08:32 +00:00
|
|
|
@timeout 10000
|
|
|
|
|
2015-08-04 07:46:59 +00:00
|
|
|
url = "file://#{fixtures}/pages/window-opener.html"
|
|
|
|
w = null
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
w?.destroy()
|
|
|
|
|
|
|
|
it 'is null for main window', (done) ->
|
|
|
|
w = new BrowserWindow(show: false)
|
2015-10-06 07:43:36 +00:00
|
|
|
w.webContents.on 'ipc-message', (event, args) ->
|
|
|
|
assert.deepEqual args, ['opener', null]
|
|
|
|
done()
|
2015-11-13 08:03:40 +00:00
|
|
|
w.loadURL url
|
2015-08-04 07:46:59 +00:00
|
|
|
|
|
|
|
it 'is not null for window opened by window.open', (done) ->
|
2015-10-06 07:43:36 +00:00
|
|
|
listener = (event) ->
|
|
|
|
assert.equal event.data, 'object'
|
2015-08-04 07:46:59 +00:00
|
|
|
b.close()
|
2015-10-06 07:43:36 +00:00
|
|
|
done()
|
|
|
|
window.addEventListener 'message', listener
|
2015-09-15 06:26:46 +00:00
|
|
|
b = window.open url, '', 'show=no'
|
2015-08-04 07:46:59 +00:00
|
|
|
|
2015-12-11 00:49:23 +00:00
|
|
|
describe 'window.postMessage', ->
|
|
|
|
it 'sets the origin correctly', (done) ->
|
|
|
|
listener = (event) ->
|
|
|
|
window.removeEventListener 'message', listener
|
|
|
|
b.close()
|
2015-12-14 22:55:48 +00:00
|
|
|
message = JSON.parse(event.data)
|
|
|
|
assert.equal message.data, 'testing'
|
|
|
|
assert.equal message.origin, 'file://'
|
|
|
|
assert.equal message.sourceEqualsOpener, true
|
2015-12-11 00:49:23 +00:00
|
|
|
assert.equal event.origin, 'file://'
|
|
|
|
done()
|
|
|
|
window.addEventListener 'message', listener
|
|
|
|
b = window.open "file://#{fixtures}/pages/window-open-postMessage.html", '', 'show=no'
|
|
|
|
BrowserWindow.fromId(b.guestId).webContents.once 'did-finish-load', ->
|
|
|
|
b.postMessage('testing', '*')
|
|
|
|
|
2015-09-01 04:15:00 +00:00
|
|
|
describe 'window.opener.postMessage', ->
|
|
|
|
it 'sets source and origin correctly', (done) ->
|
2015-09-09 08:11:45 +00:00
|
|
|
listener = (event) ->
|
|
|
|
window.removeEventListener 'message', listener
|
2015-09-01 04:15:00 +00:00
|
|
|
b.close()
|
2015-12-11 01:04:36 +00:00
|
|
|
assert.equal event.source, b
|
2015-09-01 04:15:00 +00:00
|
|
|
assert.equal event.origin, 'file://'
|
|
|
|
done()
|
2015-09-09 08:11:45 +00:00
|
|
|
window.addEventListener 'message', listener
|
|
|
|
b = window.open "file://#{fixtures}/pages/window-opener-postMessage.html", '', 'show=no'
|
2015-09-01 04:15:00 +00:00
|
|
|
|
2014-05-14 08:10:33 +00:00
|
|
|
describe 'creating a Uint8Array under browser side', ->
|
|
|
|
it 'does not crash', ->
|
2015-08-04 07:46:59 +00:00
|
|
|
RUint8Array = remote.getGlobal 'Uint8Array'
|
2014-05-14 08:10:33 +00:00
|
|
|
new RUint8Array
|
2014-05-18 14:37:59 +00:00
|
|
|
|
|
|
|
describe 'webgl', ->
|
|
|
|
it 'can be get as context in canvas', ->
|
2014-05-19 02:00:59 +00:00
|
|
|
return if process.platform is 'linux'
|
2014-05-18 14:37:59 +00:00
|
|
|
webgl = document.createElement('canvas').getContext 'webgl'
|
|
|
|
assert.notEqual webgl, null
|
2014-07-09 07:55:01 +00:00
|
|
|
|
|
|
|
describe 'web workers', ->
|
|
|
|
it 'Worker can work', (done) ->
|
|
|
|
worker = new Worker('../fixtures/workers/worker.js')
|
|
|
|
message = 'ping'
|
|
|
|
worker.onmessage = (event) ->
|
|
|
|
assert.equal event.data, message
|
|
|
|
worker.terminate()
|
|
|
|
done()
|
|
|
|
worker.postMessage message
|
|
|
|
|
|
|
|
it 'SharedWorker can work', (done) ->
|
|
|
|
worker = new SharedWorker('../fixtures/workers/shared_worker.js')
|
|
|
|
message = 'ping'
|
|
|
|
worker.port.onmessage = (event) ->
|
|
|
|
assert.equal event.data, message
|
|
|
|
done()
|
|
|
|
worker.port.postMessage message
|
2015-01-22 01:05:19 +00:00
|
|
|
|
|
|
|
describe 'iframe', ->
|
|
|
|
iframe = null
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
iframe = document.createElement 'iframe'
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
document.body.removeChild iframe
|
|
|
|
|
|
|
|
it 'does not have node integration', (done) ->
|
|
|
|
iframe.src = "file://#{fixtures}/pages/set-global.html"
|
|
|
|
document.body.appendChild iframe
|
|
|
|
iframe.onload = ->
|
|
|
|
assert.equal iframe.contentWindow.test, 'undefined undefined undefined'
|
|
|
|
done()
|
2015-05-12 12:33:00 +00:00
|
|
|
|
|
|
|
describe 'storage', ->
|
|
|
|
it 'requesting persitent quota works', (done) ->
|
|
|
|
navigator.webkitPersistentStorage.requestQuota 1024 * 1024, (grantedBytes) ->
|
|
|
|
assert.equal grantedBytes, 1048576
|
|
|
|
done()
|
2015-07-14 18:38:30 +00:00
|
|
|
|
|
|
|
describe 'websockets', ->
|
|
|
|
wss = null
|
|
|
|
server = null
|
|
|
|
WebSocketServer = ws.Server
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
wss.close()
|
|
|
|
server.close()
|
|
|
|
|
|
|
|
it 'has user agent', (done) ->
|
|
|
|
server = http.createServer()
|
|
|
|
server.listen 0, '127.0.0.1', ->
|
|
|
|
port = server.address().port
|
|
|
|
wss = new WebSocketServer(server: server)
|
|
|
|
wss.on 'error', done
|
|
|
|
wss.on 'connection', (ws) ->
|
|
|
|
if ws.upgradeReq.headers['user-agent']
|
|
|
|
done()
|
|
|
|
else
|
|
|
|
done('user agent is empty')
|
|
|
|
websocket = new WebSocket("ws://127.0.0.1:#{port}")
|
2015-08-07 08:55:16 +00:00
|
|
|
|
|
|
|
describe 'Promise', ->
|
|
|
|
it 'resolves correctly in Node.js calls', (done) ->
|
|
|
|
document.registerElement('x-element', {
|
|
|
|
prototype: Object.create(HTMLElement.prototype, {
|
|
|
|
createdCallback: { value: -> }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
setImmediate ->
|
|
|
|
called = false
|
|
|
|
Promise.resolve().then ->
|
2015-12-11 01:02:35 +00:00
|
|
|
done(if called then undefined else new Error('wrong sequence'))
|
2015-08-07 08:55:16 +00:00
|
|
|
document.createElement 'x-element'
|
|
|
|
called = true
|
|
|
|
|
|
|
|
it 'resolves correctly in Electron calls', (done) ->
|
|
|
|
document.registerElement('y-element', {
|
|
|
|
prototype: Object.create(HTMLElement.prototype, {
|
|
|
|
createdCallback: { value: -> }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
remote.getGlobal('setImmediate') ->
|
|
|
|
called = false
|
|
|
|
Promise.resolve().then ->
|
2015-12-11 01:02:35 +00:00
|
|
|
done(if called then undefined else new Error('wrong sequence'))
|
2015-08-07 08:55:16 +00:00
|
|
|
document.createElement 'y-element'
|
|
|
|
called = true
|