1 // ==========================================================================
  2 // Project:   SproutCore - JavaScript Application Framework
  3 // Copyright: ©2006-2011 Strobe Inc. and contributors.
  4 //            Portions ©2008-2011 Apple Inc. All rights reserved.
  5 // License:   Licensed under MIT license (see license.js)
  6 // ==========================================================================
  7 var
  8   INITIAL_VOL = 0.8,
  9   TIMEOUT = 1000,
 10   TESTFILE = static_url("silence.mp3"), // the real sound of silence
 11   isPhantom = !!window.callPhantom,
 12   pane, audioView;
 13 
 14 module("SC.AudioView", {
 15 
 16   setup: function () {
 17     SC.RunLoop.begin();
 18 
 19     audioView = SC.AudioView.create({
 20       volume: INITIAL_VOL
 21     });
 22 
 23     pane = SC.MainPane.create();
 24     pane.appendChild(audioView);
 25     pane.append();
 26 
 27     SC.RunLoop.end();
 28 
 29     SC.Timer.schedule({
 30       action: function () { audioView.set("value", TESTFILE); },
 31       interval: 100
 32     });
 33   },
 34 
 35   teardown: function () {
 36     pane.remove();
 37     pane = audioView = null;
 38   }
 39 });
 40 
 41 function checkAudioSupport() {
 42   if (isPhantom) {
 43     warn("Audio cannot be tested in PhantomJS (see http://phantomjs.org/supported-web-standards.html)");
 44     return false;
 45   }
 46   return true;
 47 }
 48 
 49 test("Test MP3 file", function () {
 50   if (!checkAudioSupport()) return;
 51   stop(TIMEOUT);
 52 
 53   // assume audio has been loaded when the duration changes
 54   audioView.addObserver("duration", function (sender, key) {
 55     ok(sender.get(key), "MP3 file did load");
 56     start();
 57   });
 58 });
 59 
 60 test("Test initial volume", function () {
 61   if (!checkAudioSupport()) return;
 62   stop(TIMEOUT);
 63 
 64   // assume audio has been loaded when the duration changes
 65   audioView.addObserver("duration", function (sender, key) {
 66     equals(audioView.get("volume"), INITIAL_VOL, "Initial volume is still set after audio has been loaded");
 67     start();
 68   });
 69 });