-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathTabManager.test.ts
More file actions
81 lines (69 loc) · 2.15 KB
/
Copy pathTabManager.test.ts
File metadata and controls
81 lines (69 loc) · 2.15 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
jest.mock('../lib/environment', () => ({
environment: {
chrome: true,
name: 'chrome',
version: 1,
manifestV3: false,
notSupported: {},
notAllowed: {},
bugFreeVersions: {},
initialConfig: {},
storageQuota: { syncQuotaBytesPerItem: () => 8000 },
browserConfig: {}
},
api: {
runtime: { lastError: null },
browserAction: {},
i18n: { getMessage: (key: string) => key },
tabs: {}
}
}));
import { api } from '../lib/environment';
import { TabManager } from '../core/TabManager';
const tabManagerType = TabManager as any;
describe('TabManager webNavigation tracking', () => {
beforeEach(() => {
tabManagerType.tabs = {};
tabManagerType.currentTab = null;
api.runtime.lastError = null;
api.tabs.get = jest.fn((tabId: number, callback: Function) => callback({
id: tabId,
url: 'https://current.example/',
incognito: false,
index: 0
}));
});
it('updates the tab url when main-frame navigation starts', () => {
let tabData = TabManager.getOrSetTab(1, false, 'https://old.example/');
let updates = 0;
const onUpdated = () => updates++;
TabManager.TabUpdated.on(onUpdated);
tabManagerType.handleNavigationStarted({
tabId: 1,
frameId: 0,
url: 'https://new.example/path'
});
TabManager.TabUpdated.off(onUpdated);
expect(tabData.url).toBe('https://new.example/path');
expect(tabData.proxifiedParentDocumentUrl).toBe('https://new.example/path');
expect(updates).toBe(1);
});
it('ignores sub-frame navigation changes', () => {
let tabData = TabManager.getOrSetTab(1, false, 'https://old.example/');
tabManagerType.handleNavigationStarted({
tabId: 1,
frameId: 1,
url: 'https://subframe.example/'
});
expect(tabData.url).toBe('https://old.example/');
});
it('reloads current document url when pending navigation fails', () => {
let tabData = TabManager.getOrSetTab(1, false, 'https://loading.example/');
tabManagerType.handleNavigationError({
tabId: 1,
frameId: 0,
url: 'https://loading.example/'
});
expect(tabData.url).toBe('https://current.example/');
});
});