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.

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

mercurial