scratch – Blame information for rev 73

Subversion Repositories:
Rev:
Rev Author Line No. Line
73 office 1 describe("SoundJS", function () {
2 beforeEach(function () {
3 jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;
4  
5 this.mp3File = "audio/Thunder1.mp3";
6 this.oggFile = "audio/Thunder1.ogg";
7 this.sound = createjs.Sound;
8 });
9  
10 afterEach(function () {
11 this.sound.removeAllSounds();
12 this.sound.removeAllEventListeners("fileload");
13 });
14  
15 it("should play mp3s", function (done) {
16 var _this = this;
17 this.sound.registerSound(this.mp3File, "thunder");
18 this.sound.on("fileload", function (evt) {
19 expect(evt.src).toBe(_this.mp3File);
20 var s = createjs.Sound.play("thunder");
21 expect(s.playState).toBe("playSucceeded");
22 done();
23 });
24 });
25  
26 it("should play oggs", function (done) {
27 var _this = this;
28 this.sound.registerSound(this.oggFile, "thunder");
29 this.sound.on("fileload", function (evt) {
30 expect(evt.src).toBe(_this.oggFile);
31 var s = createjs.Sound.play("thunder");
32 expect(s.playState).toBe("playSucceeded");
33 done();
34 });
35  
36 });
37  
38 it("removeSound() should work", function (done) {
39 this.sound.registerSound(this.mp3File, "thunder");
40 this.sound.on("fileload", function (evt) {
41 createjs.Sound.removeSound("thunder");
42 var s = createjs.Sound.play("thunder");
43 expect(s.playState).toBe("playFailed");
44 done();
45 });
46  
47 });
48  
49 it("removeAllSounds() should work", function (done) {
50 this.sound.registerSound(this.mp3File, "thunder");
51 this.sound.on("fileload", function (evt) {
52 createjs.Sound.removeAllSounds();
53 var s = createjs.Sound.play("thunder");
54 expect(s.playState).toBe("playFailed");
55 done();
56 });
57  
58 });
59  
60 describe("Capabilities", function () {
61 beforeEach(function () {
62 this.capabilities = this.sound.getCapabilities();
63 this.availableCapabilities = ["panning", "volume", "tracks", "mp3", "ogg", "wav", "mpeg", "m4a", "mp4", "aiff", "wma", "mid"];
64 });
65  
66 it("getCapabilities() should contain the correct properties.", function () {
67 var containsAll = true;
68 var _this = this;
69 this.availableCapabilities.forEach(function (item, index, arr) {
70 if (!(item in _this.capabilities)) {
71 containsAll = false;
72 }
73 });
74  
75 expect(containsAll).toBe(true);
76 });
77  
78 it("getCapability() should match getCapabilities().", function () {
79 for (var n in this.capabilities) {
80 expect(this.capabilities[n]).toBe(this.sound.getCapability(n));
81 }
82 });
83 });
84  
85 it("setMute() should work.", function () {
86 this.sound.setMute(true);
87 expect(this.sound.getMute()).toBe(true);
88 });
89  
90 it("setVolume() should work.", function () {
91 this.sound.setVolume(.5);
92 expect(this.sound.getVolume()).toBe(.5);
93 });
94  
95 it("initializeDefaultPlugins() should work", function () {
96 expect(this.sound.initializeDefaultPlugins()).toBe(true);
97 });
98  
99 it("isReady() should work", function () {
100 expect(this.sound.isReady()).toBe(true);
101 });
102  
103 it("loadComplete() should be true", function (done) {
104 this.sound.registerSound(this.mp3File, "thunder");
105 this.sound.on("fileload", function (evt) {
106 expect(createjs.Sound.loadComplete("thunder")).toBe(true);
107 createjs.Sound.removeAllSounds();
108 expect(createjs.Sound.loadComplete("thunder")).toBe(false);
109 done();
110 });
111 });
112  
113 it("loadComplete() should be false", function (done) {
114 this.sound.registerSound(this.mp3File, "thunder");
115 this.sound.on("fileload", function (evt) {
116 createjs.Sound.removeAllSounds();
117 expect(createjs.Sound.loadComplete("thunder")).toBe(false);
118 done();
119 });
120 });
121  
122 it("registerSounds() should work", function (done) {
123 var sounds = [
124 {src: "Game-Shot.mp3", id: "shot"},
125 {src: "Game-Spawn.mp3", id: "spawn"},
126 {src: "Humm.mp3", id: "humm"}
127 ];
128 createjs.Sound.registerSounds(sounds, "audio/");
129  
130 var loadCount = 0;
131  
132 this.sound.on("fileload", function (evt) {
133 if (++loadCount == sounds.length) {
134 for (var i = 0; i < sounds.length; i++) {
135 var s = createjs.Sound.play(sounds[i].id);
136 expect(s.playState).toBe("playSucceeded");
137 }
138 done();
139 }
140 });
141 });
142  
143 it("defaultInterruptBehavior should be INTERRUPT_NONE", function () {
144 expect(this.sound.defaultInterruptBehavior).toBe(this.sound.INTERRUPT_NONE);
145 });
146  
147 it("EXTENSION_MAP should contain mp4", function () {
148 expect(this.sound.EXTENSION_MAP.m4a).toBe("mp4");
149 });
150  
151 it("Default constants should be be correct", function () {
152 var defaults = {
153 INTERRUPT_ANY: "any",
154 INTERRUPT_EARLY: "early",
155 INTERRUPT_LATE: "late",
156 INTERRUPT_NONE: "none",
157 PLAY_FAILED: "playFailed",
158 PLAY_FINISHED: "playFinished",
159 PLAY_INITED: "playInited",
160 PLAY_INTERRUPTED: "playInterrupted",
161 PLAY_SUCCEEDED: "playSucceeded"
162 };
163  
164 for (var n in defaults) {
165 expect(this.sound[n]).toBe(defaults[n]);
166 }
167 });
168  
169 it("Default SUPPORTED_EXTENSIONS should match defaults", function () {
170 var correctCount = 0;
171 var defaults = ["mp3", "ogg", "mpeg", "wav", "m4a", "mp4", "aiff", "wma", "mid"];
172 for (var i = 0; i < this.sound.SUPPORTED_EXTENSIONS.length; i++) {
173 if (defaults.indexOf(this.sound.SUPPORTED_EXTENSIONS[i]) > -1) {
174 correctCount++;
175 }
176 }
177  
178 expect(correctCount).toBe(defaults.length);
179 });
180  
181 it("stop() should stop all playing sounds.", function (done) {
182 var sounds = [
183 {src: "Game-Shot.mp3", id: "shot"},
184 {src: "Game-Spawn.mp3", id: "spawn"},
185 {src: "Humm.mp3", id: "humm"}
186 ];
187 createjs.Sound.registerSounds(sounds, "audio/");
188  
189 var loadCount = 0;
190 var i;
191  
192 this.sound.on("fileload", function (evt) {
193 if (++loadCount == sounds.length) {
194 var playingSounds = [];
195 for (i = 0; i < sounds.length; i++) {
196 var s = createjs.Sound.play(sounds[i].id);
197 playingSounds.push(s);
198 }
199  
200 createjs.Sound.stop();
201 for (i = 0; i < playingSounds.length; i++) {
202 expect(playingSounds[i].playState).toBe("playFinished");
203 }
204 done();
205 }
206 });
207 });
208 });