mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-03 11:21:20 +01:00
Prepare 4.0.5 Firefox update and Shorts fixes
Add Firefox data consent, repair contributor sign-in, and introduce optional Hide clutter buttons. Harden video navigation, voting, and action layouts with shared browser regression coverage and reproducible release packaging.
This commit is contained in:
1 parent
3657de9b2c
commit
e500088e65
196 files changed
+39706
-2694
No files matched your search
@@ -1,21 +1,37 @@
|
||||
const fs = require("node:fs");
|
||||
const { EventEmitter } = require("node:events");
|
||||
const http = require("node:http");
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
const { createFakeBackend } = require("../UserScript/e2e/harness");
|
||||
const { WORKER_SIGNAL_PATH, isAllowedApiPreflight } = require("./hermetic-api-contract");
|
||||
const {
|
||||
ARTIFACT_BROWSER_SCENARIO_CATALOG,
|
||||
ARTIFACT_EXTENSION_DELAYED_FAILURE_SCENARIO_ID,
|
||||
ARTIFACT_SMOKE_SCENARIO_ID,
|
||||
ARTIFACT_WATCH_SPA_CLONED_VOTE_SCENARIO_ID,
|
||||
ARTIFACT_WATCH_SPA_SCENARIO_ID,
|
||||
ARTIFACT_WATCH_SPA_VOTE_SCENARIO_ID,
|
||||
HermeticExtensionArtifactAdapter,
|
||||
SHARED_ARTIFACT_SCENARIO_IDS,
|
||||
SHARED_ARTIFACT_RUNTIMES,
|
||||
assertArtifactBrowserScenarioCatalog,
|
||||
assertLoopbackOrigin,
|
||||
createArtifactBrowserScenarioPlan,
|
||||
createPageSignalCollector,
|
||||
createSharedArtifactBackendOptions,
|
||||
createWorkerSignalCollector,
|
||||
isArtifactVoteHandshakeValid,
|
||||
isSpaDestinationValid,
|
||||
prepareHermeticExtensionArtifact,
|
||||
readGeneratedMv3Contract,
|
||||
readArtifactVoteHandshake,
|
||||
runArtifactWatchRenderScenario,
|
||||
runArtifactWatchSpaClonedVoteScenario,
|
||||
runArtifactWatchSpaScenario,
|
||||
runArtifactWatchSpaVoteScenario,
|
||||
runExtensionDelayedOutgoingFailureScenario,
|
||||
startHermeticApiServer,
|
||||
} = require("./hermetic-artifact-smoke");
|
||||
|
||||
const PRODUCTION_API_ORIGIN = "https://returnyoutubedislikeapi.com";
|
||||
@@ -26,13 +42,22 @@ function createExtensionFixture() {
|
||||
temporaryDirectories.push(directory);
|
||||
fs.writeFileSync(
|
||||
path.join(directory, "manifest.json"),
|
||||
JSON.stringify({ host_permissions: ["*://returnyoutubedislikeapi.com/*"], manifest_version: 3 }),
|
||||
JSON.stringify({
|
||||
background: { service_worker: "ryd.background.js" },
|
||||
content_scripts: [
|
||||
{ css: ["content-style.css"], js: ["ryd.content-script.js"], matches: ["*://www.youtube.com/*"] },
|
||||
],
|
||||
host_permissions: ["*://returnyoutubedislikeapi.com/*"],
|
||||
manifest_version: 3,
|
||||
version: "4.0.5",
|
||||
}),
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(directory, "ryd.background.js"),
|
||||
`fetch("${PRODUCTION_API_ORIGIN}/register")\napi.runtime.onInstalled.addListener((details) => {\n maybeShowChangelog(details);\n});`,
|
||||
);
|
||||
fs.writeFileSync(path.join(directory, "ryd.content-script.js"), `fetch("${PRODUCTION_API_ORIGIN}/votes")`);
|
||||
fs.writeFileSync(path.join(directory, "content-style.css"), "#ryd-bar { display: block; }");
|
||||
fs.writeFileSync(path.join(directory, "menu-fixer.js"), "document.documentElement.dataset.menuFixerLoaded = 'true';");
|
||||
return directory;
|
||||
}
|
||||
@@ -45,13 +70,76 @@ afterEach(() => {
|
||||
|
||||
test("the artifact smoke is the shared watch-render scenario", () => {
|
||||
expect(ARTIFACT_SMOKE_SCENARIO_ID).toBe("watch-render");
|
||||
expect(ARTIFACT_WATCH_SPA_CLONED_VOTE_SCENARIO_ID).toBe("watch-spa-cloned-controls-immediate-dislike");
|
||||
expect(ARTIFACT_WATCH_SPA_SCENARIO_ID).toBe("watch-spa-side-panel");
|
||||
expect(ARTIFACT_WATCH_SPA_VOTE_SCENARIO_ID).toBe("watch-spa-dislike-activation");
|
||||
expect(SHARED_ARTIFACT_SCENARIO_IDS).toEqual([
|
||||
"watch-render",
|
||||
"watch-spa-side-panel",
|
||||
"watch-spa-dislike-activation",
|
||||
"watch-spa-cloned-controls-immediate-dislike",
|
||||
]);
|
||||
expect(SHARED_ARTIFACT_RUNTIMES).toEqual(["userscript", "extension"]);
|
||||
expect(ARTIFACT_BROWSER_SCENARIO_CATALOG).toEqual([
|
||||
...SHARED_ARTIFACT_SCENARIO_IDS.map((id) => ({ id, runtimes: SHARED_ARTIFACT_RUNTIMES, shared: true })),
|
||||
{
|
||||
capability: "background",
|
||||
id: ARTIFACT_EXTENSION_DELAYED_FAILURE_SCENARIO_ID,
|
||||
runtimes: ["extension"],
|
||||
shared: false,
|
||||
},
|
||||
]);
|
||||
expect(assertArtifactBrowserScenarioCatalog()).toBe(ARTIFACT_BROWSER_SCENARIO_CATALOG);
|
||||
expect(createArtifactBrowserScenarioPlan()).toEqual([
|
||||
...SHARED_ARTIFACT_SCENARIO_IDS.flatMap((scenarioId) =>
|
||||
SHARED_ARTIFACT_RUNTIMES.map((runtime) => ({ runtime, scenarioId })),
|
||||
),
|
||||
{ runtime: "extension", scenarioId: ARTIFACT_EXTENSION_DELAYED_FAILURE_SCENARIO_ID },
|
||||
]);
|
||||
});
|
||||
|
||||
test.each([
|
||||
[
|
||||
"a missing extension run from a core scenario",
|
||||
(catalog) => {
|
||||
catalog[0] = { ...catalog[0], runtimes: ["userscript"] };
|
||||
},
|
||||
/must run for userscript and extension/,
|
||||
],
|
||||
[
|
||||
"a core scenario reclassified as extension-only",
|
||||
(catalog) => {
|
||||
catalog[0] = { ...catalog[0], capability: "background", runtimes: ["extension"], shared: false };
|
||||
},
|
||||
/must remain shared/,
|
||||
],
|
||||
[
|
||||
"an undeclared extension-only capability",
|
||||
(catalog) => {
|
||||
catalog[catalog.length - 1] = { ...catalog.at(-1), capability: "mobile-layout" };
|
||||
},
|
||||
/must declare a supported capability/,
|
||||
],
|
||||
[
|
||||
"an extension-only scenario registered for userscript",
|
||||
(catalog) => {
|
||||
catalog[catalog.length - 1] = { ...catalog.at(-1), runtimes: ["userscript", "extension"] };
|
||||
},
|
||||
/must run only for extension/,
|
||||
],
|
||||
[
|
||||
"an unknown scenario presented as shared coverage",
|
||||
(catalog) => {
|
||||
catalog.push({ id: "uncatalogued-core-behavior", runtimes: ["userscript", "extension"], shared: true });
|
||||
},
|
||||
/must be added to the shared scenario contract/,
|
||||
],
|
||||
])("the artifact catalog rejects %s", (_label, mutateCatalog, message) => {
|
||||
const catalog = ARTIFACT_BROWSER_SCENARIO_CATALOG.map((entry) => ({ ...entry, runtimes: [...entry.runtimes] }));
|
||||
mutateCatalog(catalog);
|
||||
|
||||
expect(() => assertArtifactBrowserScenarioCatalog(catalog)).toThrow(message);
|
||||
expect(() => createArtifactBrowserScenarioPlan(catalog)).toThrow(message);
|
||||
});
|
||||
|
||||
function validSpaSnapshot() {
|
||||
@@ -105,6 +193,9 @@ function validVoteHandshake(change = {}) {
|
||||
sharedUserId: ARTIFACT_USER_ID,
|
||||
vote: {
|
||||
body: { userId: ARTIFACT_USER_ID, value: -1, videoId: "zyxwvutsrqp" },
|
||||
responded: true,
|
||||
responseBody: { challenge: "AAAAAAAAAAAAAAAAAAAAAA==", difficulty: 0 },
|
||||
responseStatus: 200,
|
||||
},
|
||||
voteCount: 1,
|
||||
...change,
|
||||
@@ -125,6 +216,141 @@ test.each(["https://returnyoutubedislikeapi.com", "https://api.example.test", "h
|
||||
},
|
||||
);
|
||||
|
||||
test.each([
|
||||
["/votes", "GET"],
|
||||
["/puzzle/registration", "POST"],
|
||||
["/interact/vote", "POST"],
|
||||
[WORKER_SIGNAL_PATH, "POST"],
|
||||
])("accepts a preflight only for a declared API method: %s %s", (pathname, method) => {
|
||||
expect(isAllowedApiPreflight(pathname, method)).toBe(true);
|
||||
});
|
||||
|
||||
test.each([
|
||||
["/not-an-api", "POST"],
|
||||
["/interact/vote", "GET"],
|
||||
["/votes", "POST"],
|
||||
["/votes", null],
|
||||
])("rejects undeclared preflight traffic: %s %s", (pathname, method) => {
|
||||
expect(isAllowedApiPreflight(pathname, method)).toBe(false);
|
||||
});
|
||||
|
||||
function requestPreflight(origin, pathname, requestedMethod) {
|
||||
const url = new URL(pathname, origin);
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = http.request(
|
||||
url,
|
||||
{
|
||||
headers: {
|
||||
"access-control-request-method": requestedMethod,
|
||||
origin: "https://www.youtube.com",
|
||||
},
|
||||
method: "OPTIONS",
|
||||
},
|
||||
(response) => {
|
||||
response.resume();
|
||||
response.once("end", () => resolve(response.statusCode));
|
||||
},
|
||||
);
|
||||
request.once("error", reject);
|
||||
request.end();
|
||||
});
|
||||
}
|
||||
|
||||
test("the loopback backend records and rejects an OPTIONS request to an unknown path", async () => {
|
||||
const apiServer = await startHermeticApiServer();
|
||||
try {
|
||||
await expect(requestPreflight(apiServer.origin, "/interact/vote", "POST")).resolves.toBe(204);
|
||||
await expect(requestPreflight(apiServer.origin, "/unexpected-preflight", "POST")).resolves.toBe(404);
|
||||
|
||||
expect(apiServer.records.map(({ method, pathname }) => ({ method, pathname }))).toEqual([
|
||||
{ method: "OPTIONS", pathname: "/interact/vote" },
|
||||
{ method: "OPTIONS", pathname: "/unexpected-preflight" },
|
||||
]);
|
||||
expect(apiServer.unexpectedRequests).toHaveLength(1);
|
||||
expect(apiServer.unexpectedRequests[0]).toMatchObject({
|
||||
method: "OPTIONS",
|
||||
pathname: "/unexpected-preflight",
|
||||
responseStatus: 404,
|
||||
});
|
||||
} finally {
|
||||
await apiServer.close();
|
||||
}
|
||||
});
|
||||
|
||||
function createPreflightRoute(pathname, requestedMethod) {
|
||||
const request = {
|
||||
headers: () => ({ "access-control-request-method": requestedMethod }),
|
||||
method: () => "OPTIONS",
|
||||
resourceType: () => "fetch",
|
||||
url: () => `https://returnyoutubedislikeapi.com${pathname}`,
|
||||
};
|
||||
return {
|
||||
abort: jest.fn(async () => {}),
|
||||
fulfill: jest.fn(async () => {}),
|
||||
request: () => request,
|
||||
};
|
||||
}
|
||||
|
||||
function createWatchDocumentRoute() {
|
||||
const request = {
|
||||
resourceType: () => "document",
|
||||
url: () => "https://www.youtube.com/watch?v=abcdefghijk",
|
||||
};
|
||||
return {
|
||||
fulfill: jest.fn(async () => {}),
|
||||
request: () => request,
|
||||
};
|
||||
}
|
||||
|
||||
test("shared artifact fixtures do not preseed runtime roles or a Dislike count container", async () => {
|
||||
const backendOptions = createSharedArtifactBackendOptions({
|
||||
countsByVideo: { abcdefghijk: { dislikes: 25, likes: 100 } },
|
||||
});
|
||||
expect(backendOptions.fixture).toEqual({
|
||||
nativeDislikeText: false,
|
||||
roleAttribute: "data-fixture-role",
|
||||
});
|
||||
|
||||
const backend = createFakeBackend(backendOptions);
|
||||
const route = createWatchDocumentRoute();
|
||||
await backend.handle(route);
|
||||
|
||||
expect(route.fulfill).toHaveBeenCalledTimes(1);
|
||||
const [{ body }] = route.fulfill.mock.calls[0];
|
||||
const dislikeMarkup = body.match(/<dislike-button-view-model\b[\s\S]*?<\/dislike-button-view-model>/)?.[0];
|
||||
expect(body).toContain('data-fixture-role="buttons"');
|
||||
expect(body).not.toContain("data-ryd-role=");
|
||||
expect(dislikeMarkup).toBeDefined();
|
||||
expect(dislikeMarkup).not.toMatch(/id="text"|role="text"|ytSpecButtonShapeNextButtonTextContent/);
|
||||
});
|
||||
|
||||
test("the routed fake backend records a valid preflight and blocks an unknown one", async () => {
|
||||
const backend = createFakeBackend();
|
||||
const valid = createPreflightRoute("/interact/confirmVote", "POST");
|
||||
const invalid = createPreflightRoute("/unexpected-preflight", "POST");
|
||||
|
||||
await backend.handle(valid);
|
||||
await backend.handle(invalid);
|
||||
|
||||
expect(valid.fulfill).toHaveBeenCalledWith(expect.objectContaining({ status: 204 }));
|
||||
expect(valid.abort).not.toHaveBeenCalled();
|
||||
expect(backend.preflightRequests).toEqual([
|
||||
expect.objectContaining({
|
||||
method: "OPTIONS",
|
||||
pathname: "/interact/confirmVote",
|
||||
requestedMethod: "POST",
|
||||
}),
|
||||
]);
|
||||
expect(invalid.abort).toHaveBeenCalledWith("blockedbyclient");
|
||||
expect(backend.blockedRequests).toEqual([
|
||||
expect.objectContaining({
|
||||
method: "OPTIONS",
|
||||
pathname: "/unexpected-preflight",
|
||||
requestedMethod: "POST",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
test("redirects eager MV3 background traffic while leaving routed content-script traffic intact", () => {
|
||||
const sourceDirectory = createExtensionFixture();
|
||||
const prepared = prepareHermeticExtensionArtifact(sourceDirectory, "http://127.0.0.1:43127");
|
||||
@@ -135,6 +361,10 @@ test("redirects eager MV3 background traffic while leaving routed content-script
|
||||
expect(fs.readFileSync(path.join(prepared.extensionDirectory, "ryd.background.js"), "utf8")).toContain(
|
||||
"http://127.0.0.1:43127/register",
|
||||
);
|
||||
expect(fs.readFileSync(path.join(prepared.extensionDirectory, "ryd.background.js"), "utf8")).toContain(
|
||||
"__rydArtifactWorkerSignals",
|
||||
);
|
||||
expect(prepared.workerSignalEndpoint).toBe(`http://127.0.0.1:43127${WORKER_SIGNAL_PATH}`);
|
||||
expect(fs.readFileSync(path.join(prepared.extensionDirectory, "ryd.background.js"), "utf8")).toContain(
|
||||
"api.runtime.onInstalled.addListener(() => {});",
|
||||
);
|
||||
@@ -158,6 +388,18 @@ test("rejects an extension artifact whose injected auxiliary script was dropped
|
||||
);
|
||||
});
|
||||
|
||||
test("the direct MV3 adapter contract rejects a development bundle with an inline source map", () => {
|
||||
const sourceDirectory = createExtensionFixture();
|
||||
fs.appendFileSync(
|
||||
path.join(sourceDirectory, "ryd.content-script.js"),
|
||||
"\n//# sourceMappingURL=data:application/json;base64,e30=",
|
||||
);
|
||||
|
||||
expect(() => readGeneratedMv3Contract(sourceDirectory)).toThrow(
|
||||
"ryd.content-script.js contains an inline source map and is not a production bundle.",
|
||||
);
|
||||
});
|
||||
|
||||
test.each(["userscript", "extension"])("runs one shared artifact scenario contract for %s", async (runtime) => {
|
||||
const events = [];
|
||||
const adapter = {
|
||||
@@ -167,9 +409,13 @@ test.each(["userscript", "extension"])("runs one shared artifact scenario contra
|
||||
runtime,
|
||||
start: jest.fn(async () => events.push("start")),
|
||||
waitForWatchResult: jest.fn(async (videoId) => ({
|
||||
actionSurfaceVisible: true,
|
||||
count: "25",
|
||||
countVisible: true,
|
||||
fillVisible: true,
|
||||
ownedByExpectedWatch: true,
|
||||
rateBarVisible: true,
|
||||
sameActionSurface: true,
|
||||
videoId,
|
||||
})),
|
||||
};
|
||||
@@ -183,6 +429,39 @@ test.each(["userscript", "extension"])("runs one shared artifact scenario contra
|
||||
expect(events).toEqual(["start", "open:abcdefghijk", "signals:watch-render", "close"]);
|
||||
});
|
||||
|
||||
test.each([
|
||||
["a hidden action surface", { actionSurfaceVisible: false }],
|
||||
["a hidden dislike count", { countVisible: false }],
|
||||
["an outgoing watch root", { ownedByExpectedWatch: false }],
|
||||
["a count and bar on different action surfaces", { sameActionSurface: false }],
|
||||
["a missing numeric count", { count: "" }],
|
||||
["a hidden ratio bar", { rateBarVisible: false }],
|
||||
["a hidden ratio fill", { fillVisible: false }],
|
||||
])("the watch-render oracle rejects %s", async (_label, mutation) => {
|
||||
const adapter = {
|
||||
assertNoPageSignals: jest.fn(async () => {}),
|
||||
close: jest.fn(async () => {}),
|
||||
openWatch: jest.fn(async () => {}),
|
||||
runtime: "extension",
|
||||
start: jest.fn(async () => {}),
|
||||
waitForWatchResult: jest.fn(async (videoId) => ({
|
||||
actionSurfaceVisible: true,
|
||||
count: "25",
|
||||
countVisible: true,
|
||||
fillVisible: true,
|
||||
ownedByExpectedWatch: true,
|
||||
rateBarVisible: true,
|
||||
sameActionSurface: true,
|
||||
videoId,
|
||||
...mutation,
|
||||
})),
|
||||
};
|
||||
|
||||
await expect(runArtifactWatchRenderScenario(adapter, { videoId: "abcdefghijk" })).rejects.toThrow();
|
||||
expect(adapter.assertNoPageSignals).not.toHaveBeenCalled();
|
||||
expect(adapter.close).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test.each(["userscript", "extension"])("runs the same continuous A-to-B SPA contract for %s", async (runtime) => {
|
||||
const events = [];
|
||||
const adapter = {
|
||||
@@ -219,6 +498,121 @@ test.each(["userscript", "extension"])("runs the same continuous A-to-B SPA cont
|
||||
expect(events).toEqual(["start", "open:abcdefghijk", "signals:watch-spa-side-panel", "close"]);
|
||||
});
|
||||
|
||||
function createDelayedFailureAdapter(destinationRequestAt) {
|
||||
const events = [];
|
||||
const outgoingRequest = { seen: Promise.resolve(), release: jest.fn() };
|
||||
return {
|
||||
events,
|
||||
assertNoPageSignals: jest.fn(async () => {}),
|
||||
assertSpaNetwork: jest.fn(async () => ({ fromVideoRequests: 1, interactionRequests: 0, toVideoRequests: 1 })),
|
||||
close: jest.fn(async () => events.push("close")),
|
||||
deferNextStatsRequest: jest.fn(() => {
|
||||
events.push("defer");
|
||||
return outgoingRequest;
|
||||
}),
|
||||
navigateSpaWatchWhilePending: jest.fn(async () => ({
|
||||
destination: { destinationReplaced: true, nativeHydrationStartedAt: 1000, nativeHydrationDelay: 750 },
|
||||
outgoing: { beforeBarCount: 0 },
|
||||
})),
|
||||
openSpaWatch: jest.fn(async () => events.push("open")),
|
||||
readDestinationDislikeTextHistory: jest.fn(async () => ["", "65"]),
|
||||
readSpaWatchSnapshot: jest.fn(async () => validSpaSnapshot()),
|
||||
readStatsRequestTimings: jest.fn(() => [{ at: destinationRequestAt, query: { videoId: "zyxwvutsrqp" } }]),
|
||||
runtime: "extension",
|
||||
setPremiumTeaserHidden: jest.fn(async (hidden) => events.push(`hide-teaser:${hidden}`)),
|
||||
start: jest.fn(async () => events.push("start")),
|
||||
waitForWatchResult: jest.fn(),
|
||||
};
|
||||
}
|
||||
|
||||
test("isolates main initialization request timing before loading the outgoing fixture", async () => {
|
||||
const adapter = createDelayedFailureAdapter(1800);
|
||||
await expect(runExtensionDelayedOutgoingFailureScenario(adapter)).resolves.toMatchObject({
|
||||
destinationRequestReadyDelayMs: 50,
|
||||
scenarioId: ARTIFACT_EXTENSION_DELAYED_FAILURE_SCENARIO_ID,
|
||||
});
|
||||
expect(adapter.events).toEqual(["start", "hide-teaser:true", "defer", "open", "close"]);
|
||||
});
|
||||
|
||||
test("waits for the initial background preference write before hiding the teaser", async () => {
|
||||
const previousChrome = globalThis.chrome;
|
||||
const listeners = new Set();
|
||||
let storedValue;
|
||||
const sync = {
|
||||
get: jest.fn(async () => ({ hidePremiumTeaser: storedValue })),
|
||||
set: jest.fn(async ({ hidePremiumTeaser }) => {
|
||||
storedValue = hidePremiumTeaser;
|
||||
}),
|
||||
};
|
||||
globalThis.chrome = {
|
||||
storage: {
|
||||
sync,
|
||||
onChanged: {
|
||||
addListener: (listener) => listeners.add(listener),
|
||||
removeListener: (listener) => listeners.delete(listener),
|
||||
},
|
||||
},
|
||||
};
|
||||
try {
|
||||
const adapter = { worker: { evaluate: (callback, value) => callback(value) } };
|
||||
const pending = HermeticExtensionArtifactAdapter.prototype.setPremiumTeaserHidden.call(adapter, true);
|
||||
await Promise.resolve();
|
||||
expect(sync.set).not.toHaveBeenCalled();
|
||||
storedValue = false;
|
||||
for (const listener of listeners) listener({ hidePremiumTeaser: { newValue: false } }, "sync");
|
||||
await pending;
|
||||
expect(sync.set).toHaveBeenCalledWith({ hidePremiumTeaser: true });
|
||||
expect(storedValue).toBe(true);
|
||||
expect(listeners.size).toBe(0);
|
||||
} finally {
|
||||
if (previousChrome === undefined) delete globalThis.chrome;
|
||||
else globalThis.chrome = previousChrome;
|
||||
}
|
||||
});
|
||||
|
||||
test("arms delayed destination controls before the real navigation click can expose them", async () => {
|
||||
const events = [];
|
||||
const destination = { destinationReplaced: true, nativeHydrationStartedAt: 1000, nativeHydrationDelay: 750 };
|
||||
const page = {
|
||||
evaluate: jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce({ beforeBarCount: 0 })
|
||||
.mockImplementationOnce(async (_callback, options) => {
|
||||
expect(options).toMatchObject({
|
||||
beforeNavigation: true,
|
||||
expectedVideoId: "zyxwvutsrqp",
|
||||
nativeHydrationDelay: 750,
|
||||
});
|
||||
events.push("arm");
|
||||
})
|
||||
.mockImplementationOnce(async () => {
|
||||
events.push("read");
|
||||
return destination;
|
||||
})
|
||||
.mockResolvedValueOnce(undefined),
|
||||
locator: jest.fn(() => ({ click: async () => events.push("click") })),
|
||||
waitForFunction: jest.fn(async () => {}),
|
||||
};
|
||||
await expect(
|
||||
HermeticExtensionArtifactAdapter.prototype.navigateSpaWatchWhilePending.call(
|
||||
{ page },
|
||||
"abcdefghijk",
|
||||
"zyxwvutsrqp",
|
||||
),
|
||||
).resolves.toEqual({ destination, outgoing: { beforeBarCount: 0 } });
|
||||
expect(events).toEqual(["arm", "click", "read"]);
|
||||
});
|
||||
|
||||
test.each([
|
||||
["a request before native controls hydrate", 1749, /before its controls hydrated/],
|
||||
["a request beyond the initialization latency budget", 2001, /budget is 250ms/],
|
||||
])("the isolated initialization scenario still rejects %s", async (_label, at, message) => {
|
||||
const adapter = createDelayedFailureAdapter(at);
|
||||
await expect(runExtensionDelayedOutgoingFailureScenario(adapter)).rejects.toThrow(message);
|
||||
expect(adapter.assertSpaNetwork).not.toHaveBeenCalled();
|
||||
expect(adapter.close).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("recognizes only one ordered, successful destination dislike handshake", () => {
|
||||
const records = [
|
||||
{ method: "POST", pathname: "/puzzle/registration" },
|
||||
@@ -226,6 +620,9 @@ test("recognizes only one ordered, successful destination dislike handshake", ()
|
||||
body: { userId: ARTIFACT_USER_ID, value: -1, videoId: "zyxwvutsrqp" },
|
||||
method: "POST",
|
||||
pathname: "/interact/vote",
|
||||
respondedAt: 122,
|
||||
responseBody: { challenge: "AAAAAAAAAAAAAAAAAAAAAA==", difficulty: 0 },
|
||||
responseStatus: 200,
|
||||
},
|
||||
{
|
||||
body: { solution: "AAAAAA==", userId: ARTIFACT_USER_ID, videoId: "zyxwvutsrqp" },
|
||||
@@ -261,7 +658,13 @@ test.each([
|
||||
}),
|
||||
],
|
||||
["a malformed identity", (value) => ({ ...value, sharedUserId: "short-user" })],
|
||||
["an unfinished vote response", (value) => ({ ...value, vote: { ...value.vote, responded: false } })],
|
||||
["a failed vote status", (value) => ({ ...value, vote: { ...value.vote, responseStatus: 500 } })],
|
||||
["a false confirmation", (value) => ({ ...value, confirmation: { ...value.confirmation, responseBody: false } })],
|
||||
[
|
||||
"an unfinished confirmation response",
|
||||
(value) => ({ ...value, confirmation: { ...value.confirmation, responded: false } }),
|
||||
],
|
||||
[
|
||||
"a failed confirmation status",
|
||||
(value) => ({ ...value, confirmation: { ...value.confirmation, responseStatus: 500 } }),
|
||||
@@ -278,6 +681,15 @@ test.each([
|
||||
expect(isArtifactVoteHandshakeValid(mutate(validVoteHandshake()))).toBe(false);
|
||||
});
|
||||
|
||||
test("accepts successful 2xx vote and confirmation responses", () => {
|
||||
const handshake = validVoteHandshake({
|
||||
confirmation: { ...validVoteHandshake().confirmation, responseStatus: 202 },
|
||||
vote: { ...validVoteHandshake().vote, responseStatus: 201 },
|
||||
});
|
||||
|
||||
expect(isArtifactVoteHandshakeValid(handshake)).toBe(true);
|
||||
});
|
||||
|
||||
test.each(["userscript", "extension"])(
|
||||
"runs one post-SPA dislike activation and confirmation contract for %s",
|
||||
async (runtime) => {
|
||||
@@ -323,7 +735,9 @@ test.each(["userscript", "extension"])(
|
||||
userId: ARTIFACT_USER_ID,
|
||||
value: -1,
|
||||
videoId: "zyxwvutsrqp",
|
||||
voteResponded: true,
|
||||
voteRequests: 1,
|
||||
voteStatus: 200,
|
||||
},
|
||||
runtime,
|
||||
scenarioId: "watch-spa-dislike-activation",
|
||||
@@ -337,6 +751,62 @@ test.each(["userscript", "extension"])(
|
||||
},
|
||||
);
|
||||
|
||||
test.each(["userscript", "extension"])(
|
||||
"requires the first immediate click on cloned initialized controls for %s",
|
||||
async (runtime) => {
|
||||
const events = [];
|
||||
const adapter = {
|
||||
activateClonedSpaDislike: jest.fn(async (videoId) => ({
|
||||
ariaPressedBefore: "false",
|
||||
barCount: 1,
|
||||
countAfterSynchronousClick: "66",
|
||||
countBefore: "65",
|
||||
countContainerCount: 1,
|
||||
interactionStartIndex: 9,
|
||||
presentationCloned: true,
|
||||
videoId,
|
||||
})),
|
||||
assertNoPageSignals: jest.fn(async (scenarioId) => events.push(`signals:${scenarioId}`)),
|
||||
assertSpaVoteNetwork: jest.fn(async () => ({ fromVideoRequests: 1, toVideoRequests: 1 })),
|
||||
close: jest.fn(async () => events.push("close")),
|
||||
navigateSpaWatch: jest.fn(async () => ({
|
||||
destination: { destinationReplaced: true },
|
||||
outgoing: { beforeBarCount: 1 },
|
||||
})),
|
||||
openSpaWatch: jest.fn(async (videoId) => events.push(`open:${videoId}`)),
|
||||
readSpaVoteHandshake: jest.fn(async () => validVoteHandshake()),
|
||||
readSpaWatchSnapshot: jest.fn(async () => validSpaSnapshot()),
|
||||
runtime,
|
||||
start: jest.fn(async () => events.push("start")),
|
||||
waitForWatchResult: jest.fn(async (videoId) => ({ count: "10", fillRatio: 0.9, videoId })),
|
||||
};
|
||||
|
||||
await expect(
|
||||
runArtifactWatchSpaClonedVoteScenario(adapter, {
|
||||
handshakeStableForMs: 0,
|
||||
handshakeTimeoutMs: 1,
|
||||
intervalMs: 1,
|
||||
stabilityDurationMs: 0,
|
||||
stableForMs: 0,
|
||||
timeoutMs: 1,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
activation: { ariaPressedBefore: "false", presentationCloned: true, videoId: "zyxwvutsrqp" },
|
||||
handshake: { interactionRequests: 2, value: -1, videoId: "zyxwvutsrqp" },
|
||||
runtime,
|
||||
scenarioId: "watch-spa-cloned-controls-immediate-dislike",
|
||||
});
|
||||
expect(adapter.activateClonedSpaDislike).toHaveBeenCalledWith("zyxwvutsrqp");
|
||||
expect(adapter.readSpaVoteHandshake).toHaveBeenCalledWith(9, "zyxwvutsrqp", -1);
|
||||
expect(events).toEqual([
|
||||
"start",
|
||||
"open:abcdefghijk",
|
||||
"signals:watch-spa-cloned-controls-immediate-dislike",
|
||||
"close",
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
test("rejects a duplicated post-SPA vote chain and still closes the adapter", async () => {
|
||||
const duplicatedHandshake = validVoteHandshake({
|
||||
confirmationCount: 2,
|
||||
@@ -434,9 +904,13 @@ test("always closes an artifact adapter after a failed visual assertion", async
|
||||
runtime: "extension",
|
||||
start: jest.fn(),
|
||||
waitForWatchResult: jest.fn(async () => ({
|
||||
actionSurfaceVisible: true,
|
||||
count: "25",
|
||||
countVisible: true,
|
||||
fillVisible: true,
|
||||
ownedByExpectedWatch: true,
|
||||
rateBarVisible: false,
|
||||
sameActionSurface: true,
|
||||
videoId: "abcdefghijk",
|
||||
})),
|
||||
};
|
||||
@@ -457,9 +931,13 @@ test("turns an otherwise successful artifact result into a failure when the page
|
||||
runtime: "userscript",
|
||||
start: jest.fn(),
|
||||
waitForWatchResult: jest.fn(async (videoId) => ({
|
||||
actionSurfaceVisible: true,
|
||||
count: "25",
|
||||
countVisible: true,
|
||||
fillVisible: true,
|
||||
ownedByExpectedWatch: true,
|
||||
rateBarVisible: true,
|
||||
sameActionSurface: true,
|
||||
videoId,
|
||||
})),
|
||||
};
|
||||
@@ -492,13 +970,54 @@ function consoleMessage(
|
||||
};
|
||||
}
|
||||
|
||||
function createWorkerDouble(signals = []) {
|
||||
const worker = new EventEmitter();
|
||||
worker.evaluate = jest.fn(async (callback, argument) => {
|
||||
globalThis.__rydArtifactWorkerSignals = signals;
|
||||
try {
|
||||
return await callback(argument);
|
||||
} finally {
|
||||
delete globalThis.__rydArtifactWorkerSignals;
|
||||
}
|
||||
});
|
||||
worker.url = () => "chrome-extension://abcdefghijklmnopabcdefghijklmnop/ryd.background.js";
|
||||
return worker;
|
||||
}
|
||||
|
||||
test("the worker collector fails on a captured unhandled rejection even without a console event", async () => {
|
||||
const worker = createWorkerDouble([
|
||||
{
|
||||
at: 123,
|
||||
details: {},
|
||||
kind: "unhandledrejection",
|
||||
message: "intentional worker promise rejection",
|
||||
name: "Error",
|
||||
stack: "Error: intentional worker promise rejection",
|
||||
},
|
||||
]);
|
||||
const collector = createWorkerSignalCollector(worker, { workerSignals: [] });
|
||||
|
||||
await expect(collector.assertClean("worker-negative-control")).rejects.toThrow(
|
||||
/extension MV3 worker emitted unexpected runtime signals.*intentional worker promise rejection/s,
|
||||
);
|
||||
});
|
||||
|
||||
test("the worker collector includes early console failures reported by the worker probe", async () => {
|
||||
const worker = createWorkerDouble();
|
||||
const collector = createWorkerSignalCollector(worker, {
|
||||
workerSignals: [{ kind: "console-error", message: "startup exploded" }],
|
||||
});
|
||||
|
||||
await expect(collector.assertClean("worker-startup")).rejects.toThrow(/startup exploded/);
|
||||
});
|
||||
|
||||
test.each(["userscript", "extension"])(
|
||||
"collects clean page signals through one shared %s collector",
|
||||
async (runtime) => {
|
||||
const page = createPageDouble();
|
||||
const collector = await createPageSignalCollector(page, runtime);
|
||||
|
||||
page.emit("console", consoleMessage("warning", "harmless warning"));
|
||||
page.emit("console", consoleMessage("info", "harmless information"));
|
||||
|
||||
await expect(collector.assertClean("watch-render")).resolves.toEqual({
|
||||
consoleErrors: [],
|
||||
@@ -513,6 +1032,11 @@ test.each(["userscript", "extension"])(
|
||||
|
||||
test.each([
|
||||
["console error", (page) => page.emit("console", consoleMessage("error", "fixture exploded")), "fixture exploded"],
|
||||
[
|
||||
"console warning",
|
||||
(page) => page.emit("console", consoleMessage("warning", "initialization retry failed")),
|
||||
"initialization retry failed",
|
||||
],
|
||||
[
|
||||
"failed browser resource load",
|
||||
(page) => page.emit("console", consoleMessage("error", "Failed to load resource: net::ERR_FILE_NOT_FOUND")),
|
||||
|
||||
Reference in new issue
Block a user