Add support/tests for did-get-response-details event on <WebView>

This commit is contained in:
Rob Brackett 2016-04-08 12:55:20 -07:00
parent c1b1348735
commit 15b042b5f6
2 changed files with 30 additions and 1 deletions

View file

@ -12,7 +12,7 @@ var WEB_VIEW_EVENTS = {
'did-frame-finish-load': ['isMainFrame'],
'did-start-loading': [],
'did-stop-loading': [],
'did-get-response-details': ['status', 'newURL', 'originalURL', 'httpResponseCode', 'requestMethod', 'referrer', 'headers'],
'did-get-response-details': ['status', 'newURL', 'originalURL', 'httpResponseCode', 'requestMethod', 'referrer', 'headers', 'resourceType'],
'did-get-redirect-request': ['oldURL', 'newURL', 'isMainFrame'],
'dom-ready': [],
'console-message': ['level', 'message', 'line', 'sourceId'],

View file

@ -763,4 +763,33 @@ describe('<webview> tag', function () {
document.body.appendChild(webview)
})
})
describe('did-get-response-details event', function () {
it('emits for the page and its resources', function (done) {
// expected {fileName: resourceType} pairs
var expectedResources = {
'did-get-response-details.html': 'mainFrame',
'logo.png': 'image'
}
var responses = 0;
webview.addEventListener('did-get-response-details', function (event) {
responses++
var fileName = event.newURL.slice(event.newURL.lastIndexOf('/') + 1)
var expectedType = expectedResources[fileName]
assert(!!expectedType, `Unexpected response details for ${event.newURL}`)
assert(typeof event.status === 'boolean', 'status should be boolean')
assert.equal(event.httpResponseCode, 200)
assert.equal(event.requestMethod, 'GET')
assert(typeof event.referrer === 'string', 'referrer should be string')
assert(!!event.headers, 'headers should be present')
assert(typeof event.headers === 'object', 'headers should be object')
assert.equal(event.resourceType, expectedType, 'Incorrect resourceType')
if (responses === Object.keys(expectedResources).length) {
done()
}
})
webview.src = 'file://' + path.join(fixtures, 'pages', 'did-get-response-details.html')
document.body.appendChild(webview)
})
})
})