Bug 1649280 - Create a new webconsole message group for storage isolation messages. r=timhuang,nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D84456
This commit is contained in:
Nihanth Subramanya 2020-07-22 16:00:22 +00:00
Родитель 6cf2a7977e
Коммит 1f4855ea8d
5 изменённых файлов: 123 добавлений и 4 удалений

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

@ -156,6 +156,7 @@ const chromeRDPEnums = {
START_GROUP_COLLAPSED: "startGroupCollapsed",
END_GROUP: "endGroup",
CONTENT_BLOCKING_GROUP: "contentBlockingWarningGroup",
STORAGE_ISOLATION_GROUP: "storageIsolationWarningGroup",
TRACKING_PROTECTION_GROUP: "trackingProtectionWarningGroup",
COOKIE_SAMESITE_GROUP: "cookieSameSiteGroup",
CORS_GROUP: "CORSWarningGroup",

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

@ -376,7 +376,9 @@ tags = trackingprotection
[browser_webconsole_visibility_messages.js]
[browser_webconsole_warn_about_replaced_api.js]
[browser_webconsole_warning_group_content_blocking.js]
skip-if = fission
skip-if = fission # Bug 1654522
[browser_webconsole_warning_group_storage_isolation.js]
skip-if = fission || (os == 'win' && debug) # Bug 1654522, 1653057
[browser_webconsole_warning_group_cookies.js]
[browser_webconsole_warning_groups_filtering.js]
skip-if = (os == "win" && bits == 32) && !debug # Bug 1560261

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

@ -0,0 +1,101 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Load a third-party page that sets a cookie and make sure a warning about
// partitioned storage access appears in the console. Also test that multiple
// such warnings are grouped together.
"use strict";
requestLongerTimeout(2);
const TEST_PATH = "browser/devtools/client/webconsole/test/browser/";
const TEST_FILE = TEST_PATH + "test-warning-groups.html";
const TEST_URI = "http://example.com/" + TEST_FILE;
const PARTITIONED_URL = "http://example.org/" + TEST_PATH + "cookieSetter.html";
const STORAGE_ISOLATION_GROUP_LABEL =
`Partitioned cookie or storage access was provided to “<URL>” because it is ` +
`loaded in the third-party context and storage partitioning is enabled.`;
const COOKIE_BEHAVIOR_PREF = "network.cookie.cookieBehavior";
const COOKIE_BEHAVIOR_PARTITION_FOREIGN = 5;
pushPref("devtools.webconsole.groupWarningMessages", true);
async function cleanUp() {
await new Promise(resolve => {
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value =>
resolve()
);
});
}
add_task(async function testStorageIsolationMessage() {
await cleanUp();
await pushPref(COOKIE_BEHAVIOR_PREF, COOKIE_BEHAVIOR_PARTITION_FOREIGN);
const { hud, tab, win } = await openNewWindowAndConsole(TEST_URI);
const now = Date.now();
const getWarningMessage = url =>
STORAGE_ISOLATION_GROUP_LABEL.replace("<URL>", url);
info("Test storage isolation message");
const url1 = `${PARTITIONED_URL}?1&${now}`;
const message = getWarningMessage(url1);
const onStorageIsolationWarningMessage = waitForMessage(
hud,
message,
".warn"
);
emitStorageIsolationMessage(tab, url1);
await onStorageIsolationWarningMessage;
ok(true, "The storage isolation message was displayed");
info(
"Emit a new storage isolation message to check that it causes a grouping"
);
const onStorageIsolationWarningGroupMessage = waitForMessage(
hud,
STORAGE_ISOLATION_GROUP_LABEL,
".warn"
);
const url2 = `${PARTITIONED_URL}?2&${now}`;
emitStorageIsolationMessage(tab, url2);
const { node } = await onStorageIsolationWarningGroupMessage;
is(
node.querySelector(".warning-group-badge").textContent,
"2",
"The badge has the expected text"
);
checkConsoleOutputForWarningGroup(hud, [
`▶︎⚠ ${STORAGE_ISOLATION_GROUP_LABEL} 2`,
]);
info("Open the group");
node.querySelector(".arrow").click();
await waitFor(() => findMessage(hud, url1));
checkConsoleOutputForWarningGroup(hud, [
`▼︎⚠ ${STORAGE_ISOLATION_GROUP_LABEL} 2`,
`| ${getWarningMessage(url1)}`,
`| ${getWarningMessage(url2)}`,
]);
await win.close();
await cleanUp();
});
/**
* Emit a Storage Isolation message. This is done by loading an iframe with a
* third-party resource. The iframe is loaded with a incremented counter query
* parameter each time so we can get the warning message.
*/
function emitStorageIsolationMessage(tab, url) {
SpecialPowers.spawn(tab.linkedBrowser, [url], function(innerURL) {
content.wrappedJSObject.loadIframe(innerURL);
});
}

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

@ -2,6 +2,6 @@
<html>
<script>
"use strict";
document.cookie = "name=value";
document.cookie = "name=value;samesite=lax";
</script>
</html>

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

@ -557,6 +557,7 @@ function createWarningGroupMessage(id, type, firstMessage) {
function getWarningGroupLabel(firstMessage) {
if (
isContentBlockingMessage(firstMessage) ||
isStorageIsolationMessage(firstMessage) ||
isTrackingProtectionMessage(firstMessage)
) {
return replaceURL(firstMessage.messageText, "<URL>");
@ -628,6 +629,10 @@ function getWarningGroupType(message) {
return MESSAGE_TYPE.CONTENT_BLOCKING_GROUP;
}
if (isStorageIsolationMessage(message)) {
return MESSAGE_TYPE.STORAGE_ISOLATION_GROUP;
}
if (isTrackingProtectionMessage(message)) {
return MESSAGE_TYPE.TRACKING_PROTECTION_GROUP;
}
@ -663,6 +668,7 @@ function getParentWarningGroupMessageId(message) {
function isWarningGroup(message) {
return (
message.type === MESSAGE_TYPE.CONTENT_BLOCKING_GROUP ||
message.type === MESSAGE_TYPE.STORAGE_ISOLATION_GROUP ||
message.type === MESSAGE_TYPE.TRACKING_PROTECTION_GROUP ||
message.type === MESSAGE_TYPE.COOKIE_SAMESITE_GROUP ||
message.type === MESSAGE_TYPE.CORS_GROUP ||
@ -681,11 +687,20 @@ function isContentBlockingMessage(message) {
category == "cookieBlockedPermission" ||
category == "cookieBlockedTracker" ||
category == "cookieBlockedAll" ||
category == "cookieBlockedForeign" ||
category == "cookiePartitionedForeign"
category == "cookieBlockedForeign"
);
}
/**
* Returns true if the message is a storage isolation message.
* @param {ConsoleMessage} message
* @returns {Boolean}
*/
function isStorageIsolationMessage(message) {
const { category } = message;
return category == "cookiePartitionedForeign";
}
/**
* Returns true if the message is a tracking protection message.
* @param {ConsoleMessage} message