@@ -52148,16 +52148,35 @@ test('captcha token injection revalidates the selected frame and calls one match
5214852148 assert.equal(hiddenCallbackToken, null, `${build}: hidden widget callback was invoked`);
5214952149 assert.equal(modalCallbackToken, 'TOKEN_MODAL_WIDGET', `${build}: selected callback was not invoked`);
5215052150
52151+ hiddenResponse.value = '';
52152+ modalResponse.value = '';
52153+ const staleFieldId = runtime.injectCaptchaTokenInPage({
52154+ fieldName: 'g-recaptcha-response',
52155+ token: 'TOKEN_STALE_FIELD_ID',
52156+ target: {
52157+ frameId: 9,
52158+ frameUrl: globalThis.location.href,
52159+ websiteKey: 'KEY_SHARED_WIDGET',
52160+ responseFieldId: 'g-recaptcha-response-removed',
52161+ responseFieldIndex: 1,
52162+ },
52163+ });
52164+ assert.equal(staleFieldId.success, false, `${build}: missing selected field ID fell back to an index`);
52165+ assert.equal(staleFieldId.staleTarget, true, `${build}: missing selected field ID was not marked stale`);
52166+ assert.equal(hiddenResponse.value, '', `${build}: stale field ID touched the first response field`);
52167+ assert.equal(modalResponse.value, '', `${build}: stale field ID touched the old indexed response field`);
52168+
5215152169 const canonicalHcaptchaResponse = makeResponse('h-captcha-response-only');
5215252170 let createdCompatibilityResponse = null;
52171+ let hcaptchaCompatibilityResponses = [];
5215352172 const hcaptchaHost = {
5215452173 getAttribute: (name) => name === 'data-sitekey' ? 'HKEY_CANONICAL_ONLY' : null,
5215552174 };
5215652175 const hcaptchaDocument = {
5215752176 querySelector: () => null,
5215852177 querySelectorAll: (selector) => {
5215952178 if (selector.includes('h-captcha-response')) return [canonicalHcaptchaResponse];
52160- if (selector.includes('g-recaptcha-response')) return [] ;
52179+ if (selector.includes('g-recaptcha-response')) return hcaptchaCompatibilityResponses ;
5216152180 if (selector.includes('[data-sitekey]')) return [hcaptchaHost];
5216252181 return [];
5216352182 },
@@ -52208,6 +52227,56 @@ test('captcha token injection revalidates the selected frame and calls one match
5220852227 `${build}: missing hCaptcha compatibility field was not created`,
5220952228 );
5221052229
52230+ const firstCompatibilityResponse = makeResponse('g-recaptcha-response-first');
52231+ const secondCompatibilityResponse = makeResponse('g-recaptcha-response-second');
52232+ hcaptchaCompatibilityResponses = [firstCompatibilityResponse, secondCompatibilityResponse];
52233+ canonicalHcaptchaResponse.value = '';
52234+ createdCompatibilityResponse = null;
52235+ const ambiguousCompatibilityHcaptcha = runtime.injectCaptchaTokenInPage({
52236+ fieldName: 'h-captcha-response',
52237+ alsoSet: 'g-recaptcha-response',
52238+ token: 'TOKEN_HCAPTCHA_AMBIGUOUS_COMPATIBILITY',
52239+ target: {
52240+ frameId: 9,
52241+ frameUrl: hcaptchaWindow.location.href,
52242+ websiteKey: 'HKEY_CANONICAL_ONLY',
52243+ responseFieldId: 'h-captcha-response-only',
52244+ responseFieldIndex: 0,
52245+ documentTimeOrigin: 123456789,
52246+ },
52247+ }, {
52248+ document: hcaptchaDocument,
52249+ window: hcaptchaWindow,
52250+ });
52251+ assert.equal(
52252+ ambiguousCompatibilityHcaptcha.success,
52253+ true,
52254+ `${build}: ambiguous hCaptcha compatibility fields aborted canonical injection`,
52255+ );
52256+ assert.deepEqual(
52257+ ambiguousCompatibilityHcaptcha.fieldsUpdated,
52258+ ['h-captcha-response'],
52259+ `${build}: skipped compatibility field was reported as updated`,
52260+ );
52261+ assert.equal(
52262+ ambiguousCompatibilityHcaptcha.compatibilityFieldSkipped,
52263+ true,
52264+ `${build}: compatibility-field skip was not reported`,
52265+ );
52266+ assert.match(
52267+ ambiguousCompatibilityHcaptcha.compatibilityFieldError,
52268+ /Multiple CAPTCHA response fields/,
52269+ `${build}: compatibility-field ambiguity diagnostic missing`,
52270+ );
52271+ assert.equal(
52272+ canonicalHcaptchaResponse.value,
52273+ 'TOKEN_HCAPTCHA_AMBIGUOUS_COMPATIBILITY',
52274+ `${build}: canonical hCaptcha field was not updated after compatibility ambiguity`,
52275+ );
52276+ assert.equal(firstCompatibilityResponse.value, '', `${build}: first ambiguous compatibility field was updated`);
52277+ assert.equal(secondCompatibilityResponse.value, '', `${build}: second ambiguous compatibility field was updated`);
52278+ assert.equal(createdCompatibilityResponse, null, `${build}: ambiguous compatibility field was recreated`);
52279+
5221152280 responseFields = [response];
5221252281 captchaHosts = [host];
5221352282 const selectedFrameUrl = globalThis.location.href;
0 commit comments