Sat, 03 Jan 2015 20:18:00 +0100
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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const Ci = Components.interfaces; |
michael@0 | 6 | const Cu = Components.utils; |
michael@0 | 7 | const PREF_DEPRECATION_WARNINGS = "devtools.errorconsole.deprecation_warnings"; |
michael@0 | 8 | |
michael@0 | 9 | Cu.import("resource://gre/modules/Services.jsm", this); |
michael@0 | 10 | Cu.import("resource://gre/modules/Deprecated.jsm", this); |
michael@0 | 11 | |
michael@0 | 12 | // Using this named functions to test deprecation and the properly logged |
michael@0 | 13 | // callstacks. |
michael@0 | 14 | function basicDeprecatedFunction () { |
michael@0 | 15 | Deprecated.warning("this method is deprecated.", "http://example.com"); |
michael@0 | 16 | return true; |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function deprecationFunctionBogusCallstack () { |
michael@0 | 20 | Deprecated.warning("this method is deprecated.", "http://example.com", { |
michael@0 | 21 | caller: {} |
michael@0 | 22 | }); |
michael@0 | 23 | return true; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | function deprecationFunctionCustomCallstack () { |
michael@0 | 27 | // Get the nsIStackFrame that will contain the name of this function. |
michael@0 | 28 | function getStack () { |
michael@0 | 29 | return Components.stack; |
michael@0 | 30 | } |
michael@0 | 31 | Deprecated.warning("this method is deprecated.", "http://example.com", |
michael@0 | 32 | getStack()); |
michael@0 | 33 | return true; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | let tests = [ |
michael@0 | 37 | // Test deprecation warning without passing the callstack. |
michael@0 | 38 | { |
michael@0 | 39 | deprecatedFunction: basicDeprecatedFunction, |
michael@0 | 40 | expectedObservation: function (aMessage) { |
michael@0 | 41 | testAMessage(aMessage); |
michael@0 | 42 | ok(aMessage.errorMessage.indexOf("basicDeprecatedFunction") > 0, |
michael@0 | 43 | "Callstack is correctly logged."); |
michael@0 | 44 | } |
michael@0 | 45 | }, |
michael@0 | 46 | // Test a reported error when URL to documentation is not passed. |
michael@0 | 47 | { |
michael@0 | 48 | deprecatedFunction: function () { |
michael@0 | 49 | Deprecated.warning("this method is deprecated."); |
michael@0 | 50 | return true; |
michael@0 | 51 | }, |
michael@0 | 52 | expectedObservation: function (aMessage) { |
michael@0 | 53 | ok(aMessage.errorMessage.indexOf("must provide a URL") > 0, |
michael@0 | 54 | "Deprecation warning logged an empty URL argument."); |
michael@0 | 55 | } |
michael@0 | 56 | }, |
michael@0 | 57 | // Test deprecation with a bogus callstack passed as an argument (it will be |
michael@0 | 58 | // replaced with the current call stack). |
michael@0 | 59 | { |
michael@0 | 60 | deprecatedFunction: deprecationFunctionBogusCallstack, |
michael@0 | 61 | expectedObservation: function (aMessage) { |
michael@0 | 62 | testAMessage(aMessage); |
michael@0 | 63 | ok(aMessage.errorMessage.indexOf("deprecationFunctionBogusCallstack") > 0, |
michael@0 | 64 | "Callstack is correctly logged."); |
michael@0 | 65 | } |
michael@0 | 66 | }, |
michael@0 | 67 | // When pref is unset Deprecated.warning should not log anything. |
michael@0 | 68 | { |
michael@0 | 69 | deprecatedFunction: basicDeprecatedFunction, |
michael@0 | 70 | expectedObservation: null, |
michael@0 | 71 | // Set pref to false. |
michael@0 | 72 | logWarnings: false |
michael@0 | 73 | }, |
michael@0 | 74 | // Test deprecation with a valid custom callstack passed as an argument. |
michael@0 | 75 | { |
michael@0 | 76 | deprecatedFunction: deprecationFunctionCustomCallstack, |
michael@0 | 77 | expectedObservation: function (aMessage) { |
michael@0 | 78 | testAMessage(aMessage); |
michael@0 | 79 | ok(aMessage.errorMessage.indexOf("deprecationFunctionCustomCallstack") > 0, |
michael@0 | 80 | "Callstack is correctly logged."); |
michael@0 | 81 | }, |
michael@0 | 82 | // Set pref to true. |
michael@0 | 83 | logWarnings: true |
michael@0 | 84 | }]; |
michael@0 | 85 | |
michael@0 | 86 | // Which test are we running now? |
michael@0 | 87 | let idx = -1; |
michael@0 | 88 | |
michael@0 | 89 | function test() { |
michael@0 | 90 | waitForExplicitFinish(); |
michael@0 | 91 | |
michael@0 | 92 | // Check if Deprecated is loaded. |
michael@0 | 93 | ok(Deprecated, "Deprecated object exists"); |
michael@0 | 94 | |
michael@0 | 95 | nextTest(); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | // Test Consle Message attributes. |
michael@0 | 99 | function testAMessage (aMessage) { |
michael@0 | 100 | ok(aMessage.errorMessage.indexOf("DEPRECATION WARNING: " + |
michael@0 | 101 | "this method is deprecated.") === 0, |
michael@0 | 102 | "Deprecation is correctly logged."); |
michael@0 | 103 | ok(aMessage.errorMessage.indexOf("http://example.com") > 0, |
michael@0 | 104 | "URL is correctly logged."); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | function nextTest() { |
michael@0 | 108 | idx++; |
michael@0 | 109 | |
michael@0 | 110 | if (idx == tests.length) { |
michael@0 | 111 | finish(); |
michael@0 | 112 | return; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | info("Running test #" + idx); |
michael@0 | 116 | let test = tests[idx]; |
michael@0 | 117 | |
michael@0 | 118 | // Deprecation warnings will be logged only when the preference is set. |
michael@0 | 119 | if (typeof test.logWarnings !== "undefined") { |
michael@0 | 120 | Services.prefs.setBoolPref(PREF_DEPRECATION_WARNINGS, test.logWarnings); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | // Create a console listener. |
michael@0 | 124 | let consoleListener = { |
michael@0 | 125 | observe: function (aMessage) { |
michael@0 | 126 | // Ignore unexpected messages. |
michael@0 | 127 | if (!(aMessage instanceof Ci.nsIScriptError)) { |
michael@0 | 128 | return; |
michael@0 | 129 | } |
michael@0 | 130 | if (aMessage.errorMessage.indexOf("DEPRECATION WARNING: ") < 0 && |
michael@0 | 131 | aMessage.errorMessage.indexOf("must provide a URL") < 0) { |
michael@0 | 132 | return; |
michael@0 | 133 | } |
michael@0 | 134 | ok(aMessage instanceof Ci.nsIScriptError, |
michael@0 | 135 | "Deprecation log message is an instance of type nsIScriptError."); |
michael@0 | 136 | |
michael@0 | 137 | |
michael@0 | 138 | if (test.expectedObservation === null) { |
michael@0 | 139 | ok(false, "Deprecated warning not expected"); |
michael@0 | 140 | } |
michael@0 | 141 | else { |
michael@0 | 142 | test.expectedObservation(aMessage); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | Services.console.unregisterListener(consoleListener); |
michael@0 | 146 | executeSoon(nextTest); |
michael@0 | 147 | } |
michael@0 | 148 | }; |
michael@0 | 149 | Services.console.registerListener(consoleListener); |
michael@0 | 150 | test.deprecatedFunction(); |
michael@0 | 151 | if (test.expectedObservation === null) { |
michael@0 | 152 | executeSoon(function() { |
michael@0 | 153 | Services.console.unregisterListener(consoleListener); |
michael@0 | 154 | executeSoon(nextTest); |
michael@0 | 155 | }); |
michael@0 | 156 | } |
michael@0 | 157 | } |