forked from webmademovies/popcorn-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
butter.unit.js
242 lines (239 loc) · 6.02 KB
/
butter.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
$(document).ready(function(){
var video = document.getElementById('video');
var popcorn = new Popcorn('#video');
var pluginResults;
var pluginOptions;
var manifest = {
about: {name: 'test', version: '0.1', author: 'Bobby Richter', website: 'http://robothaus.org'},
options: {
start : {elem:'input', type:'text', label:'In'},
end : {elem:'input', type:'text', label:'Out'},
target : 'test-target',
}
};
var plugin = (Popcorn.plugin('test',{
manifest: manifest,
_setup:function(options){pluginOptions = options; pluginResults='_setup';},
start:function(options){pluginResults='start'},
end:function(options){pluginResults='end'}
}));
var pluginInstance = popcorn['test']({start: 1, end: 2});
module("Popcorn");
var tests = [
{
title: 'Popcorn.registry',
test: function() {
ok(Popcorn.registry, 'exists');
}
},
{
title: 'Popcorn.getTrackEvents',
test: function() {
ok(Popcorn.getTrackEvents, 'exists');
}
},
{
title: 'Popcorn.getTrackEvents(popcorn) returns correct results',
test: function() {
expect(2);
var results = Popcorn.getTrackEvents(popcorn);
equals(results[0].start, 1, 'start is 1');
equals(results[0].end, 2, 'end is 2');
}
},
{
title: 'Popcorn.getTrackEvents exists',
test: function() {
ok(Popcorn.getTrackEvents, 'exists');
}
},
{
title: 'Valid plugins are addressable as p[pluginName]',
test: function() {
ok(popcorn['test'], 'popcorn[\'test\'] exists');
}
},
{
title: 'Invalid plugin names yield undefined using p[invalidName]',
test: function() {
ok(popcorn['notValid'] === undefined, 'is undefined');
}
},
{
title: 'p[validPluginName] is expected plugin',
test: function() {
equals(popcorn['test'],plugin['test'], 'popcorn[\'test\'] == plugin[\'test\']');
}
},
{
title: 'Popcorn.registry must be a list',
test: function() {
expect(2);
ok(Popcorn.registry, 'registry exists');
equals(typeof(Popcorn.registry), 'object', 'Popcorn.registry is an object');
}
},
{
title: 'Popcorn.registry must contain plugins',
test: function() {
equals(Popcorn.registry[0], plugin, 'Popcorn.registry contains test plugin');
}
},
{
title: 'plugin.type must exist',
test: function() {
ok(plugin.type, 'exists');
}
},
{
title: 'Plugin instance options._natives must exist',
test: function() {
ok(pluginOptions._natives, 'exists');
}
},
{
title: 'Plugin instance options.target should exist',
test: function() {
ok(pluginOptions.target, 'exists');
}
},
{
title: 'Popcorn.manifest be a list',
test: function() {
expect(2);
ok(Popcorn.manifest, 'Popcorn.manifest exists');
equals(typeof(Popcorn.manifest), 'object', 'Popcorn.manifest is an object');
}
},
{
title: 'Popcorn.manifest must contain plugin manifests',
test: function() {
equals(Popcorn.manifest['test'], manifest);
}
},
{
title: 'Plugin manifest must contain options property',
test: function() {
ok(Popcorn.manifest['test'].options, 'exists');
}
},
{
title: 'popcorn.video exists',
test: function() {
ok(popcorn.video, 'exists');
}
},
{
title: 'popcorn.video.currentTime exists',
test: function() {
ok(popcorn.video.currentTime !== undefined, 'exists');
}
},
{
title: 'popcorn.video.play exists',
test: function() {
ok(popcorn.video.play, 'exists');
}
},
{
title: 'popcorn.video.pause exists',
test: function() {
ok(popcorn.video.pause, 'exists');
}
},
{
title: 'popcorn.video.volume exists',
test: function() {
ok(popcorn.video.volume, 'exists');
}
},
{
title: 'popcorn.video.duration exists',
test: function() {
ok(popcorn.video.duration !== undefined, 'exists');
}
},
{
title: 'popcorn.video.readyState exists',
test: function() {
ok(popcorn.video.readyState !== undefined, 'exists');
}
},
{
title: 'popcorn.data exists',
test: function() {
ok(popcorn.data, 'exists');
}
},
{
title: 'popcorn.data.trackEvents exists',
test: function() {
ok(popcorn.data.trackEvents, 'exists');
}
},
{
title: 'popcorn.data.trackEvents.byStart exists',
test: function() {
ok(popcorn.data.trackEvents.byStart, 'exists');
}
},
{
title: 'popcorn.data.history must be a list',
test: function() {
expect(2);
ok(popcorn.data.history, 'history exists');
equals(typeof(popcorn.data.history), 'object', 'history in an object');
}
},
{
title: 'popcorn.getLastTrackEventId exists and works',
test: function() {
expect(2);
ok(popcorn.getLastTrackEventId, 'exists');
ok(popcorn.getLastTrackEventId(), 'works');
}
},
{
title: 'popcorn.getTrackEvents exists and works',
test: function() {
expect(2);
ok(popcorn.getTrackEvents, 'exists');
ok(popcorn.getTrackEvents(), 'works');
}
},
{
title: 'popcorn.getTrackEvents === Popcorn.getTrackEvents(popcorn)',
test: function() {
expect(2);
var tracks1 = popcorn.getTrackEvents();
var tracks2 = Popcorn.getTrackEvents(popcorn);
equals(tracks1.length, tracks2.length, 'lengths are equal');
equals(tracks1[0], tracks2[0], 'objects are equal');
}
},
{
title: 'popcorn.listen exists && works',
test: function() {
expect(2);
ok(popcorn.listen, 'exists');
popcorn.listen('ended', function(){});
for (var i in popcorn.data.events['ended']) {
ok(popcorn.data.events['ended'][i], 'works');
break;
} //for
}
},
{
title: 'popcorn.removeTrackEvent exists and works',
test: function() {
expect(2);
ok(popcorn.removeTrackEvent, 'exists');
popcorn.removeTrackEvent(popcorn.getLastTrackEventId());
equals(popcorn.getTrackEvents().length, 0, 'works');
}
},
];
for (var i=0; i<tests.length; ++i) {
test(tests[i].title, tests[i].test);
} //for
});