toolkit/identity/tests/unit/test_log_utils.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/identity/tests/unit/test_log_utils.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +
     1.5 +"use strict";
     1.6 +
     1.7 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
     1.8 +Cu.import('resource://gre/modules/Services.jsm');
     1.9 +Cu.import('resource://gre/modules/identity/LogUtils.jsm');
    1.10 +
    1.11 +function toggle_debug() {
    1.12 +  do_test_pending();
    1.13 +
    1.14 +  function Wrapper() {
    1.15 +    this.init();
    1.16 +  }
    1.17 +  Wrapper.prototype = {
    1.18 +    QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports, Ci.nsIObserver]),
    1.19 +
    1.20 +    observe: function observe(aSubject, aTopic, aData) {
    1.21 +      if (aTopic === "nsPref:changed") {
    1.22 +        // race condition?
    1.23 +        do_check_eq(Logger._debug, true);
    1.24 +        do_test_finished();
    1.25 +        run_next_test();
    1.26 +      }
    1.27 +    },
    1.28 +
    1.29 +    init: function() {
    1.30 +      Services.prefs.addObserver('toolkit.identity.debug', this, false);
    1.31 +    }
    1.32 +  };
    1.33 +
    1.34 +  var wrapper = new Wrapper();
    1.35 +  Services.prefs.setBoolPref('toolkit.identity.debug', true);
    1.36 +}
    1.37 +
    1.38 +// test that things don't break
    1.39 +
    1.40 +function logAlias(...args) {
    1.41 +  Logger.log.apply(Logger, ["log alias"].concat(args));
    1.42 +}
    1.43 +function reportErrorAlias(...args) {
    1.44 +  Logger.reportError.apply(Logger, ["report error alias"].concat(args));
    1.45 +}
    1.46 +
    1.47 +function test_log() {
    1.48 +  Logger.log("log test", "I like pie");
    1.49 +  do_test_finished();
    1.50 +  run_next_test();
    1.51 +}
    1.52 +
    1.53 +function test_reportError() {
    1.54 +  Logger.reportError("log test", "We are out of pies!!!");
    1.55 +  do_test_finished();
    1.56 +  run_next_test();
    1.57 +}
    1.58 +
    1.59 +function test_wrappers() {
    1.60 +  logAlias("I like potatoes");
    1.61 +  do_test_finished();
    1.62 +  reportErrorAlias("Too much red bull");
    1.63 +}
    1.64 +
    1.65 +let TESTS = [
    1.66 +// XXX fix me 
    1.67 +//    toggle_debug,
    1.68 +    test_log,
    1.69 +    test_reportError,
    1.70 +    test_wrappers,
    1.71 +];
    1.72 +
    1.73 +TESTS.forEach(add_test);
    1.74 +
    1.75 +function run_test() {
    1.76 +  run_next_test();
    1.77 +}

mercurial