mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 06:38:36 +00:00
Backout 65804eae62b1, a0b216d3be12, 68e5d9fe91fc (bug 837326) for impending bustage that would make this CLOSED TREE worse than it already is
This commit is contained in:
parent
a4a5f6ffba
commit
72a9f29c5d
@ -1646,23 +1646,13 @@ nsCookieService::SetCookieStringInternal(nsIURI *aHostURI,
|
||||
// check default prefs
|
||||
CookieStatus cookieStatus = CheckPrefs(aHostURI, aIsForeign, requireHostMatch,
|
||||
aCookieHeader.get());
|
||||
// fire a notification if third party or if cookie was rejected
|
||||
// (but not if there was an error)
|
||||
// fire a notification if cookie was rejected (but not if there was an error)
|
||||
switch (cookieStatus) {
|
||||
case STATUS_REJECTED:
|
||||
NotifyRejected(aHostURI);
|
||||
if (aIsForeign) {
|
||||
NotifyThirdParty(aHostURI, false, aChannel);
|
||||
}
|
||||
return; // Stop here
|
||||
return;
|
||||
case STATUS_REJECTED_WITH_ERROR:
|
||||
return;
|
||||
case STATUS_ACCEPTED: // Fallthrough
|
||||
case STATUS_ACCEPT_SESSION:
|
||||
if (aIsForeign) {
|
||||
NotifyThirdParty(aHostURI, true, aChannel);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1695,38 +1685,8 @@ nsCookieService::SetCookieStringInternal(nsIURI *aHostURI,
|
||||
void
|
||||
nsCookieService::NotifyRejected(nsIURI *aHostURI)
|
||||
{
|
||||
if (mObserverService) {
|
||||
if (mObserverService)
|
||||
mObserverService->NotifyObservers(aHostURI, "cookie-rejected", nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
// notify observers that a third-party cookie was accepted/rejected
|
||||
// if the cookie issuer is unknown, it defaults to "?"
|
||||
void
|
||||
nsCookieService::NotifyThirdParty(nsIURI *aHostURI, bool aIsAccepted, nsIChannel *aChannel)
|
||||
{
|
||||
if (!mObserverService) {
|
||||
return;
|
||||
}
|
||||
const char* topic = aIsAccepted ? "third-party-cookie-accepted"
|
||||
: "third-party-cookie-rejected";
|
||||
|
||||
if (aChannel) {
|
||||
nsCOMPtr<nsIURI> channelURI;
|
||||
DebugOnly<nsresult> rv = aChannel->GetURI(getter_AddRefs(channelURI));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Channel doesn't have a uri");
|
||||
nsAutoCString referringHost;
|
||||
rv = channelURI->GetHost(referringHost);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "URI doesn't have a host");
|
||||
nsAutoString referringHostUTF16 = NS_ConvertUTF8toUTF16(referringHost);
|
||||
mObserverService->NotifyObservers(aHostURI,
|
||||
topic,
|
||||
referringHostUTF16.get());
|
||||
} else {
|
||||
mObserverService->NotifyObservers(aHostURI,
|
||||
topic,
|
||||
NS_LITERAL_STRING("?").get());
|
||||
}
|
||||
}
|
||||
|
||||
// notify observers that the cookie list changed. there are five possible
|
||||
|
@ -287,7 +287,6 @@ class nsCookieService : public nsICookieService
|
||||
bool FindCookie(const nsCookieKey& aKey, const nsAFlatCString &aHost, const nsAFlatCString &aName, const nsAFlatCString &aPath, nsListIter &aIter);
|
||||
static void FindStaleCookie(nsCookieEntry *aEntry, int64_t aCurrentTime, nsListIter &aIter);
|
||||
void NotifyRejected(nsIURI *aHostURI);
|
||||
void NotifyThirdParty(nsIURI *aHostURI, bool aAccepted, nsIChannel *aChannel);
|
||||
void NotifyChanged(nsISupports *aSubject, const PRUnichar *aData);
|
||||
void NotifyPurged(nsICookie2* aCookie);
|
||||
already_AddRefed<nsIArray> CreatePurgeList(nsICookie2* aCookie);
|
||||
|
@ -58,18 +58,6 @@ interface nsIChannel;
|
||||
* subject: an nsIURI interface pointer representing the URI that attempted
|
||||
* to set the cookie.
|
||||
* data : none.
|
||||
*
|
||||
* topic : "third-party-cookie-accepted"
|
||||
* broadcast whenever a third party cookie was accepted
|
||||
* subject: an nsIURI interface pointer representing the URI that attempted
|
||||
* to set the cookie.
|
||||
* data : the referrer, or "?" if unknown
|
||||
*
|
||||
* topic : "third-party-cookie-rejected"
|
||||
* broadcast whenever a third party cookie was rejected
|
||||
* subject: an nsIURI interface pointer representing the URI that attempted
|
||||
* to set the cookie.
|
||||
* data : the referrer, or "?" if unknown
|
||||
*/
|
||||
[scriptable, uuid(2aaa897a-293c-4d2b-a657-8c9b7136996d)]
|
||||
interface nsICookieService : nsISupports
|
||||
|
@ -3320,34 +3320,6 @@
|
||||
"n_buckets": "1000",
|
||||
"description": "The time (in milliseconds) that it took a 'detach' request to go round trip."
|
||||
},
|
||||
"COOKIES_3RDPARTY_NUM_SITES_ACCEPTED": {
|
||||
"kind": "linear",
|
||||
"low": "5",
|
||||
"high": "145",
|
||||
"n_buckets": "30",
|
||||
"description": "The number of distinct pairs (first-party site, third-party site attempting to set cookie) for which the third-party cookie has been accepted. Sites are considered identical if they have the same eTLD + 1. Measures are normalized per 24h."
|
||||
},
|
||||
"COOKIES_3RDPARTY_NUM_SITES_BLOCKED": {
|
||||
"kind": "linear",
|
||||
"low": "5",
|
||||
"high": "145",
|
||||
"n_buckets": "30",
|
||||
"description": "The number of distinct pairs (first-party site, third-party site attempting to set cookie) for which the third-party cookie has been rejected. Sites are considered identical if they have the same eTLD + 1. Measures are normalized per 24h."
|
||||
},
|
||||
"COOKIES_3RDPARTY_NUM_ATTEMPTS_ACCEPTED": {
|
||||
"kind": "linear",
|
||||
"low": "10",
|
||||
"high": "500",
|
||||
"n_buckets": "50",
|
||||
"description": "The total number of distinct attempts by third-party sites to place cookies which have been accepted. Measures are normalized per 24h."
|
||||
},
|
||||
"COOKIES_3RDPARTY_NUM_ATTEMPTS_BLOCKED": {
|
||||
"kind": "linear",
|
||||
"low": "10",
|
||||
"high": "500",
|
||||
"n_buckets": "50",
|
||||
"description": "The total number of distinct attempts by third-party sites to place cookies which have been rejected. Measures are normalized per 24h."
|
||||
},
|
||||
"DEVTOOLS_DEBUGGER_RDP_LOCAL_BLACKBOX_MS": {
|
||||
"kind": "exponential",
|
||||
"high": "10000",
|
||||
|
@ -28,7 +28,6 @@ DISABLED_EXTRA_COMPONENTS = \
|
||||
|
||||
EXTRA_JS_MODULES = \
|
||||
TelemetryStopwatch.jsm \
|
||||
ThirdPartyCookieProbe.jsm \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
|
||||
|
@ -15,7 +15,6 @@ Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||
Cu.import("resource://gre/modules/LightweightThemeManager.jsm");
|
||||
#endif
|
||||
Cu.import("resource://gre/modules/ctypes.jsm");
|
||||
Cu.import("resource://gre/modules/ThirdPartyCookieProbe.jsm");
|
||||
|
||||
// When modifying the payload in incompatible ways, please bump this version number
|
||||
const PAYLOAD_VERSION = 1;
|
||||
@ -762,10 +761,6 @@ TelemetryPing.prototype = {
|
||||
* Initializes telemetry within a timer. If there is no PREF_SERVER set, don't turn on telemetry.
|
||||
*/
|
||||
setup: function setup() {
|
||||
// Initialize some probes that are kept in their own modules
|
||||
this._thirdPartyCookies = new ThirdPartyCookieProbe();
|
||||
this._thirdPartyCookies.init();
|
||||
|
||||
// Record old value and update build ID preference if this is the first
|
||||
// run with a new build ID.
|
||||
let previousBuildID = undefined;
|
||||
@ -1007,7 +1002,7 @@ TelemetryPing.prototype = {
|
||||
* Remove observers to avoid leaks
|
||||
*/
|
||||
uninstall: function uninstall() {
|
||||
this.detachObservers();
|
||||
this.detachObservers()
|
||||
if (this._hasWindowRestoredObserver) {
|
||||
Services.obs.removeObserver(this, "sessionstore-windows-restored");
|
||||
this._hasWindowRestoredObserver = false;
|
||||
|
@ -1,180 +0,0 @@
|
||||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
let Ci = Components.interfaces;
|
||||
let Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["ThirdPartyCookieProbe"];
|
||||
|
||||
const MILLISECONDS_PER_DAY = 1000 * 60 * 60 * 24;
|
||||
|
||||
/**
|
||||
* A probe implementing the measurements detailed at
|
||||
* https://wiki.mozilla.org/SecurityEngineering/ThirdPartyCookies/Telemetry
|
||||
*
|
||||
* This implementation uses only in-memory data.
|
||||
*/
|
||||
this.ThirdPartyCookieProbe = function() {
|
||||
/**
|
||||
* A set of third-party sites that have caused cookies to be
|
||||
* rejected. These sites are trimmed down to ETLD + 1
|
||||
* (i.e. "x.y.com" and "z.y.com" are both trimmed down to "y.com",
|
||||
* "x.y.co.uk" is trimmed down to "y.co.uk").
|
||||
*
|
||||
* Used to answer the following question: "For each third-party
|
||||
* site, how many other first parties embed them and result in
|
||||
* cookie traffic?" (see
|
||||
* https://wiki.mozilla.org/SecurityEngineering/ThirdPartyCookies/Telemetry#Breadth
|
||||
* )
|
||||
*
|
||||
* @type Map<string, RejectStats> A mapping from third-party site
|
||||
* to rejection statistics.
|
||||
*/
|
||||
this._thirdPartyCookies = new Map();
|
||||
/**
|
||||
* Timestamp of the latest call to flush() in milliseconds since the Epoch.
|
||||
*/
|
||||
this._latestFlush = Date.now();
|
||||
};
|
||||
|
||||
this.ThirdPartyCookieProbe.prototype = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
|
||||
init: function() {
|
||||
Services.obs.addObserver(this, "profile-before-change", false);
|
||||
Services.obs.addObserver(this, "third-party-cookie-accepted", false);
|
||||
Services.obs.addObserver(this, "third-party-cookie-rejected", false);
|
||||
},
|
||||
dispose: function() {
|
||||
Services.obs.removeObserver(this, "profile-before-change");
|
||||
Services.obs.removeObserver(this, "third-party-cookie-accepted");
|
||||
Services.obs.removeObserver(this, "third-party-cookie-rejected");
|
||||
},
|
||||
/**
|
||||
* Observe either
|
||||
* - "profile-before-change" (no meaningful subject or data) - time to flush statistics and unregister; or
|
||||
* - "third-party-cookie-accepted"/"third-party-cookie-rejected" with
|
||||
* subject: the nsIURI of the third-party that attempted to set the cookie;
|
||||
* data: a string holding the uri of the page seen by the user.
|
||||
*/
|
||||
observe: function(docURI, topic, referrer) {
|
||||
try {
|
||||
if (topic == "profile-before-change") {
|
||||
// A final flush, then unregister
|
||||
this.flush();
|
||||
this.dispose();
|
||||
}
|
||||
if (topic != "third-party-cookie-accepted"
|
||||
&& topic != "third-party-cookie-rejected") {
|
||||
// Not a third-party cookie
|
||||
return;
|
||||
}
|
||||
// Add host to this._thirdPartyCookies
|
||||
let firstParty = normalizeHost(referrer);
|
||||
let thirdParty = normalizeHost(docURI.QueryInterface(Ci.nsIURI).host);
|
||||
let data = this._thirdPartyCookies.get(thirdParty);
|
||||
if (!data) {
|
||||
data = new RejectStats();
|
||||
this._thirdPartyCookies.set(thirdParty, data);
|
||||
}
|
||||
if (topic == "third-party-cookie-accepted") {
|
||||
data.addAccepted(firstParty);
|
||||
} else {
|
||||
data.addRejected(firstParty);
|
||||
}
|
||||
} catch (ex) {
|
||||
// Errors should not remain silent
|
||||
Services.console.logStringMessage("ThirdPartyCookieProbe: Uncaught error " + ex + "\n" + ex.stack);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear internal data, fill up corresponding histograms.
|
||||
*/
|
||||
flush: function(aUptime) {
|
||||
let now = Date.now();
|
||||
let updays = (now - this._latestFlush) / MILLISECONDS_PER_DAY;
|
||||
if (updays <= 0) {
|
||||
// Unlikely, but regardless, don't risk division by zero
|
||||
// or weird stuff.
|
||||
return;
|
||||
}
|
||||
this._latestFlush = now;
|
||||
let acceptedSites = Services.telemetry.getHistogramById("COOKIES_3RDPARTY_NUM_SITES_ACCEPTED");
|
||||
let rejectedSites = Services.telemetry.getHistogramById("COOKIES_3RDPARTY_NUM_SITES_BLOCKED");
|
||||
let acceptedRequests = Services.telemetry.getHistogramById("COOKIES_3RDPARTY_NUM_ATTEMPTS_ACCEPTED");
|
||||
let rejectedRequests = Services.telemetry.getHistogramById("COOKIES_3RDPARTY_NUM_ATTEMPTS_BLOCKED");
|
||||
for (let [k, data] of this._thirdPartyCookies) {
|
||||
acceptedSites.add(data.countAcceptedSites / updays);
|
||||
rejectedSites.add(data.countRejectedSites / updays);
|
||||
acceptedRequests.add(data.countAcceptedRequests / updays);
|
||||
rejectedRequests.add(data.countRejectedRequests / updays);
|
||||
}
|
||||
this._thirdPartyCookies.clear();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Data gathered on cookies that a third party site has attempted to set.
|
||||
*
|
||||
* Privacy note: the only data actually sent to the server is the size of
|
||||
* the sets.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
let RejectStats = function() {
|
||||
/**
|
||||
* The set of all sites for which we have accepted third-party cookies.
|
||||
*/
|
||||
this._acceptedSites = new Set();
|
||||
/**
|
||||
* The set of all sites for which we have rejected third-party cookies.
|
||||
*/
|
||||
this._rejectedSites = new Set();
|
||||
/**
|
||||
* Total number of attempts to set a third-party cookie that have
|
||||
* been accepted. Two accepted attempts on the same site will both
|
||||
* augment this count.
|
||||
*/
|
||||
this._acceptedRequests = 0;
|
||||
/**
|
||||
* Total number of attempts to set a third-party cookie that have
|
||||
* been rejected. Two rejected attempts on the same site will both
|
||||
* augment this count.
|
||||
*/
|
||||
this._rejectedRequests = 0;
|
||||
};
|
||||
RejectStats.prototype = {
|
||||
addAccepted: function(firstParty) {
|
||||
this._acceptedSites.add(firstParty);
|
||||
this._acceptedRequests++;
|
||||
},
|
||||
addRejected: function(firstParty) {
|
||||
this._rejectedSites.add(firstParty);
|
||||
this._rejectedRequests++;
|
||||
},
|
||||
get countAcceptedSites() {
|
||||
return this._acceptedSites.size;
|
||||
},
|
||||
get countRejectedSites() {
|
||||
return this._rejectedSites.size;
|
||||
},
|
||||
get countAcceptedRequests() {
|
||||
return this._acceptedRequests;
|
||||
},
|
||||
get countRejectedRequests() {
|
||||
return this._rejectedRequests;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalize a host to its eTLD + 1.
|
||||
*/
|
||||
function normalizeHost(host) {
|
||||
return Services.eTLD.getBaseDomainFromHost(host);
|
||||
};
|
@ -30,4 +30,3 @@ EXTRA_COMPONENTS += [
|
||||
EXTRA_PP_COMPONENTS += [
|
||||
'TelemetryPing.js',
|
||||
]
|
||||
|
||||
|
@ -1,52 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
|
||||
// copied from toolkit/mozapps/extensions/test/xpcshell/head_addons.js
|
||||
const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
|
||||
const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");
|
||||
|
||||
function createAppInfo(id, name, version, platformVersion) {
|
||||
gAppInfo = {
|
||||
// nsIXULAppInfo
|
||||
vendor: "Mozilla",
|
||||
name: name,
|
||||
ID: id,
|
||||
version: version,
|
||||
appBuildID: "2007010101",
|
||||
platformVersion: platformVersion,
|
||||
platformBuildID: "2007010101",
|
||||
|
||||
// nsIXULRuntime
|
||||
inSafeMode: false,
|
||||
logConsoleErrors: true,
|
||||
OS: "XPCShell",
|
||||
XPCOMABI: "noarch-spidermonkey",
|
||||
invalidateCachesOnRestart: function invalidateCachesOnRestart() {
|
||||
// Do nothing
|
||||
},
|
||||
|
||||
// nsICrashReporter
|
||||
annotations: {},
|
||||
|
||||
annotateCrashReport: function(key, data) {
|
||||
this.annotations[key] = data;
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo,
|
||||
Ci.nsIXULRuntime,
|
||||
Ci.nsICrashReporter,
|
||||
Ci.nsISupports])
|
||||
};
|
||||
|
||||
var XULAppInfoFactory = {
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return gAppInfo.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
|
||||
XULAPPINFO_CONTRACTID, XULAppInfoFactory);
|
||||
}
|
@ -357,6 +357,55 @@ function runOldPingFileTest() {
|
||||
do_check_false(histogramsFile.exists());
|
||||
}
|
||||
|
||||
// copied from toolkit/mozapps/extensions/test/xpcshell/head_addons.js
|
||||
const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
|
||||
const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");
|
||||
|
||||
function createAppInfo(id, name, version, platformVersion) {
|
||||
gAppInfo = {
|
||||
// nsIXULAppInfo
|
||||
vendor: "Mozilla",
|
||||
name: name,
|
||||
ID: id,
|
||||
version: version,
|
||||
appBuildID: "2007010101",
|
||||
platformVersion: platformVersion,
|
||||
platformBuildID: "2007010101",
|
||||
|
||||
// nsIXULRuntime
|
||||
inSafeMode: false,
|
||||
logConsoleErrors: true,
|
||||
OS: "XPCShell",
|
||||
XPCOMABI: "noarch-spidermonkey",
|
||||
invalidateCachesOnRestart: function invalidateCachesOnRestart() {
|
||||
// Do nothing
|
||||
},
|
||||
|
||||
// nsICrashReporter
|
||||
annotations: {},
|
||||
|
||||
annotateCrashReport: function(key, data) {
|
||||
this.annotations[key] = data;
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo,
|
||||
Ci.nsIXULRuntime,
|
||||
Ci.nsICrashReporter,
|
||||
Ci.nsISupports])
|
||||
};
|
||||
|
||||
var XULAppInfoFactory = {
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return gAppInfo.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
|
||||
XULAPPINFO_CONTRACTID, XULAppInfoFactory);
|
||||
}
|
||||
|
||||
function dummyTheme(id) {
|
||||
return {
|
||||
id: id,
|
||||
|
@ -1,164 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
let Cu = Components.utils;
|
||||
let Cc = Components.classes;
|
||||
let Ci = Components.interfaces;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/ThirdPartyCookieProbe.jsm");
|
||||
Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
|
||||
|
||||
let TOPIC_ACCEPTED = "third-party-cookie-accepted";
|
||||
let TOPIC_REJECTED = "third-party-cookie-rejected";
|
||||
|
||||
let FLUSH_MILLISECONDS = 1000 * 60 * 60 * 24 / 2; /*Half a day, for testing purposes*/
|
||||
|
||||
const NUMBER_OF_REJECTS = 30;
|
||||
const NUMBER_OF_ACCEPTS = 17;
|
||||
const NUMBER_OF_REPEATS = 5;
|
||||
|
||||
const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsITelemetryPing);
|
||||
|
||||
let gCookieService;
|
||||
let gThirdPartyCookieProbe;
|
||||
|
||||
let gHistograms = {
|
||||
clear: function() {
|
||||
this.sitesAccepted.clear();
|
||||
this.requestsAccepted.clear();
|
||||
this.sitesRejected.clear();
|
||||
this.requestsRejected.clear();
|
||||
}
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
do_print("Initializing environment");
|
||||
do_get_profile();
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
|
||||
gCookieService = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
|
||||
|
||||
do_print("Initializing ThirdPartyCookieProbe.jsm");
|
||||
gThirdPartyCookieProbe = new ThirdPartyCookieProbe();
|
||||
gThirdPartyCookieProbe.init();
|
||||
|
||||
do_print("Acquiring histograms");
|
||||
gHistograms.sitesAccepted =
|
||||
Services.telemetry.getHistogramById("COOKIES_3RDPARTY_NUM_SITES_ACCEPTED");
|
||||
gHistograms.sitesRejected =
|
||||
Services.telemetry.getHistogramById("COOKIES_3RDPARTY_NUM_SITES_BLOCKED"),
|
||||
gHistograms.requestsAccepted =
|
||||
Services.telemetry.getHistogramById("COOKIES_3RDPARTY_NUM_ATTEMPTS_ACCEPTED");
|
||||
gHistograms.requestsRejected =
|
||||
Services.telemetry.getHistogramById("COOKIES_3RDPARTY_NUM_ATTEMPTS_BLOCKED"),
|
||||
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function: try to set a cookie with the given document uri and referrer uri.
|
||||
*
|
||||
* @param obj An object with the following fields
|
||||
* - {string} request The uri of the request setting the cookie.
|
||||
* - {string} referrer The uri of the referrer for this request.
|
||||
*/
|
||||
function tryToSetCookie(obj) {
|
||||
let requestURI = Services.io.newURI(obj.request, null, null);
|
||||
let referrerURI = Services.io.newURI(obj.referrer, null, null);
|
||||
let requestChannel = Services.io.newChannelFromURI(requestURI);
|
||||
gCookieService.setCookieString(referrerURI, null, "Is there a cookie in my jar?", requestChannel);
|
||||
}
|
||||
|
||||
function wait(ms) {
|
||||
let deferred = Promise.defer();
|
||||
do_timeout(ms, () => deferred.resolve());
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function oneTest(tld, flushUptime, check) {
|
||||
gHistograms.clear();
|
||||
do_print("Testing with tld " + tld);
|
||||
|
||||
do_print("Adding rejected entries");
|
||||
Services.prefs.setIntPref("network.cookie.cookieBehavior",
|
||||
1 /*reject third-party cookies*/);
|
||||
|
||||
for (let i = 0; i < NUMBER_OF_REJECTS; ++i) {
|
||||
for (let j = 0; j < NUMBER_OF_REPEATS; ++j) {
|
||||
for (let prefix of ["http://", "https://"]) {
|
||||
// Histogram sitesRejected should only count
|
||||
// NUMBER_OF_REJECTS entries.
|
||||
// Histogram requestsRejected should count
|
||||
// NUMBER_OF_REJECTS * NUMBER_OF_REPEATS * 2
|
||||
tryToSetCookie({
|
||||
request: prefix + "echelon" + tld,
|
||||
referrer: prefix + "domain" + i + tld
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_print("Adding accepted entries");
|
||||
Services.prefs.setIntPref("network.cookie.cookieBehavior",
|
||||
0 /*accept third-party cookies*/);
|
||||
|
||||
for (let i = 0; i < NUMBER_OF_ACCEPTS; ++i) {
|
||||
for (let j = 0; j < NUMBER_OF_REPEATS; ++j) {
|
||||
for (let prefix of ["http://", "https://"]) {
|
||||
// Histogram sitesAccepted should only count
|
||||
// NUMBER_OF_ACCEPTS entries.
|
||||
// Histogram requestsAccepted should count
|
||||
// NUMBER_OF_ACCEPTS * NUMBER_OF_REPEATS * 2
|
||||
tryToSetCookie({
|
||||
request: prefix + "prism" + tld,
|
||||
referrer: prefix + "domain" + i + tld
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_print("Checking that the histograms have not changed before ping()");
|
||||
do_check_eq(gHistograms.sitesAccepted.snapshot().sum, 0);
|
||||
do_check_eq(gHistograms.sitesRejected.snapshot().sum, 0);
|
||||
do_check_eq(gHistograms.requestsAccepted.snapshot().sum, 0);
|
||||
do_check_eq(gHistograms.requestsRejected.snapshot().sum, 0);
|
||||
|
||||
do_print("Checking that the resulting histograms are correct");
|
||||
if (flushUptime != null) {
|
||||
let now = Date.now();
|
||||
let before = now - flushUptime;
|
||||
gThirdPartyCookieProbe._latestFlush = before;
|
||||
}
|
||||
gThirdPartyCookieProbe.flush();
|
||||
check();
|
||||
}
|
||||
|
||||
add_task(function() {
|
||||
// To ensure that we work correctly with eTLD, test with several suffixes
|
||||
for (let tld of [".com", ".com.ar", ".co.uk", ".gouv.fr"]) {
|
||||
oneTest(tld, FLUSH_MILLISECONDS, function() {
|
||||
do_check_eq(gHistograms.sitesAccepted.snapshot().sum, NUMBER_OF_ACCEPTS * 2);
|
||||
do_check_eq(gHistograms.sitesRejected.snapshot().sum, NUMBER_OF_REJECTS * 2);
|
||||
do_check_eq(gHistograms.requestsAccepted.snapshot().sum, NUMBER_OF_ACCEPTS * NUMBER_OF_REPEATS * 2 * 2);
|
||||
do_check_eq(gHistograms.requestsRejected.snapshot().sum, NUMBER_OF_REJECTS * NUMBER_OF_REPEATS * 2 * 2);
|
||||
});
|
||||
}
|
||||
|
||||
// Check that things still work with default uptime management
|
||||
for (let tld of [".com", ".com.ar", ".co.uk", ".gouv.fr"]) {
|
||||
yield wait(1000); // Ensure that uptime is at least one second
|
||||
oneTest(tld, null, function() {
|
||||
do_check_true(gHistograms.sitesAccepted.snapshot().sum > 0);
|
||||
do_check_true(gHistograms.sitesRejected.snapshot().sum > 0);
|
||||
do_check_true(gHistograms.requestsAccepted.snapshot().sum > 0);
|
||||
do_check_true(gHistograms.requestsRejected.snapshot().sum > 0);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
add_task(function() {
|
||||
gThirdPartyCookieProbe.dispose();
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
[DEFAULT]
|
||||
head = head.js
|
||||
head =
|
||||
tail =
|
||||
|
||||
[test_nsITelemetry.js]
|
||||
@ -11,4 +11,3 @@ tail =
|
||||
[test_TelemetryPing_idle.js]
|
||||
[test_TelemetryStopwatch.js]
|
||||
[test_TelemetryPingBuildID.js]
|
||||
[test_ThirdPartyCookieProbe.js]
|
||||
|
Loading…
x
Reference in New Issue
Block a user