-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathsourcenode.test.js
More file actions
145 lines (113 loc) · 5.19 KB
/
Copy pathsourcenode.test.js
File metadata and controls
145 lines (113 loc) · 5.19 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
import VideoContext from "../../src/videocontext";
let videocontext;
require("webgl-mock");
beforeEach(function() {
const canvas = new HTMLCanvasElement(500, 500);
videocontext = new VideoContext(canvas);
});
describe("SourceNode", function() {
describe("#duration", function() {
it("should return the time the node is playing for", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
imageNode.start(10);
imageNode.stop(20);
expect(imageNode.duration).toBe(10);
});
it("should return Infinity if no stop time has been specified", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
imageNode.start(10);
expect(imageNode.duration).toBe(Infinity);
});
it("should return undefined if start hasn't been called", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
expect(imageNode.duration).toBe(undefined);
});
it("should return undefined if source nodes has had clearTimelineState called on it", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
imageNode.start(10);
imageNode.stop(20);
imageNode.clearTimelineState();
expect(imageNode.duration).toBe(undefined);
});
});
describe("#start()", function() {
it("should return true if setting start time was successful", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
expect(imageNode.start(10)).toBe(true);
});
it("should return false if start hase already been called without first calling clearTimelineState", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
imageNode.start(0);
expect(imageNode.start(10)).toBe(false);
});
it("should return true if start has already been called followed be calling clearTimelineState", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
imageNode.start(0);
imageNode.clearTimelineState();
expect(imageNode.start(10)).toBe(true);
});
it("duration should be Infinity if stop hasn't been called", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
imageNode.start(0);
expect(imageNode.duration).toBe(Infinity);
});
it("sourceNode state should be set to sequenced", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
imageNode.start(0);
expect(imageNode.state).toBe(1);
});
});
describe("#stop()", function() {
it("should return true if setting stop time was successful", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
imageNode.start(10);
expect(imageNode.stop(20)).toBe(true);
});
it("should return false if start hasn't been called first", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
expect(imageNode.stop(10)).toBe(false);
});
it("should return false if time is before startTime ", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
imageNode.start(10);
expect(imageNode.stop(2)).toBe(false);
});
it("duration should be less than Infinity", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
imageNode.start(0);
imageNode.stop(10);
expect(imageNode.duration).toBeLessThan(Infinity);
});
});
describe("#clearTimelineState()", function() {
it("should set a SourceNodes state to waiting", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
imageNode.start(0);
imageNode.stop(10);
imageNode.clearTimelineState();
expect(imageNode.state).toBe(0);
});
it("should set a SourceNodes duration to undefined", function() {
var imageElement = document.createElement("img");
var imageNode = videocontext.image(imageElement);
imageNode.start(0);
imageNode.stop(10);
imageNode.clearTimelineState();
expect(imageNode.duration).toBe(undefined);
});
});
});