Files
webmail/lib/__tests__/account-utils-http2.test.ts
T
lucamzanon 335347a56f fix: detect HTTP/2 from the initial navigation timing so accounts aren't capped at five
isHttp2Available() only inspected "resource" timing entries, which can be
empty right after a fresh login or session restore, before any subresource
finishes loading. On an HTTP/2 page this made getMaxAccounts() fall back to
the HTTP/1.1 cap of five accounts. Include the "navigation" timing entry,
whose nextHopProtocol is known immediately, so h2/h3 is recognized on first
load. Environments without timing data still return false (no h2 assumed).
2026-09-10 10:14:25 +02:00

14 lines
788 B
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest';
import { getMaxAccounts, MAX_ACCOUNT_SLOTS } from '../account-utils';
afterEach(() => vi.restoreAllMocks());
describe('account limit protocol detection', () => {
it('recognizes HTTP/2 from document navigation before resources load', () => {
vi.spyOn(performance, 'getEntriesByType').mockImplementation(type => type === 'navigation' ? [{ nextHopProtocol: 'h2' } as PerformanceResourceTiming] : []);
expect(getMaxAccounts()).toBe(MAX_ACCOUNT_SLOTS);
});
it('retains the conservative cap when no multiplexed protocol was observed', () => {
vi.spyOn(performance, 'getEntriesByType').mockReturnValue([{ nextHopProtocol: 'http/1.1' } as PerformanceResourceTiming]);
expect(getMaxAccounts()).toBe(5);
});
});