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.

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

mercurial