Commit d9ac3180 d9ac3180f5cf10600926b349e8c79ec1c9778216 by Nicolas Perriault

Merge pull request #726 from n1k0/resource-error-event

Trigger a "resource-error" event on resource loading failure
2 parents ea6b83e3 8a75d22e
...@@ -349,6 +349,16 @@ Emitted when a remote `window.callPhantom(data) <https://github.com/ariya/phanto ...@@ -349,6 +349,16 @@ Emitted when a remote `window.callPhantom(data) <https://github.com/ariya/phanto
349 349
350 Emitted when any remote console logging call has been performed. 350 Emitted when any remote console logging call has been performed.
351 351
352 ``resource.error``
353 ~~~~~~~~~~~~~~~~~~~~~
354
355 **Arguments:** ``resourceError``
356
357 Emitted when any requested resource fails to load properly. The received ``resourceError`` object has the following properties:
358
359 - ``errorCode``: HTTP status code received
360 - ``url``: resource url
361
352 ``resource.received`` 362 ``resource.received``
353 ~~~~~~~~~~~~~~~~~~~~~ 363 ~~~~~~~~~~~~~~~~~~~~~
354 364
......
...@@ -2558,6 +2558,9 @@ function createPage(casper) { ...@@ -2558,6 +2558,9 @@ function createPage(casper) {
2558 casper.options.onResourceRequested.call(casper, casper, requestData, request); 2558 casper.options.onResourceRequested.call(casper, casper, requestData, request);
2559 } 2559 }
2560 }; 2560 };
2561 page.onResourceError = function onResourceError(resourceError) {
2562 casper.emit('resource.error', resourceError);
2563 };
2561 page.onUrlChanged = function onUrlChanged(url) { 2564 page.onUrlChanged = function onUrlChanged(url) {
2562 casper.log(f('url changed to "%s"', url), "debug"); 2565 casper.log(f('url changed to "%s"', url), "debug");
2563 casper.navigationRequested = false; 2566 casper.navigationRequested = false;
......
...@@ -20,3 +20,16 @@ casper.test.begin("Basic resources tests", 5, function(test) { ...@@ -20,3 +20,16 @@ casper.test.begin("Basic resources tests", 5, function(test) {
20 test.done(); 20 test.done();
21 }); 21 });
22 }); 22 });
23
24 casper.test.begin('"resource.error" event', 3, function(test) {
25 casper.on("resource.error", function(error) {
26 test.assertType(error, "object", '"resource.error" triggered error information');
27 test.assert(error.errorCode === 203, '"resource.error" error code is correct');
28 test.assertMatch(error.url, /non-existant\.html$/, '"resource.error" url is correct');
29 });
30
31 casper.start('tests/site/non-existant.html').run(function() {
32 casper.removeAllListeners("resource.error");
33 test.done();
34 });
35 });
......