2016-03-25 23:03:49 +03:00
|
|
|
const assert = require('assert')
|
|
|
|
const path = require('path')
|
2016-08-03 22:47:53 +03:00
|
|
|
const {closeWindow} = require('./window-helpers')
|
2016-03-25 23:03:49 +03:00
|
|
|
const BrowserWindow = require('electron').remote.BrowserWindow
|
2016-01-22 11:47:23 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
describe('debugger module', function () {
|
|
|
|
var fixtures = path.resolve(__dirname, 'fixtures')
|
|
|
|
var w = null
|
2016-02-17 04:09:41 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
beforeEach(function () {
|
2016-01-22 11:47:23 +03:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
})
|
2016-02-17 04:09:41 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
afterEach(function () {
|
2016-08-03 22:47:53 +03:00
|
|
|
return closeWindow(w).then(function () { w = null })
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
2016-01-22 11:47:23 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
describe('debugger.attach', function () {
|
|
|
|
it('fails when devtools is already open', function (done) {
|
|
|
|
w.webContents.on('did-finish-load', function () {
|
|
|
|
w.webContents.openDevTools()
|
2016-01-22 11:47:23 +03:00
|
|
|
try {
|
2016-03-25 23:03:49 +03:00
|
|
|
w.webContents.debugger.attach()
|
2016-03-29 02:19:18 +03:00
|
|
|
} catch (err) {
|
2016-03-25 23:03:49 +03:00
|
|
|
assert(w.webContents.debugger.isAttached())
|
|
|
|
done()
|
2016-01-22 11:47:23 +03:00
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
w.webContents.loadURL('file://' + path.join(fixtures, 'pages', 'a.html'))
|
|
|
|
})
|
2016-01-22 11:47:23 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('fails when protocol version is not supported', function (done) {
|
2016-01-22 11:47:23 +03:00
|
|
|
try {
|
2016-03-25 23:03:49 +03:00
|
|
|
w.webContents.debugger.attach('2.0')
|
2016-03-29 02:19:18 +03:00
|
|
|
} catch (err) {
|
2016-03-25 23:03:49 +03:00
|
|
|
assert(!w.webContents.debugger.isAttached())
|
|
|
|
done()
|
2016-01-22 11:47:23 +03:00
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
2016-01-22 11:47:23 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('attaches when no protocol version is specified', function (done) {
|
2016-01-22 11:47:23 +03:00
|
|
|
try {
|
2016-03-25 23:03:49 +03:00
|
|
|
w.webContents.debugger.attach()
|
2016-03-29 02:19:18 +03:00
|
|
|
} catch (err) {
|
2016-03-25 23:03:49 +03:00
|
|
|
done('unexpected error : ' + err)
|
2016-01-22 11:47:23 +03:00
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
assert(w.webContents.debugger.isAttached())
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2016-01-22 11:47:23 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
describe('debugger.detach', function () {
|
|
|
|
it('fires detach event', function (done) {
|
|
|
|
w.webContents.debugger.on('detach', function (e, reason) {
|
|
|
|
assert.equal(reason, 'target closed')
|
|
|
|
assert(!w.webContents.debugger.isAttached())
|
|
|
|
done()
|
|
|
|
})
|
2016-01-22 11:47:23 +03:00
|
|
|
try {
|
2016-03-25 23:03:49 +03:00
|
|
|
w.webContents.debugger.attach()
|
2016-03-29 02:19:18 +03:00
|
|
|
} catch (err) {
|
2016-03-25 23:03:49 +03:00
|
|
|
done('unexpected error : ' + err)
|
2016-01-22 11:47:23 +03:00
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
w.webContents.debugger.detach()
|
|
|
|
})
|
|
|
|
})
|
2016-01-22 11:47:23 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
describe('debugger.sendCommand', function () {
|
|
|
|
it('retuns response', function (done) {
|
|
|
|
w.webContents.loadURL('about:blank')
|
2016-01-22 11:47:23 +03:00
|
|
|
try {
|
2016-03-25 23:03:49 +03:00
|
|
|
w.webContents.debugger.attach()
|
2016-03-29 02:19:18 +03:00
|
|
|
} catch (err) {
|
2016-03-29 02:31:06 +03:00
|
|
|
return done('unexpected error : ' + err)
|
2016-03-25 23:03:49 +03:00
|
|
|
}
|
|
|
|
var callback = function (err, res) {
|
2016-03-31 00:06:50 +03:00
|
|
|
assert(!err.message)
|
2016-03-25 23:03:49 +03:00
|
|
|
assert(!res.wasThrown)
|
|
|
|
assert.equal(res.result.value, 6)
|
|
|
|
w.webContents.debugger.detach()
|
|
|
|
done()
|
2016-01-22 11:47:23 +03:00
|
|
|
}
|
|
|
|
const params = {
|
2016-03-29 02:31:06 +03:00
|
|
|
'expression': '4+2'
|
2016-03-25 23:03:49 +03:00
|
|
|
}
|
|
|
|
w.webContents.debugger.sendCommand('Runtime.evaluate', params, callback)
|
|
|
|
})
|
2016-01-22 11:47:23 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('fires message event', function (done) {
|
2016-03-29 02:31:06 +03:00
|
|
|
var url = process.platform !== 'win32'
|
|
|
|
? 'file://' + path.join(fixtures, 'pages', 'a.html')
|
|
|
|
: 'file:///' + path.join(fixtures, 'pages', 'a.html').replace(/\\/g, '/')
|
2016-03-25 23:03:49 +03:00
|
|
|
w.webContents.loadURL(url)
|
2016-01-22 11:47:23 +03:00
|
|
|
try {
|
2016-03-25 23:03:49 +03:00
|
|
|
w.webContents.debugger.attach()
|
2016-03-29 02:19:18 +03:00
|
|
|
} catch (err) {
|
2016-03-25 23:03:49 +03:00
|
|
|
done('unexpected error : ' + err)
|
2016-01-22 11:47:23 +03:00
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
w.webContents.debugger.on('message', function (e, method, params) {
|
2016-03-29 02:31:06 +03:00
|
|
|
if (method === 'Console.messageAdded') {
|
2016-12-19 22:28:08 +03:00
|
|
|
assert.equal(params.message.level, 'log')
|
2016-03-25 23:03:49 +03:00
|
|
|
assert.equal(params.message.url, url)
|
|
|
|
assert.equal(params.message.text, 'a')
|
|
|
|
w.webContents.debugger.detach()
|
|
|
|
done()
|
2016-01-22 11:47:23 +03:00
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
w.webContents.debugger.sendCommand('Console.enable')
|
|
|
|
})
|
2016-01-22 11:47:23 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('returns error message when command fails', function (done) {
|
|
|
|
w.webContents.loadURL('about:blank')
|
2016-01-22 11:47:23 +03:00
|
|
|
try {
|
2016-03-25 23:03:49 +03:00
|
|
|
w.webContents.debugger.attach()
|
2016-03-29 02:19:18 +03:00
|
|
|
} catch (err) {
|
2016-03-25 23:03:49 +03:00
|
|
|
done('unexpected error : ' + err)
|
2016-01-22 11:47:23 +03:00
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
w.webContents.debugger.sendCommand('Test', function (err) {
|
|
|
|
assert.equal(err.message, "'Test' wasn't found")
|
|
|
|
w.webContents.debugger.detach()
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|