Bug 1522810 disable client id header in private window, r=aswan

When switching to using a header for the discover pane I forgot
to check for privateness of the window.  This patch should apply to both
m-c and beta.

Differential Revision: https://phabricator.services.mozilla.com/D17647

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Shane Caraveo 2019-01-25 18:43:11 +00:00
Родитель 3e9e8f9274
Коммит 0c6d9d1764
4 изменённых файлов: 66 добавлений и 4 удалений

Просмотреть файл

@ -26,6 +26,8 @@ ChromeUtils.defineModuleGetter(this, "Preferences",
"resource://gre/modules/Preferences.jsm");
ChromeUtils.defineModuleGetter(this, "ClientID",
"resource://gre/modules/ClientID.jsm");
ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
XPCOMUtils.defineLazyPreferenceGetter(this, "WEBEXT_PERMISSION_PROMPTS",
"extensions.webextPermissionPrompts", false);
@ -2011,7 +2013,8 @@ var gDiscoverView = {
get clientIdDiscoveryEnabled() {
// These prefs match Discovery.jsm for enabling clientId cookies.
return Services.prefs.getBoolPref("datareporting.healthreport.uploadEnabled", false) &&
Services.prefs.getBoolPref("browser.discovery.enabled", false);
Services.prefs.getBoolPref("browser.discovery.enabled", false) &&
!PrivateBrowsingUtils.isContentWindowPrivate(window);
},
async getClientHeader() {

Просмотреть файл

@ -65,6 +65,7 @@ skip-if = os == "linux" && !debug # Bug 1395539 - fails on multi-core
[browser_checkAddonCompatibility.js]
[browser_details.js]
[browser_discovery.js]
[browser_discovery_clientid.js]
[browser_dragdrop.js]
[browser_dragdrop_incompat.js]
[browser_extension_sideloading_permission.js]

Просмотреть файл

@ -0,0 +1,58 @@
"use strict";
const {ClientID} = ChromeUtils.import("resource://gre/modules/ClientID.jsm", {});
const MAIN_URL = "https://example.com/" + RELATIVE_DIR + "discovery.html";
function waitForHeader() {
return new Promise(resolve => {
let observer = (subject, topic, state) => {
let channel = subject.QueryInterface(Ci.nsIHttpChannel);
if (channel.URI.spec != MAIN_URL) {
return;
}
try {
resolve(channel.getRequestHeader("Moz-Client-Id"));
} catch (e) {
if (e.result == Cr.NS_ERROR_NOT_AVAILABLE) {
// The header was not set.
resolve(null);
}
} finally {
Services.obs.removeObserver(observer, "http-on-modify-request");
}
};
Services.obs.addObserver(observer, "http-on-modify-request");
});
}
add_task(async function setup() {
SpecialPowers.pushPrefEnv({"set": [
[PREF_DISCOVERURL, MAIN_URL],
["datareporting.healthreport.uploadEnabled", true],
["browser.discovery.enabled", true],
]});
});
add_task(async function test_no_private_clientid() {
let privateWindow = await BrowserTestUtils.openNewBrowserWindow({private: true});
let [header, manager] = await Promise.all([
waitForHeader(),
open_manager("addons://discover/", undefined, undefined, undefined, privateWindow),
]);
ok(PrivateBrowsingUtils.isContentWindowPrivate(manager), "window is private");
is(header, null, "header was not set");
await close_manager(manager);
await BrowserTestUtils.closeWindow(privateWindow);
});
add_task(async function test_clientid() {
let clientId = await ClientID.getClientIdHash();
ok(!!clientId, "clientId is avialable");
let [header, manager] = await Promise.all([
waitForHeader(),
open_manager("addons://discover/"),
]);
is(header, clientId, "header was set");
await close_manager(manager);
});

Просмотреть файл

@ -368,7 +368,7 @@ function wait_for_manager_load(aManagerWindow, aCallback) {
return log_callback(p, aCallback);
}
function open_manager(aView, aCallback, aLoadCallback, aLongerTimeout) {
function open_manager(aView, aCallback, aLoadCallback, aLongerTimeout, aWin = window) {
let p = new Promise((resolve, reject) => {
async function setup_manager(aManagerWindow) {
@ -399,8 +399,8 @@ function open_manager(aView, aCallback, aLoadCallback, aLongerTimeout) {
setup_manager(aSubject);
}, "EM-loaded");
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
switchToTabHavingURI(MANAGER_URI, true, {
aWin.gBrowser.selectedTab = BrowserTestUtils.addTab(aWin.gBrowser);
aWin.switchToTabHavingURI(MANAGER_URI, true, {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});
});