toolkit/devtools/tests/unit/test_safeErrorString.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: js; js-indent-level: 2; -*- */
     2 /* Any copyright is dedicated to the Public Domain.
     3    http://creativecommons.org/publicdomain/zero/1.0/ */
     5 // Test DevToolsUtils.safeErrorString
     7 function run_test() {
     8   test_with_error();
     9   test_with_tricky_error();
    10   test_with_string();
    11   test_with_thrower();
    12   test_with_psychotic();
    13 }
    15 function test_with_error() {
    16   let s = DevToolsUtils.safeErrorString(new Error("foo bar"));
    17   // Got the message.
    18   do_check_true(s.contains("foo bar"));
    19   // Got the stack.
    20   do_check_true(s.contains("test_with_error"))
    21   do_check_true(s.contains("test_safeErrorString.js"));
    22   // Got the lineNumber and columnNumber.
    23   do_check_true(s.contains("Line"));
    24   do_check_true(s.contains("column"));
    25 }
    27 function test_with_tricky_error() {
    28   let e = new Error("batman");
    29   e.stack = { toString: Object.create(null) };
    30   let s = DevToolsUtils.safeErrorString(e);
    31   // Still got the message, despite a bad stack property.
    32   do_check_true(s.contains("batman"));
    33 }
    35 function test_with_string() {
    36   let s = DevToolsUtils.safeErrorString("not really an error");
    37   // Still get the message.
    38   do_check_true(s.contains("not really an error"));
    39 }
    41 function test_with_thrower() {
    42   let s = DevToolsUtils.safeErrorString({
    43     toString: () => {
    44       throw new Error("Muahahaha");
    45     }
    46   });
    47   // Still don't fail, get string back.
    48   do_check_eq(typeof s, "string");
    49 }
    51 function test_with_psychotic() {
    52   let s = DevToolsUtils.safeErrorString({
    53     toString: () => Object.create(null)
    54   });
    55   // Still get a string out, and no exceptions thrown
    56   do_check_eq(typeof s, "string");
    57 }

mercurial