forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-debugger-spec.js
129 lines (119 loc) · 3.7 KB
/
api-debugger-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const assert = require('assert')
const path = require('path')
const {closeWindow} = require('./window-helpers')
const BrowserWindow = require('electron').remote.BrowserWindow
describe('debugger module', function () {
var fixtures = path.resolve(__dirname, 'fixtures')
var w = null
beforeEach(function () {
w = new BrowserWindow({
show: false,
width: 400,
height: 400
})
})
afterEach(function () {
return closeWindow(w).then(function () { w = null })
})
describe('debugger.attach', function () {
it('fails when devtools is already open', function (done) {
w.webContents.on('did-finish-load', function () {
w.webContents.openDevTools()
try {
w.webContents.debugger.attach()
} catch (err) {
assert(w.webContents.debugger.isAttached())
done()
}
})
w.webContents.loadURL('file://' + path.join(fixtures, 'pages', 'a.html'))
})
it('fails when protocol version is not supported', function (done) {
try {
w.webContents.debugger.attach('2.0')
} catch (err) {
assert(!w.webContents.debugger.isAttached())
done()
}
})
it('attaches when no protocol version is specified', function (done) {
try {
w.webContents.debugger.attach()
} catch (err) {
done('unexpected error : ' + err)
}
assert(w.webContents.debugger.isAttached())
done()
})
})
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()
})
try {
w.webContents.debugger.attach()
} catch (err) {
done('unexpected error : ' + err)
}
w.webContents.debugger.detach()
})
})
describe('debugger.sendCommand', function () {
it('retuns response', function (done) {
w.webContents.loadURL('about:blank')
try {
w.webContents.debugger.attach()
} catch (err) {
return done('unexpected error : ' + err)
}
var callback = function (err, res) {
assert(!err.message)
assert(!res.wasThrown)
assert.equal(res.result.value, 6)
w.webContents.debugger.detach()
done()
}
const params = {
'expression': '4+2'
}
w.webContents.debugger.sendCommand('Runtime.evaluate', params, callback)
})
it('fires message event', function (done) {
var url = process.platform !== 'win32'
? 'file://' + path.join(fixtures, 'pages', 'a.html')
: 'file:///' + path.join(fixtures, 'pages', 'a.html').replace(/\\/g, '/')
w.webContents.loadURL(url)
try {
w.webContents.debugger.attach()
} catch (err) {
done('unexpected error : ' + err)
}
w.webContents.debugger.on('message', function (e, method, params) {
if (method === 'Console.messageAdded') {
assert.equal(params.message.level, 'log')
assert.equal(params.message.url, url)
assert.equal(params.message.text, 'a')
w.webContents.debugger.detach()
done()
}
})
w.webContents.debugger.sendCommand('Console.enable')
})
it('returns error message when command fails', function (done) {
w.webContents.loadURL('about:blank')
try {
w.webContents.debugger.attach()
} catch (err) {
done('unexpected error : ' + err)
}
w.webContents.debugger.sendCommand('Test', function (err) {
assert.equal(err.message, "'Test' wasn't found")
w.webContents.debugger.detach()
done()
})
})
})
})