Commit f8517450 f8517450ce108387e4dd65c1603fc71ba13f5f52 by Nicolas Perriault

sync with master

2 parents 75a5d399 8fa8d23a
branches:
only:
- master
- testcase
before_script:
- "npm install -g jshint"
- "phantomjs --version"
......
......@@ -2001,7 +2001,10 @@ function createPage(casper) {
}
};
page.onConfirm = function onConfirm(message) {
return casper.filter('page.confirm', message) || true;
if ('page.confirm' in casper._filters) {
return casper.filter('page.confirm', message);
}
return true;
};
page.onConsoleMessage = function onConsoleMessage(msg) {
// client utils casper console message
......
......@@ -19,6 +19,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
/*global CasperError*/
var isArray = Array.isArray;
function EventEmitter() {
......@@ -230,6 +232,17 @@ EventEmitter.prototype.filter = function() {
return filter.apply(this, Array.prototype.splice.call(arguments, 1));
};
EventEmitter.prototype.removeAllFilters = function(type) {
if (arguments.length === 0) {
this._filters = {};
return this;
}
if (type && this._filters && this._filters[type]) {
this._filters[type] = null;
}
return this;
};
EventEmitter.prototype.setFilter = function(type, filterFn) {
if (!this._filters) {
this._filters = {};
......
......@@ -8,10 +8,22 @@ casper.setFilter('page.confirm', function(message) {
});
casper.start('tests/site/confirm.html', function() {
this.test.assert(this.getGlobal('confirmed'), 'confirmation received');
this.test.assert(this.getGlobal('confirmed'), 'confirmation dialog accepted');
});
casper.then(function() {
//remove the page.confirm event filter so we can add a new one
casper.removeAllFilters('page.confirm')
casper.setFilter('page.confirm', function(message) {
return false;
});
});
casper.thenOpen('/tests/site/confirm.html', function() {
this.test.assertNot(this.getGlobal('confirmed'), 'confirmation dialog canceled');
});
casper.run(function() {
this.test.assertEquals(received, 'are you sure?', 'confirmation message is ok');
this.test.done(2);
this.test.done(3);
});
......