forked from fingerprintjs/fingerprintjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen_frame.test.ts
More file actions
173 lines (158 loc) · 5.47 KB
/
screen_frame.test.ts
File metadata and controls
173 lines (158 loc) · 5.47 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { withMockProperties } from '../../tests/utils'
import * as screenFrame from './screen_frame'
describe('Sources', () => {
describe('screenFrame', () => {
beforeEach(() => {
screenFrame.resetScreenFrameWatch()
})
it('gets non-zero frame', async () => {
await withMockProperties(
screen,
{
width: { get: () => 1440 },
height: { get: () => 900 },
availWidth: { get: () => 1367 },
availHeight: { get: () => 853 },
availLeft: { get: () => 49 },
availTop: { get: () => 11 },
},
async () => {
const frame = await screenFrame.getScreenFrame()()
expect(frame).toEqual([11, 24, 36, 49])
const roundedFrame = await screenFrame.getRoundedScreenFrame()()
expect(roundedFrame).toEqual([10, 20, 40, 50])
},
)
})
it('gets null frame', async () => {
await withMockProperties(
screen,
{
width: { get: () => 1920 },
height: { get: () => 1080 },
availWidth: { get: () => 1920 },
availHeight: { get: () => 1080 },
availLeft: { get: () => 0 },
availTop: { get: () => 0 },
},
async () => {
const frame = await screenFrame.getScreenFrame()()
expect(frame).toEqual([0, 0, 0, 0])
const roundedFrame = await screenFrame.getRoundedScreenFrame()()
expect(roundedFrame).toEqual([0, 0, 0, 0])
},
)
})
it('gets frame with unavailable position (IE and Edge ≤18)', async () => {
await withMockProperties(
screen,
{
width: { get: () => 1280 },
height: { get: () => 1024 },
availWidth: { get: () => 1182 },
availHeight: { get: () => 1000 },
availLeft: { get: () => undefined },
availTop: { get: () => undefined },
},
async () => {
const frame = await screenFrame.getScreenFrame()()
expect(frame).toEqual([null, 98, 24, null])
const roundedFrame = await screenFrame.getRoundedScreenFrame()()
expect(roundedFrame).toEqual([null, 100, 20, null])
},
)
})
it('watches for screen frame', async () => {
try {
jasmine.clock().install()
jasmine.clock().mockDate()
let screenFrameGetter: () => Promise<screenFrame.FrameSize>
await withMockProperties(
screen,
{
width: { get: () => 640 },
height: { get: () => 480 },
availWidth: { get: () => 640 },
availHeight: { get: () => 480 },
availLeft: { get: () => 0 },
availTop: { get: () => 0 },
},
async () => {
screenFrameGetter = screenFrame.getScreenFrame()
// The screen frame is null now
const frame = await screenFrameGetter()
expect(frame).toEqual([0, 0, 0, 0])
},
)
await withMockProperties(
screen,
{
width: { get: () => 640 },
height: { get: () => 480 },
availWidth: { get: () => 600 },
availHeight: { get: () => 400 },
availLeft: { get: () => 10 },
availTop: { get: () => 30 },
},
async () => {
// The screen frame has become non-null, the frame watch shall remember it
jasmine.clock().tick(screenFrame.screenFrameCheckInterval)
},
)
await withMockProperties(
screen,
{
width: { get: () => 640 },
height: { get: () => 480 },
availWidth: { get: () => 640 },
availHeight: { get: () => 480 },
availLeft: { get: () => 0 },
availTop: { get: () => 0 },
},
async () => {
// The screen frame has become null again, `getScreenFrame` shall return the remembered non-null frame
jasmine.clock().tick(screenFrame.screenFrameCheckInterval)
const frame = await screenFrameGetter()
expect(frame).toEqual([30, 30, 50, 10])
},
)
await withMockProperties(
screen,
{
width: { get: () => 640 },
height: { get: () => 480 },
availWidth: { get: () => 600 },
availHeight: { get: () => 400 },
availLeft: { get: () => 30 },
availTop: { get: () => 10 },
},
async () => {
// The screen frame has become non-null, `getScreenFrame` shall return the new size and remember it
jasmine.clock().tick(screenFrame.screenFrameCheckInterval)
const frame = await screenFrameGetter()
expect(frame).toEqual([10, 10, 70, 30])
},
)
await withMockProperties(
screen,
{
width: { get: () => 640 },
height: { get: () => 480 },
availWidth: { get: () => 640 },
availHeight: { get: () => 480 },
availLeft: { get: () => 0 },
availTop: { get: () => 0 },
},
async () => {
// The screen frame has become null again, `getScreenFrame` shall return the new non-null frame
jasmine.clock().tick(screenFrame.screenFrameCheckInterval)
const frame = await screenFrameGetter()
expect(frame).toEqual([10, 10, 70, 30])
},
)
} finally {
jasmine.clock().uninstall()
}
})
})
})