Bug 1865845: stop caching mac attribution data in a separate file r=nalexander

This is mostly removing code and tests related to reading/writing the cache file on macOS and updating of tests. Aside from that, the most notable part is the change to `setAttributionString` to automatically prepend `__MOZCUSTOM__` when writing an attribution code. This is mostly done to make things simpler and cleaner in the majority of the tests, but seeing as `getAttributionString` is also aware of it, it seems like a generally nicer way to do this.

Differential Revision: https://phabricator.services.mozilla.com/D197204
This commit is contained in:
Ben Hearsum
2024-01-09 20:21:54 +00:00
parent a85096e195
commit ec42f5ce45
12 changed files with 88 additions and 199 deletions

View File

@@ -39,7 +39,14 @@ add_task(async function testValidAttrCodes() {
// are not URI encoded, and the AttributionCode code that deals with
// them expects that - so we have to simulate that as well.
msixCampaignIdStub.callsFake(async () => decodeURIComponent(currentCode));
} else if (AppConstants.platform === "macosx") {
const { MacAttribution } = ChromeUtils.importESModule(
"resource:///modules/MacAttribution.sys.mjs"
);
await MacAttribution.setAttributionString(currentCode);
} else {
// non-msix windows
await AttributionCode.writeAttributionFile(currentCode);
}
AttributionCode._clearCache();
@@ -80,7 +87,14 @@ add_task(async function testInvalidAttrCodes() {
}
msixCampaignIdStub.callsFake(async () => decodeURIComponent(currentCode));
} else if (AppConstants.platform === "macosx") {
const { MacAttribution } = ChromeUtils.importESModule(
"resource:///modules/MacAttribution.sys.mjs"
);
await MacAttribution.setAttributionString(currentCode);
} else {
// non-msix windows
await AttributionCode.writeAttributionFile(currentCode);
}
AttributionCode._clearCache();
@@ -102,11 +116,12 @@ add_task(async function testInvalidAttrCodes() {
* and making sure we still get the expected code.
*/
let condition = {
// MSIX attribution codes are not cached by us, thus this test is
// macOS and MSIX attribution codes are not cached by us, thus this test is
// unnecessary for those builds.
skip_if: () =>
AppConstants.platform === "win" &&
Services.sysinfo.getProperty("hasWinPackageId"),
(AppConstants.platform === "win" &&
Services.sysinfo.getProperty("hasWinPackageId")) ||
AppConstants.platform === "macosx",
};
add_task(condition, async function testDeletedFile() {
// Set up the test by clearing the cache and writing a valid file.

View File

@@ -61,7 +61,13 @@ add_task(async () => {
// data.
add_task(async function testExtendedAttributeProcessing() {
for (let entry of extendedAttributeTestCases) {
await MacAttribution.setAttributionString(entry.raw);
// We use setMacXAttr directly here rather than setAttributionString because
// we need the ability to set invalid attribution strings.
await IOUtils.setMacXAttr(
MacAttribution.applicationPath,
"com.apple.application-instance",
new TextEncoder().encode(entry.raw)
);
try {
let got = await MacAttribution.getAttributionString();
if (entry.error === true) {
@@ -89,10 +95,9 @@ add_task(async function testValidAttrCodes() {
continue;
}
await MacAttribution.setAttributionString("__MOZCUSTOM__" + entry.code);
await MacAttribution.setAttributionString(entry.code);
// Read attribution code from xattr.
await AttributionCode.deleteFileAsync();
AttributionCode._clearCache();
let result = await AttributionCode.getAttrDataAsync();
Assert.deepEqual(
@@ -102,7 +107,6 @@ add_task(async function testValidAttrCodes() {
);
// Read attribution code from cache.
AttributionCode._clearCache();
result = await AttributionCode.getAttrDataAsync();
Assert.deepEqual(
result,
@@ -125,8 +129,7 @@ add_task(async function testInvalidAttrCodes() {
for (let code of invalidAttrCodes) {
await MacAttribution.setAttributionString("__MOZCUSTOM__" + code);
// Read attribution code from referrer.
await AttributionCode.deleteFileAsync();
// Read attribution code from xattr
AttributionCode._clearCache();
let result = await AttributionCode.getAttrDataAsync();
Assert.deepEqual(result, {}, "Code should have failed to parse: " + code);