-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdetect-flash-test.js
More file actions
54 lines (39 loc) · 1.28 KB
/
detect-flash-test.js
File metadata and controls
54 lines (39 loc) · 1.28 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
import test from 'tape';
import df, { detectFlash } from './detect-flash';
const TIMEOUT = 1000;
const ID = '__flash_detector';
const CALLBACK = `${ID}_call`;
const dummyFlash = {};
function makeFlashFound(timeout = TIMEOUT) {
setTimeout(() => {
window[CALLBACK]();
}, timeout / 2);
}
test('export', (t) => {
t.plan(1);
t.equal(df, detectFlash, 'should export detectFlash as default');
});
test('detectFlash in case flash is not installed', (t) => {
t.plan(1);
detectFlash('dummy-path')
.catch(() => t.pass('No flash sould be found when flash is not installed.'));
});
test('detectFlash in case flash is installed but blocked', (t) => {
t.plan(1);
navigator.plugins['Shockwave Flash'] = dummyFlash;
detectFlash('dummy-path')
.catch(() => t.pass('No flash sould be found when flash is installed but blocked.'));
});
test('detectFlash in case flash is alive', (t) => {
t.plan(1);
detectFlash('dummy-path')
.then(() => t.pass('Flash should be found when flash is alive.'));
makeFlashFound();
});
test('detectFlash in case flash is alive, but it takes a longer time to detect it', (t) => {
t.plan(1);
const to = TIMEOUT * 5;
detectFlash('dummy-path', to)
.then(() => t.pass('Flash should be found when flash is alive.'));
makeFlashFound(to / 2);
});