sync with master
Showing
4 changed files
with
32 additions
and
3 deletions
... | @@ -2001,7 +2001,10 @@ function createPage(casper) { | ... | @@ -2001,7 +2001,10 @@ function createPage(casper) { |
2001 | } | 2001 | } |
2002 | }; | 2002 | }; |
2003 | page.onConfirm = function onConfirm(message) { | 2003 | page.onConfirm = function onConfirm(message) { |
2004 | return casper.filter('page.confirm', message) || true; | 2004 | if ('page.confirm' in casper._filters) { |
2005 | return casper.filter('page.confirm', message); | ||
2006 | } | ||
2007 | return true; | ||
2005 | }; | 2008 | }; |
2006 | page.onConsoleMessage = function onConsoleMessage(msg) { | 2009 | page.onConsoleMessage = function onConsoleMessage(msg) { |
2007 | // client utils casper console message | 2010 | // client utils casper console message | ... | ... |
... | @@ -19,6 +19,8 @@ | ... | @@ -19,6 +19,8 @@ |
19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | /*global CasperError*/ | ||
23 | |||
22 | var isArray = Array.isArray; | 24 | var isArray = Array.isArray; |
23 | 25 | ||
24 | function EventEmitter() { | 26 | function EventEmitter() { |
... | @@ -230,6 +232,17 @@ EventEmitter.prototype.filter = function() { | ... | @@ -230,6 +232,17 @@ EventEmitter.prototype.filter = function() { |
230 | return filter.apply(this, Array.prototype.splice.call(arguments, 1)); | 232 | return filter.apply(this, Array.prototype.splice.call(arguments, 1)); |
231 | }; | 233 | }; |
232 | 234 | ||
235 | EventEmitter.prototype.removeAllFilters = function(type) { | ||
236 | if (arguments.length === 0) { | ||
237 | this._filters = {}; | ||
238 | return this; | ||
239 | } | ||
240 | if (type && this._filters && this._filters[type]) { | ||
241 | this._filters[type] = null; | ||
242 | } | ||
243 | return this; | ||
244 | }; | ||
245 | |||
233 | EventEmitter.prototype.setFilter = function(type, filterFn) { | 246 | EventEmitter.prototype.setFilter = function(type, filterFn) { |
234 | if (!this._filters) { | 247 | if (!this._filters) { |
235 | this._filters = {}; | 248 | this._filters = {}; | ... | ... |
... | @@ -8,10 +8,22 @@ casper.setFilter('page.confirm', function(message) { | ... | @@ -8,10 +8,22 @@ casper.setFilter('page.confirm', function(message) { |
8 | }); | 8 | }); |
9 | 9 | ||
10 | casper.start('tests/site/confirm.html', function() { | 10 | casper.start('tests/site/confirm.html', function() { |
11 | this.test.assert(this.getGlobal('confirmed'), 'confirmation received'); | 11 | this.test.assert(this.getGlobal('confirmed'), 'confirmation dialog accepted'); |
12 | }); | ||
13 | |||
14 | casper.then(function() { | ||
15 | //remove the page.confirm event filter so we can add a new one | ||
16 | casper.removeAllFilters('page.confirm') | ||
17 | casper.setFilter('page.confirm', function(message) { | ||
18 | return false; | ||
19 | }); | ||
20 | }); | ||
21 | |||
22 | casper.thenOpen('/tests/site/confirm.html', function() { | ||
23 | this.test.assertNot(this.getGlobal('confirmed'), 'confirmation dialog canceled'); | ||
12 | }); | 24 | }); |
13 | 25 | ||
14 | casper.run(function() { | 26 | casper.run(function() { |
15 | this.test.assertEquals(received, 'are you sure?', 'confirmation message is ok'); | 27 | this.test.assertEquals(received, 'are you sure?', 'confirmation message is ok'); |
16 | this.test.done(2); | 28 | this.test.done(3); |
17 | }); | 29 | }); | ... | ... |
-
Please register or sign in to post a comment