forked from mozilla/popcorn-js
-
Notifications
You must be signed in to change notification settings - Fork 7
/
popcorn.parserVTT.unit.js
67 lines (59 loc) · 1.62 KB
/
popcorn.parserVTT.unit.js
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
test( "Popcorn 0.3 WebSRT/VTT Parser Plugin", function () {
var count = 0,
numSubs = 0,
sub,
poppercorn = Popcorn( "#video" ),
expectedSubs = [
{
id: "1",
text: "Senator, we're making<br />our final approach into Coruscant.",
start: 2.4,
end: 7.2
},
{
id: "2",
text: "Very good, Lieutenant.",
start: 9.712,
end: 13.399
},
{
id: "Track-3",
text: "It's a trap!",
start: 15.042,
end: 18.042
},
{
id: "ID9",
text: "This text is <b>boldy <i>italicized</i></b>",
start: 20.000,
end: 21.670
}
],
expects = expectedSubs.length*4 + 1;
function plus() {
if ( ++count === expects ) {
start();
}
}
poppercorn.parseVTT( "data/unit.vtt" );
expect( expects );
stop( 5000 );
// Allow load time
setTimeout(function () {
Popcorn.forEach( poppercorn.getTrackEvents(), function( evt ) {
if( evt._natives.type === "subtitle" ) {
sub = expectedSubs[numSubs++];
strictEqual( evt.id, sub.id, "Correctly parsed id" );
plus();
strictEqual( evt.text, sub.text, "Correctly parsed text of " + evt.id );
plus();
strictEqual( evt.start, sub.start, "Correctly parsed start at " + evt.id );
plus();
strictEqual( evt.end, sub.end, "Correctly parsed end at " + evt.id );
plus();
}
});
equals( expectedSubs.length, numSubs, "Parsed all subtitles" );
plus();
}, 500);
});