1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mochitest/tests/browser/browser_fail_add_task.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +"use strict"; 1.8 + 1.9 +// This test is designed to fail. 1.10 +// It ensures that throwing an asynchronous error from add_task will 1.11 +// fail the test. 1.12 + 1.13 +let passedTests = 0; 1.14 + 1.15 +function rejectWithTimeout(error = undefined) { 1.16 + let deferred = Promise.defer(); 1.17 + executeSoon(function() { 1.18 + ok(true, "we get here after a timeout"); 1.19 + deferred.reject(error); 1.20 + }); 1.21 + return deferred.promise; 1.22 +} 1.23 + 1.24 +add_task(function failWithoutError() { 1.25 + try { 1.26 + yield rejectWithTimeout(); 1.27 + } finally { 1.28 + ++passedTests; 1.29 + } 1.30 +}); 1.31 + 1.32 +add_task(function failWithString() { 1.33 + try { 1.34 + yield rejectWithTimeout("Meaningless error"); 1.35 + } finally { 1.36 + ++passedTests; 1.37 + } 1.38 +}); 1.39 + 1.40 +add_task(function failWithoutInt() { 1.41 + try { 1.42 + yield rejectWithTimeout(42); 1.43 + } finally { 1.44 + ++passedTests; 1.45 + } 1.46 +}); 1.47 + 1.48 + 1.49 +// This one should display a stack trace 1.50 +add_task(function failWithError() { 1.51 + try { 1.52 + yield rejectWithTimeout(new Error("This is an error")); 1.53 + } finally { 1.54 + ++passedTests; 1.55 + } 1.56 +}); 1.57 + 1.58 +add_task(function done() { 1.59 + is(passedTests, 4, "Passed all tests"); 1.60 +});