-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathformat-flow.test.js
More file actions
109 lines (93 loc) · 3.09 KB
/
Copy pathformat-flow.test.js
File metadata and controls
109 lines (93 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { describe, it, expect, vi, beforeEach } from 'vitest';
// Mock Chrome APIs
const mockChrome = {
action: {
setBadgeText: vi.fn(),
setBadgeBackgroundColor: vi.fn(),
},
tabs: {
query: vi.fn(),
},
scripting: {
executeScript: vi.fn(),
},
tabCapture: {
getMediaStreamId: vi.fn(),
},
offscreen: {
createDocument: vi.fn(),
},
runtime: {
lastError: null,
sendMessage: vi.fn(),
getContexts: vi.fn(),
onMessage: {
addListener: vi.fn(),
},
},
};
global.chrome = mockChrome;
import {
startRecording,
resetRecordingState,
} from './background-logic.js';
describe('Format parameter flow', () => {
beforeEach(() => {
vi.clearAllMocks();
mockChrome.runtime.lastError = null;
mockChrome.runtime.sendMessage.mockImplementation((message, callback) => {
if (message?.action === 'checkFormatSupport' && typeof callback === 'function') {
callback({ supported: true });
}
});
resetRecordingState();
});
it('should forward format=webm to offscreen document', async () => {
mockChrome.scripting.executeScript.mockResolvedValue([]);
mockChrome.tabCapture.getMediaStreamId.mockImplementation((opts, cb) => cb('stream-123'));
mockChrome.runtime.getContexts.mockResolvedValue([{ type: 'OFFSCREEN_DOCUMENT' }]);
await startRecording(123, 60, 2, 'webm');
expect(mockChrome.runtime.sendMessage).toHaveBeenCalledWith(
expect.objectContaining({
action: 'startCapture',
format: 'webm',
})
);
});
it('should forward format=gif to offscreen document', async () => {
mockChrome.scripting.executeScript.mockResolvedValue([]);
mockChrome.tabCapture.getMediaStreamId.mockImplementation((opts, cb) => cb('stream-123'));
mockChrome.runtime.getContexts.mockResolvedValue([{ type: 'OFFSCREEN_DOCUMENT' }]);
await startRecording(123, 60, 2, 'gif');
expect(mockChrome.runtime.sendMessage).toHaveBeenCalledWith(
expect.objectContaining({
action: 'startCapture',
format: 'gif',
})
);
});
it('should forward format=mp4 to offscreen document', async () => {
mockChrome.scripting.executeScript.mockResolvedValue([]);
mockChrome.tabCapture.getMediaStreamId.mockImplementation((opts, cb) => cb('stream-123'));
mockChrome.runtime.getContexts.mockResolvedValue([{ type: 'OFFSCREEN_DOCUMENT' }]);
await startRecording(123, 60, 2, 'mp4');
expect(mockChrome.runtime.sendMessage).toHaveBeenCalledWith(
expect.objectContaining({
action: 'startCapture',
format: 'mp4',
})
);
});
it('should default to webm when format is not specified', async () => {
mockChrome.scripting.executeScript.mockResolvedValue([]);
mockChrome.tabCapture.getMediaStreamId.mockImplementation((opts, cb) => cb('stream-123'));
mockChrome.runtime.getContexts.mockResolvedValue([{ type: 'OFFSCREEN_DOCUMENT' }]);
await startRecording(123, 60, 2);
expect(mockChrome.runtime.sendMessage).toHaveBeenCalledWith(
expect.objectContaining({
action: 'startCapture',
format: 'webm',
})
);
});
});