Commit 8a75d22e 8a75d22ea99dfbe63d523db0cae0232078044b55 by Nicolas Perriault

closes #649 - added resource.error event

1 parent 5fcb2361
......@@ -349,6 +349,16 @@ Emitted when a remote `window.callPhantom(data) <https://github.com/ariya/phanto
Emitted when any remote console logging call has been performed.
``resource.error``
~~~~~~~~~~~~~~~~~~~~~
**Arguments:** ``resourceError``
Emitted when any requested resource fails to load properly. The received ``resourceError`` object has the following properties:
- ``errorCode``: HTTP status code received
- ``url``: resource url
``resource.received``
~~~~~~~~~~~~~~~~~~~~~
......
......@@ -176,17 +176,6 @@ Proxy method for PhantomJS' WebPage#onResourceRequested() callback, but the curr
.. index:: Step stack
``onResourceError``
-------------------------------------------------------------------------------
**Type:** ``Function``
**Default:** ``null``
Proxy method for PhantomJS' WebPage#onResourceError() callback, but the current Casper instance is passed as first argument.
.. index:: Step stack
``onStepComplete``
-------------------------------------------------------------------------------
......
......@@ -97,7 +97,6 @@ var Casper = function Casper(options) {
onPageInitialized: null,
onResourceReceived: null,
onResourceRequested: null,
onResourceError: null,
onRunComplete: function _onRunComplete() {
this.exit();
},
......@@ -2547,9 +2546,6 @@ function createPage(casper) {
};
page.onResourceError = function onResourceError(resourceError) {
casper.emit('resource.error', resourceError);
if (utils.isFunction(casper.options.onResourceError)) {
casper.options.onResourceError.call(casper, casper, resourceError);
}
};
page.onUrlChanged = function onUrlChanged(url) {
casper.log(f('url changed to "%s"', url), "debug");
......
......@@ -50,25 +50,6 @@ casper.test.begin('onResourceRequested() & onResourceReceived() hook tests', 6,
});
});
casper.test.begin('onResourceError() hook tests', 3, function(test) {
var error = null;
casper.options.onResourceError = function(self, resourceError) {
error = resourceError;
};
casper.start('tests/site/non-existant.html', function() {
var expectedPath = '/tests/site/non-existant.html';
test.assert(error !== null, 'onResourceError() called with error information');
test.assert(error.errorCode === 203, 'onResourceError() error code is correct');
test.assert((error.url.indexOf(expectedPath, error.url.length - expectedPath.length) !== -1), 'onResourceError() url is correct');
})
casper.run(function() {
this.options.onResourceError = undefined;
test.done();
});
});
casper.test.begin('onAlert() hook tests', 1, function(test) {
var message;
casper.options.onAlert = function(self, msg) {
......
......@@ -20,3 +20,16 @@ casper.test.begin("Basic resources tests", 5, function(test) {
test.done();
});
});
casper.test.begin('"resource.error" event', 3, function(test) {
casper.on("resource.error", function(error) {
test.assertType(error, "object", '"resource.error" triggered error information');
test.assert(error.errorCode === 203, '"resource.error" error code is correct');
test.assertMatch(error.url, /non-existant\.html$/, '"resource.error" url is correct');
});
casper.start('tests/site/non-existant.html').run(function() {
casper.removeAllListeners("resource.error");
test.done();
});
});
......