mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-12 14:37:50 +00:00
61572eda35
--HG-- rename : toolkit/mozapps/shared/CertUtils.jsm => toolkit/modules/CertUtils.jsm rename : toolkit/content/DeferredTask.jsm => toolkit/modules/DeferredTask.jsm rename : toolkit/content/Deprecated.jsm => toolkit/modules/Deprecated.jsm rename : toolkit/content/Dict.jsm => toolkit/modules/Dict.jsm rename : toolkit/mozapps/shared/FileUtils.jsm => toolkit/modules/FileUtils.jsm rename : toolkit/content/Geometry.jsm => toolkit/modules/Geometry.jsm rename : toolkit/content/InlineSpellChecker.jsm => toolkit/modules/InlineSpellChecker.jsm rename : toolkit/content/LightweightThemeConsumer.jsm => toolkit/modules/LightweightThemeConsumer.jsm rename : toolkit/content/PageMenu.jsm => toolkit/modules/PageMenu.jsm rename : toolkit/content/PopupNotifications.jsm => toolkit/modules/PopupNotifications.jsm rename : toolkit/content/PrivateBrowsingUtils.jsm => toolkit/modules/PrivateBrowsingUtils.jsm rename : toolkit/content/PropertyListUtils.jsm => toolkit/modules/PropertyListUtils.jsm rename : toolkit/content/Services.jsm => toolkit/modules/Services.jsm rename : toolkit/content/Task.jsm => toolkit/modules/Task.jsm rename : toolkit/content/Troubleshoot.jsm => toolkit/modules/Troubleshoot.jsm rename : toolkit/content/UpdateChannel.jsm => toolkit/modules/UpdateChannel.jsm rename : toolkit/content/WindowDraggingUtils.jsm => toolkit/modules/WindowDraggingUtils.jsm rename : toolkit/content/debug.js => toolkit/modules/debug.js rename : toolkit/content/tests/browser/browser_DeferredTask.js => toolkit/modules/tests/browser/browser_DeferredTask.js rename : toolkit/content/tests/browser/browser_Deprecated.js => toolkit/modules/tests/browser/browser_Deprecated.js rename : toolkit/content/tests/browser/browser_Geometry.js => toolkit/modules/tests/browser/browser_Geometry.js rename : toolkit/content/tests/browser/browser_InlineSpellChecker.js => toolkit/modules/tests/browser/browser_InlineSpellChecker.js rename : toolkit/content/tests/browser/browser_Services.js => toolkit/modules/tests/browser/browser_Services.js rename : toolkit/content/tests/browser/browser_Troubleshoot.js => toolkit/modules/tests/browser/browser_Troubleshoot.js rename : toolkit/mozapps/shared/test/chrome/Makefile.in => toolkit/modules/tests/chrome/Makefile.in rename : toolkit/mozapps/shared/test/chrome/moz.build => toolkit/modules/tests/chrome/moz.build rename : toolkit/mozapps/shared/test/chrome/test_bug544442_checkCert.xul => toolkit/modules/tests/chrome/test_bug544442_checkCert.xul rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListBinary.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListBinary.plist rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListXML.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListXML.plist rename : toolkit/mozapps/shared/test/unit/test_FileUtils.js => toolkit/modules/tests/xpcshell/test_FileUtils.js rename : toolkit/content/tests/unit/test_dict.js => toolkit/modules/tests/xpcshell/test_dict.js rename : toolkit/content/tests/unit/test_propertyListsUtils.js => toolkit/modules/tests/xpcshell/test_propertyListsUtils.js rename : toolkit/mozapps/shared/test/unit/test_readCertPrefs.js => toolkit/modules/tests/xpcshell/test_readCertPrefs.js rename : toolkit/content/tests/unit/test_task.js => toolkit/modules/tests/xpcshell/test_task.js
158 lines
4.5 KiB
JavaScript
158 lines
4.5 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
const Ci = Components.interfaces;
|
|
const Cu = Components.utils;
|
|
const PREF_DEPRECATION_WARNINGS = "devtools.errorconsole.deprecation_warnings";
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm", this);
|
|
Cu.import("resource://gre/modules/Deprecated.jsm", this);
|
|
|
|
// Using this named functions to test deprecation and the properly logged
|
|
// callstacks.
|
|
function basicDeprecatedFunction () {
|
|
Deprecated.warning("this method is deprecated.", "http://example.com");
|
|
return true;
|
|
}
|
|
|
|
function deprecationFunctionBogusCallstack () {
|
|
Deprecated.warning("this method is deprecated.", "http://example.com", {
|
|
caller: {}
|
|
});
|
|
return true;
|
|
}
|
|
|
|
function deprecationFunctionCustomCallstack () {
|
|
// Get the nsIStackFrame that will contain the name of this function.
|
|
function getStack () {
|
|
return Components.stack;
|
|
}
|
|
Deprecated.warning("this method is deprecated.", "http://example.com",
|
|
getStack());
|
|
return true;
|
|
}
|
|
|
|
let tests = [
|
|
// Test deprecation warning without passing the callstack.
|
|
{
|
|
deprecatedFunction: basicDeprecatedFunction,
|
|
expectedObservation: function (aMessage) {
|
|
testAMessage(aMessage);
|
|
ok(aMessage.errorMessage.indexOf("basicDeprecatedFunction") > 0,
|
|
"Callstack is correctly logged.");
|
|
}
|
|
},
|
|
// Test a reported error when URL to documentation is not passed.
|
|
{
|
|
deprecatedFunction: function () {
|
|
Deprecated.warning("this method is deprecated.");
|
|
return true;
|
|
},
|
|
expectedObservation: function (aMessage) {
|
|
ok(aMessage.errorMessage.indexOf("must provide a URL") > 0,
|
|
"Deprecation warning logged an empty URL argument.");
|
|
}
|
|
},
|
|
// Test deprecation with a bogus callstack passed as an argument (it will be
|
|
// replaced with the current call stack).
|
|
{
|
|
deprecatedFunction: deprecationFunctionBogusCallstack,
|
|
expectedObservation: function (aMessage) {
|
|
testAMessage(aMessage);
|
|
ok(aMessage.errorMessage.indexOf("deprecationFunctionBogusCallstack") > 0,
|
|
"Callstack is correctly logged.");
|
|
}
|
|
},
|
|
// When pref is unset Deprecated.warning should not log anything.
|
|
{
|
|
deprecatedFunction: basicDeprecatedFunction,
|
|
expectedObservation: null,
|
|
// Set pref to false.
|
|
logWarnings: false
|
|
},
|
|
// Test deprecation with a valid custom callstack passed as an argument.
|
|
{
|
|
deprecatedFunction: deprecationFunctionCustomCallstack,
|
|
expectedObservation: function (aMessage) {
|
|
testAMessage(aMessage);
|
|
ok(aMessage.errorMessage.indexOf("deprecationFunctionCustomCallstack") > 0,
|
|
"Callstack is correctly logged.");
|
|
},
|
|
// Set pref to true.
|
|
logWarnings: true
|
|
}];
|
|
|
|
// Which test are we running now?
|
|
let idx = -1;
|
|
|
|
function test() {
|
|
waitForExplicitFinish();
|
|
|
|
// Check if Deprecated is loaded.
|
|
ok(Deprecated, "Deprecated object exists");
|
|
|
|
nextTest();
|
|
}
|
|
|
|
// Test Consle Message attributes.
|
|
function testAMessage (aMessage) {
|
|
ok(aMessage.errorMessage.indexOf("DEPRECATION WARNING: " +
|
|
"this method is deprecated.") === 0,
|
|
"Deprecation is correctly logged.");
|
|
ok(aMessage.errorMessage.indexOf("http://example.com") > 0,
|
|
"URL is correctly logged.");
|
|
}
|
|
|
|
function nextTest() {
|
|
idx++;
|
|
|
|
if (idx == tests.length) {
|
|
finish();
|
|
return;
|
|
}
|
|
|
|
info("Running test #" + idx);
|
|
let test = tests[idx];
|
|
|
|
// Deprecation warnings will be logged only when the preference is set.
|
|
if (typeof test.logWarnings !== "undefined") {
|
|
Services.prefs.setBoolPref(PREF_DEPRECATION_WARNINGS, test.logWarnings);
|
|
}
|
|
|
|
// Create a console listener.
|
|
let consoleListener = {
|
|
observe: function (aMessage) {
|
|
// Ignore unexpected messages.
|
|
if (!(aMessage instanceof Ci.nsIScriptError)) {
|
|
return;
|
|
}
|
|
if (aMessage.errorMessage.indexOf("DEPRECATION WARNING: ") < 0 &&
|
|
aMessage.errorMessage.indexOf("must provide a URL") < 0) {
|
|
return;
|
|
}
|
|
ok(aMessage instanceof Ci.nsIScriptError,
|
|
"Deprecation log message is an instance of type nsIScriptError.");
|
|
|
|
|
|
if (test.expectedObservation === null) {
|
|
ok(false, "Deprecated warning not expected");
|
|
}
|
|
else {
|
|
test.expectedObservation(aMessage);
|
|
}
|
|
|
|
Services.console.unregisterListener(consoleListener);
|
|
executeSoon(nextTest);
|
|
}
|
|
};
|
|
Services.console.registerListener(consoleListener);
|
|
test.deprecatedFunction();
|
|
if (test.expectedObservation === null) {
|
|
executeSoon(function() {
|
|
Services.console.unregisterListener(consoleListener);
|
|
executeSoon(nextTest);
|
|
});
|
|
}
|
|
}
|