testing/mochitest/tests/browser/browser_fail_add_task.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 "use strict";
michael@0 5
michael@0 6 // This test is designed to fail.
michael@0 7 // It ensures that throwing an asynchronous error from add_task will
michael@0 8 // fail the test.
michael@0 9
michael@0 10 let passedTests = 0;
michael@0 11
michael@0 12 function rejectWithTimeout(error = undefined) {
michael@0 13 let deferred = Promise.defer();
michael@0 14 executeSoon(function() {
michael@0 15 ok(true, "we get here after a timeout");
michael@0 16 deferred.reject(error);
michael@0 17 });
michael@0 18 return deferred.promise;
michael@0 19 }
michael@0 20
michael@0 21 add_task(function failWithoutError() {
michael@0 22 try {
michael@0 23 yield rejectWithTimeout();
michael@0 24 } finally {
michael@0 25 ++passedTests;
michael@0 26 }
michael@0 27 });
michael@0 28
michael@0 29 add_task(function failWithString() {
michael@0 30 try {
michael@0 31 yield rejectWithTimeout("Meaningless error");
michael@0 32 } finally {
michael@0 33 ++passedTests;
michael@0 34 }
michael@0 35 });
michael@0 36
michael@0 37 add_task(function failWithoutInt() {
michael@0 38 try {
michael@0 39 yield rejectWithTimeout(42);
michael@0 40 } finally {
michael@0 41 ++passedTests;
michael@0 42 }
michael@0 43 });
michael@0 44
michael@0 45
michael@0 46 // This one should display a stack trace
michael@0 47 add_task(function failWithError() {
michael@0 48 try {
michael@0 49 yield rejectWithTimeout(new Error("This is an error"));
michael@0 50 } finally {
michael@0 51 ++passedTests;
michael@0 52 }
michael@0 53 });
michael@0 54
michael@0 55 add_task(function done() {
michael@0 56 is(passedTests, 4, "Passed all tests");
michael@0 57 });

mercurial