michael@0: // In each list of tests below, test file types that are not supported should michael@0: // be ignored. To make sure tests respect that, we include a file of type michael@0: // "bogus/duh" in each list. michael@0: michael@0: // These are small test files, good for just seeing if something loads. We michael@0: // really only need one test file per backend here. michael@0: var gSmallTests = [ michael@0: { name:"small-shot.ogg", type:"audio/ogg", duration:0.276 }, michael@0: { name:"small-shot.m4a", type:"audio/mp4", duration:0.29 }, michael@0: { name:"small-shot.mp3", type:"audio/mpeg", duration:0.27 }, michael@0: { name:"small-shot-mp3.mp4", type:"audio/mp4; codecs=mp3", duration:0.34 }, michael@0: { name:"r11025_s16_c1.wav", type:"audio/x-wav", duration:1.0 }, michael@0: { name:"320x240.ogv", type:"video/ogg", width:320, height:240, duration:0.266 }, michael@0: { name:"seek.webm", type:"video/webm", width:320, height:240, duration:3.966 }, michael@0: { name:"vp9.webm", type:"video/webm", width:320, height:240, duration:4 }, michael@0: { name:"detodos.opus", type:"audio/ogg; codecs=opus", duration:2.9135 }, michael@0: { name:"gizmo.mp4", type:"video/mp4", duration:5.56 }, michael@0: { name:"bogus.duh", type:"bogus/duh" } michael@0: ]; michael@0: michael@0: // Used by test_bug654550.html, for videoStats preference michael@0: var gVideoTests = [ michael@0: { name:"320x240.ogv", type:"video/ogg", width:320, height:240, duration:0.266 }, michael@0: { name:"seek.webm", type:"video/webm", width:320, height:240, duration:3.966 }, michael@0: { name:"bogus.duh", type:"bogus/duh" } michael@0: ]; michael@0: michael@0: // Used by test_progress to ensure we get the correct progress information michael@0: // during resource download. michael@0: var gProgressTests = [ michael@0: { name:"r11025_u8_c1.wav", type:"audio/x-wav", duration:1.0, size:11069 }, michael@0: { name:"big.wav", type:"audio/x-wav", duration:9.278981, size:102444 }, michael@0: { name:"seek.ogv", type:"video/ogg", duration:3.966, size:285310 }, michael@0: { name:"320x240.ogv", type:"video/ogg", width:320, height:240, duration:0.266, size:28942 }, michael@0: { name:"seek.webm", type:"video/webm", duration:3.966, size:215529 }, michael@0: { name:"gizmo.mp4", type:"video/mp4", duration:5.56, size:383631 }, michael@0: { name:"bogus.duh", type:"bogus/duh" } michael@0: ]; michael@0: michael@0: // Used by test_played.html michael@0: var gPlayedTests = [ michael@0: { name:"big.wav", type:"audio/x-wav", duration:9.0 }, michael@0: { name:"seek.ogv", type:"video/ogg", duration:3.966 }, michael@0: { name:"seek.webm", type:"video/webm", duration:3.966 }, michael@0: { name:"gizmo.mp4", type:"video/mp4", duration:5.56 }, michael@0: { name:"owl.mp3", type:"audio/mpeg", duration:3.29 }, michael@0: { name:"vbr.mp3", type:"audio/mpeg", duration:10.0 }, michael@0: { name:"bug495794.ogg", type:"audio/ogg", duration:0.3 } michael@0: ]; michael@0: michael@0: // Used by test_mozLoadFrom. Need one test file per decoder backend, plus michael@0: // anything for testing clone-specific bugs. michael@0: var cloneKey = Math.floor(Math.random()*100000000); michael@0: var gCloneTests = gSmallTests.concat([ michael@0: // Actual duration is ~200ms, we have Content-Duration lie about it. michael@0: { name:"bug520908.ogv", type:"video/ogg", duration:9000 }, michael@0: // short-video is more like 1s, so if you load this twice you'll get an unexpected duration michael@0: { name:"dynamic_resource.sjs?key=" + cloneKey + "&res1=320x240.ogv&res2=short-video.ogv", michael@0: type:"video/ogg", duration:0.266 }, michael@0: ]); michael@0: michael@0: // Used by test_play_twice. Need one test file per decoder backend, plus michael@0: // anything for testing bugs that occur when replying a played file. michael@0: var gReplayTests = gSmallTests.concat([ michael@0: { name:"bug533822.ogg", type:"audio/ogg" }, michael@0: ]); michael@0: michael@0: // Used by test_paused_after_ended. Need one test file per decoder backend, plus michael@0: // anything for testing bugs that occur when replying a played file. michael@0: var gPausedAfterEndedTests = gSmallTests.concat([ michael@0: { name:"r11025_u8_c1.wav", type:"audio/x-wav", duration:1.0 }, michael@0: { name:"small-shot.ogg", type:"video/ogg", duration:0.276 } michael@0: ]); michael@0: michael@0: // Test the mozHasAudio property, and APIs that detect different kinds of michael@0: // tracks michael@0: var gTrackTests = [ michael@0: { name:"big.wav", type:"audio/x-wav", duration:9.278981, size:102444, hasAudio:true, hasVideo:false }, michael@0: { name:"320x240.ogv", type:"video/ogg", width:320, height:240, duration:0.266, size:28942, hasAudio:false, hasVideo:true }, michael@0: { name:"short-video.ogv", type:"video/ogg", duration:1.081, hasAudio:true, hasVideo:true }, michael@0: { name:"seek.webm", type:"video/webm", duration:3.966, size:215529, hasAudio:false, hasVideo:true }, michael@0: { name:"bogus.duh", type:"bogus/duh" } michael@0: ]; michael@0: michael@0: // Used by any media recorder test. Need one test file per decoder backend michael@0: // currently supported by the media encoder. michael@0: var gMediaRecorderTests = [ michael@0: { name:"detodos.opus", type:"audio/ogg; codecs=opus", duration:2.9135 } michael@0: ]; michael@0: michael@0: // These are files that we want to make sure we can play through. We can michael@0: // also check metadata. Put files of the same type together in this list so if michael@0: // something crashes we have some idea of which backend is responsible. michael@0: // Used by test_playback, which expects no error event and one ended event. michael@0: var gPlayTests = [ michael@0: // 8-bit samples michael@0: { name:"r11025_u8_c1.wav", type:"audio/x-wav", duration:1.0 }, michael@0: // 8-bit samples, file is truncated michael@0: { name:"r11025_u8_c1_trunc.wav", type:"audio/x-wav", duration:1.8 }, michael@0: // file has trailing non-PCM data michael@0: { name:"r11025_s16_c1_trailing.wav", type:"audio/x-wav", duration:1.0 }, michael@0: // file with list chunk michael@0: { name:"r16000_u8_c1_list.wav", type:"audio/x-wav", duration:4.2 }, michael@0: michael@0: // Ogg stream without eof marker michael@0: { name:"bug461281.ogg", type:"application/ogg", duration:2.208 }, michael@0: michael@0: // oggz-chop stream michael@0: { name:"bug482461.ogv", type:"video/ogg", duration:4.34 }, michael@0: // Theora only oggz-chop stream michael@0: { name:"bug482461-theora.ogv", type:"video/ogg", duration:4.138 }, michael@0: // With first frame a "duplicate" (empty) frame. michael@0: { name:"bug500311.ogv", type:"video/ogg", duration:1.96 }, michael@0: // Small audio file michael@0: { name:"small-shot.ogg", type:"video/ogg", duration:0.276 }, michael@0: // More audio in file than video. michael@0: { name:"short-video.ogv", type:"video/ogg", duration:1.081 }, michael@0: // First Theora data packet is zero bytes. michael@0: { name:"bug504613.ogv", type:"video/ogg", duration:Number.NaN }, michael@0: // Multiple audio streams. michael@0: { name:"bug516323.ogv", type:"video/ogg", duration:4.208 }, michael@0: // oggz-chop with non-keyframe as first frame michael@0: { name:"bug556821.ogv", type:"video/ogg", duration:2.551 }, michael@0: michael@0: // Encoded with vorbis beta1, includes unusually sized codebooks michael@0: { name:"beta-phrasebook.ogg", type:"audio/ogg", duration:4.01 }, michael@0: // Small file, only 1 frame with audio only. michael@0: { name:"bug520493.ogg", type:"audio/ogg", duration:0.458 }, michael@0: // Small file with vorbis comments with 0 length values and names. michael@0: { name:"bug520500.ogg", type:"audio/ogg", duration:0.123 }, michael@0: michael@0: // Various weirdly formed Ogg files michael@0: { name:"bug499519.ogv", type:"video/ogg", duration:0.24 }, michael@0: { name:"bug506094.ogv", type:"video/ogg", duration:0 }, michael@0: { name:"bug498855-1.ogv", type:"video/ogg", duration:0.24 }, michael@0: { name:"bug498855-2.ogv", type:"video/ogg", duration:0.24 }, michael@0: { name:"bug498855-3.ogv", type:"video/ogg", duration:0.24 }, michael@0: { name:"bug504644.ogv", type:"video/ogg", duration:1.6 }, michael@0: { name:"chain.ogv", type:"video/ogg", duration:Number.NaN }, michael@0: { name:"bug523816.ogv", type:"video/ogg", duration:0.533 }, michael@0: { name:"bug495129.ogv", type:"video/ogg", duration:2.41 }, michael@0: { name:"bug498380.ogv", type:"video/ogg", duration:0.533 }, michael@0: { name:"bug495794.ogg", type:"audio/ogg", duration:0.3 }, michael@0: { name:"bug557094.ogv", type:"video/ogg", duration:0.24 }, michael@0: { name:"multiple-bos.ogg", type:"video/ogg", duration:0.431 }, michael@0: { name:"audio-overhang.ogg", type:"audio/ogg", duration:2.3 }, michael@0: { name:"video-overhang.ogg", type:"audio/ogg", duration:3.966 }, michael@0: michael@0: // bug461281.ogg with the middle second chopped out. michael@0: { name:"audio-gaps.ogg", type:"audio/ogg", duration:2.208 }, michael@0: michael@0: // Test playback/metadata work after a redirect michael@0: { name:"redirect.sjs?domain=mochi.test:8888&file=320x240.ogv", michael@0: type:"video/ogg", duration:0.266 }, michael@0: michael@0: // Test playback of a webm file michael@0: { name:"seek.webm", type:"video/webm", duration:3.966 }, michael@0: michael@0: // Test playback of a WebM file with non-zero start time. michael@0: { name:"split.webm", type:"video/webm", duration:1.967 }, michael@0: michael@0: // Test playback of a WebM file with vp9 video michael@0: //{ name:"vp9.webm", type:"video/webm", duration:4 }, michael@0: { name:"vp9cake.webm", type:"video/webm", duration:7.966 }, michael@0: michael@0: // Test playback of a raw file michael@0: { name:"seek.yuv", type:"video/x-raw-yuv", duration:1.833 }, michael@0: michael@0: // A really short, low sample rate, single channel file. This tests whether michael@0: // we can handle playing files when only push very little audio data to the michael@0: // hardware. michael@0: { name:"spacestorm-1000Hz-100ms.ogg", type:"audio/ogg", duration:0.099 }, michael@0: michael@0: // Opus data in an ogg container michael@0: { name:"detodos.opus", type:"audio/ogg; codecs=opus", duration:2.9135 }, michael@0: // Opus data in a webm container michael@0: { name:"detodos.webm", type:"audio/webm; codecs=opus", duration:2.9135 }, michael@0: michael@0: // Multichannel Opus in an ogg container michael@0: { name:"test-1-mono.opus", type:"audio/ogg; codecs=opus", duration:1.044 }, michael@0: { name:"test-2-stereo.opus", type:"audio/ogg; codecs=opus", duration:2.925 }, michael@0: { name:"test-3-LCR.opus", type:"audio/ogg; codecs=opus", duration:4.214 }, michael@0: { name:"test-4-quad.opus", type:"audio/ogg; codecs=opus", duration:6.234 }, michael@0: { name:"test-5-5.0.opus", type:"audio/ogg; codecs=opus", duration:7.558 }, michael@0: { name:"test-6-5.1.opus", type:"audio/ogg; codecs=opus", duration:10.333 }, michael@0: { name:"test-7-6.1.opus", type:"audio/ogg; codecs=opus", duration:11.690 }, michael@0: { name:"test-8-7.1.opus", type:"audio/ogg; codecs=opus", duration:13.478 }, michael@0: michael@0: { name:"gizmo.mp4", type:"video/mp4", duration:5.56 }, michael@0: michael@0: { name:"small-shot.m4a", type:"audio/mp4", duration:0.29 }, michael@0: { name:"small-shot.mp3", type:"audio/mpeg", duration:0.27 }, michael@0: { name:"owl.mp3", type:"audio/mpeg", duration:3.29 }, michael@0: // owl.mp3 as above, but with something funny going on in the ID3v2 tag michael@0: // that causes DirectShow to fail. michael@0: { name:"owl-funny-id3.mp3", type:"audio/mpeg", duration:3.29 }, michael@0: // owl.mp3 as above, but with something even funnier going on in the ID3v2 tag michael@0: // that causes DirectShow to fail. michael@0: { name:"owl-funnier-id3.mp3", type:"audio/mpeg", duration:3.29 }, michael@0: // One second of silence with ~140KB of ID3 tags. Usually when the first MP3 michael@0: // frame is at such a high offset into the file, MP3FrameParser will give up michael@0: // and report that the stream is not MP3. However, it does not count ID3 tags michael@0: // in that offset. This test case makes sure that ID3 exclusion holds. michael@0: { name:"huge-id3.mp3", type:"audio/mpeg", duration:1.00 }, michael@0: // A truncated VBR MP3 with just enough frames to keep most decoders happy. michael@0: // The Xing header reports the length of the file to be around 10 seconds, but michael@0: // there is really only one second worth of data. We want MP3FrameParser to michael@0: // trust the header, so this should be reported as 10 seconds. michael@0: { name:"vbr-head.mp3", type:"audio/mpeg", duration:10.00 }, michael@0: michael@0: // Invalid file michael@0: { name:"bogus.duh", type:"bogus/duh", duration:Number.NaN } michael@0: ]; michael@0: michael@0: // A file for each type we can support. michael@0: var gSnifferTests = [ michael@0: { name:"big.wav", type:"audio/x-wav", duration:9.278981, size:102444 }, michael@0: { name:"320x240.ogv", type:"video/ogg", width:320, height:240, duration:0.233, size:28942 }, michael@0: { name:"seek.webm", type:"video/webm", duration:3.966, size:215529 }, michael@0: { name:"gizmo.mp4", type:"video/mp4", duration:5.56, size:383631 }, michael@0: // A mp3 file with id3 tags. michael@0: { name:"id3tags.mp3", type:"audio/mpeg", duration:0.28, size:3530}, michael@0: { name:"bogus.duh", type:"bogus/duh" } michael@0: ]; michael@0: michael@0: // Files we must reject as invalid. michael@0: var gInvalidTests = [ michael@0: { name:"invalid-m0c0.opus", type:"audio/ogg; codecs=opus"}, michael@0: { name:"invalid-m0c3.opus", type:"audio/ogg; codecs=opus"}, michael@0: { name:"invalid-m1c0.opus", type:"audio/ogg; codecs=opus"}, michael@0: { name:"invalid-m1c9.opus", type:"audio/ogg; codecs=opus"}, michael@0: { name:"invalid-m2c0.opus", type:"audio/ogg; codecs=opus"}, michael@0: { name:"invalid-m2c1.opus", type:"audio/ogg; codecs=opus"}, michael@0: { name:"invalid-cmap-short.opus", type:"audio/ogg; codecs=opus"}, michael@0: { name:"invalid-cmap-s0c0.opus", type:"audio/ogg; codecs=opus"}, michael@0: { name:"invalid-cmap-s0c2.opus", type:"audio/ogg; codecs=opus"}, michael@0: { name:"invalid-cmap-s1c2.opus", type:"audio/ogg; codecs=opus"}, michael@0: { name:"invalid-preskip.webm", type:"audio/webm; codecs=opus"}, michael@0: ]; michael@0: michael@0: // Converts a path/filename to a file:// URI which we can load from disk. michael@0: // Optionally checks whether the file actually exists on disk at the location michael@0: // we've specified. michael@0: function fileUriToSrc(path, mustExist) { michael@0: // android mochitest doesn't support file:// michael@0: if (navigator.appVersion.indexOf("Android") != -1 || SpecialPowers.Services.appinfo.name == "B2G") michael@0: return path; michael@0: michael@0: const Ci = SpecialPowers.Ci; michael@0: const Cc = SpecialPowers.Cc; michael@0: const Cr = SpecialPowers.Cr; michael@0: var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. michael@0: getService(Ci.nsIProperties); michael@0: var f = dirSvc.get("CurWorkD", Ci.nsILocalFile); michael@0: var split = path.split("/"); michael@0: for(var i = 0; i < split.length; ++i) { michael@0: f.append(split[i]); michael@0: } michael@0: if (mustExist && !f.exists()) { michael@0: ok(false, "We expected '" + path + "' to exist, but it doesn't!"); michael@0: } michael@0: return f.path; michael@0: } michael@0: michael@0: // Returns true if two TimeRanges are equal, false otherwise michael@0: function range_equals(r1, r2) { michael@0: if (r1.length != r2.length) { michael@0: return false; michael@0: } michael@0: for (var i = 0; i < r1.length; i++) { michael@0: if (r1.start(i) != r2.start(i) || r1.end(i) != r2.end(i)) { michael@0: return false; michael@0: } michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: // These are URIs to files that we use to check that we don't leak any state michael@0: // or other information such that script can determine stuff about a user's michael@0: // environment. Used by test_info_leak. michael@0: var gInfoLeakTests = [ michael@0: { michael@0: type: 'video/ogg', michael@0: src: fileUriToSrc("tests/content/media/test/320x240.ogv", true), michael@0: },{ michael@0: type: 'video/ogg', michael@0: src: fileUriToSrc("tests/content/media/test/404.ogv", false), michael@0: }, { michael@0: type: 'audio/x-wav', michael@0: src: fileUriToSrc("tests/content/media/test/r11025_s16_c1.wav", true), michael@0: }, { michael@0: type: 'audio/x-wav', michael@0: src: fileUriToSrc("tests/content/media/test/404.wav", false), michael@0: }, { michael@0: type: 'audio/ogg', michael@0: src: fileUriToSrc("tests/content/media/test/bug461281.ogg", true), michael@0: }, { michael@0: type: 'audio/ogg', michael@0: src: fileUriToSrc("tests/content/media/test/404.ogg", false), michael@0: }, { michael@0: type: 'video/webm', michael@0: src: fileUriToSrc("tests/content/media/test/seek.webm", true), michael@0: }, { michael@0: type: 'video/webm', michael@0: src: fileUriToSrc("tests/content/media/test/404.webm", false), michael@0: }, { michael@0: type: 'video/ogg', michael@0: src: 'http://localhost/404.ogv', michael@0: }, { michael@0: type: 'audio/x-wav', michael@0: src: 'http://localhost/404.wav', michael@0: }, { michael@0: type: 'video/webm', michael@0: src: 'http://localhost/404.webm', michael@0: }, { michael@0: type: 'video/ogg', michael@0: src: 'http://example.com/tests/content/media/test/test_info_leak.html' michael@0: }, { michael@0: type: 'audio/ogg', michael@0: src: 'http://example.com/tests/content/media/test/test_info_leak.html' michael@0: } michael@0: ]; michael@0: michael@0: // These are files that must fire an error during load or playback, and do not michael@0: // cause a crash. Put files of the same type together in this list so if michael@0: // something crashes we have some idea of which backend is responsible. Used michael@0: // by test_playback_errors, which expects one error event and no ended event. michael@0: // Put files of the same type together in this list so if something crashes michael@0: // we have some idea of which backend is responsible. michael@0: var gErrorTests = [ michael@0: { name:"bogus.wav", type:"audio/x-wav" }, michael@0: { name:"bogus.ogv", type:"video/ogg" }, michael@0: { name:"448636.ogv", type:"video/ogg" }, michael@0: { name:"bug504843.ogv", type:"video/ogg" }, michael@0: { name:"bug501279.ogg", type:"audio/ogg" }, michael@0: { name:"bug580982.webm", type:"video/webm" }, michael@0: { name:"bug603918.webm", type:"video/webm" }, michael@0: { name:"bug604067.webm", type:"video/webm" }, michael@0: { name:"bogus.duh", type:"bogus/duh" } michael@0: ]; michael@0: michael@0: // These are files that have nontrivial duration and are useful for seeking within. michael@0: var gSeekTests = [ michael@0: { name:"r11025_s16_c1.wav", type:"audio/x-wav", duration:1.0 }, michael@0: { name:"audio.wav", type:"audio/x-wav", duration:0.031247 }, michael@0: { name:"seek.ogv", type:"video/ogg", duration:3.966 }, michael@0: { name:"320x240.ogv", type:"video/ogg", duration:0.266 }, michael@0: { name:"seek.webm", type:"video/webm", duration:3.966 }, michael@0: { name:"bug516323.indexed.ogv", type:"video/ogg", duration:4.208333 }, michael@0: { name:"split.webm", type:"video/webm", duration:1.967 }, michael@0: { name:"detodos.opus", type:"audio/ogg; codecs=opus", duration:2.9135 }, michael@0: { name:"gizmo.mp4", type:"video/mp4", duration:5.56 }, michael@0: { name:"owl.mp3", type:"audio/mpeg", duration:3.29 }, michael@0: { name:"bogus.duh", type:"bogus/duh", duration:123 } michael@0: ]; michael@0: michael@0: var gFastSeekTests = [ michael@0: { name:"gizmo.mp4", type:"video/mp4", keyframes:[0, 1.0, 2.0, 3.0, 4.0, 5.0 ] }, michael@0: // Note: Not all keyframes in the file are actually referenced in the Cues in this file. michael@0: { name:"seek.webm", type:"video/webm", keyframes:[0, 0.8, 1.6, 2.4, 3.2]}, michael@0: // Note: the sync points are the points on both the audio and video streams michael@0: // before the keyframes. You can't just assume that the keyframes are the sync michael@0: // points, as the audio required for that sync point may be before the keyframe. michael@0: { name:"bug516323.indexed.ogv", type:"video/ogg", keyframes:[0, 0.46, 3.06] }, michael@0: ]; michael@0: michael@0: function IsWindows8OrLater() { michael@0: var re = /Windows NT (\d.\d)/; michael@0: var winver = navigator.userAgent.match(re); michael@0: return winver && winver.length == 2 && parseFloat(winver[1]) >= 6.2; michael@0: } michael@0: michael@0: // These are files that are non seekable, due to problems with the media, michael@0: // for example broken or missing indexes. michael@0: var gUnseekableTests = [ michael@0: { name:"no-cues.webm", type:"video/webm" }, michael@0: { name:"bogus.duh", type:"bogus/duh"} michael@0: ]; michael@0: // Unfortunately big-buck-bunny-unseekable.mp4 is doesn't play on Windows 7, so michael@0: // only include it in the unseekable tests if we're on later versions of Windows. michael@0: // This test actually only passes on win8 at the moment. michael@0: if (navigator.userAgent.indexOf("Windows") != -1 && IsWindows8OrLater()) { michael@0: gUnseekableTests = gUnseekableTests.concat([ michael@0: { name:"big-buck-bunny-unseekable.mp4", type:"video/mp4" } michael@0: ]); michael@0: } michael@0: // Android supports fragmented MP4 playback from 4.3. michael@0: var androidVersion = SpecialPowers.Cc['@mozilla.org/system-info;1'] michael@0: .getService(SpecialPowers.Ci.nsIPropertyBag2) michael@0: .getProperty('version'); michael@0: // Fragmented MP4. michael@0: if (navigator.userAgent.indexOf("Mobile") != -1 && androidVersion >= 18) { michael@0: gUnseekableTests = gUnseekableTests.concat([ michael@0: { name:"street.mp4", type:"video/mp4" } michael@0: ]); michael@0: } michael@0: michael@0: // These are files suitable for using with a "new Audio" constructor. michael@0: var gAudioTests = [ michael@0: { name:"r11025_s16_c1.wav", type:"audio/x-wav", duration:1.0 }, michael@0: { name:"sound.ogg", type:"audio/ogg" }, michael@0: { name:"owl.mp3", type:"audio/mpeg", duration:3.29 }, michael@0: { name:"small-shot.m4a", type:"audio/mp4", duration:0.29 }, michael@0: { name:"bogus.duh", type:"bogus/duh", duration:123 } michael@0: ]; michael@0: michael@0: // These files ensure our handling of 404 errors is consistent across the michael@0: // various backends. michael@0: var g404Tests = [ michael@0: { name:"404.wav", type:"audio/x-wav" }, michael@0: { name:"404.ogv", type:"video/ogg" }, michael@0: { name:"404.oga", type:"audio/ogg" }, michael@0: { name:"404.webm", type:"video/webm" }, michael@0: { name:"bogus.duh", type:"bogus/duh" } michael@0: ]; michael@0: michael@0: // These are files suitable for testing various decoder failures that are michael@0: // expected to fire MEDIA_ERR_DECODE. Used by test_decode_error, which expects michael@0: // an error and emptied event, and no loadedmetadata or ended event. michael@0: var gDecodeErrorTests = [ michael@0: // Valid files with unsupported codecs michael@0: { name:"r11025_msadpcm_c1.wav", type:"audio/x-wav" }, michael@0: { name:"dirac.ogg", type:"video/ogg" }, michael@0: // Invalid files michael@0: { name:"bogus.wav", type:"audio/x-wav" }, michael@0: { name:"bogus.ogv", type:"video/ogg" }, michael@0: michael@0: { name:"bogus.duh", type:"bogus/duh" } michael@0: ]; michael@0: michael@0: // These are files that are used for media fragments tests michael@0: var gFragmentTests = [ michael@0: { name:"big.wav", type:"audio/x-wav", duration:9.278981, size:102444 } michael@0: ]; michael@0: michael@0: // Used by test_chaining.html. The |links| attributes is the number of links in michael@0: // this file that we should be able to play. michael@0: var gChainingTests = [ michael@0: // Vorbis and Opus chained file. They have user comments |index=n| where `n` michael@0: // is the index of this segment in the file, 0 indexed. michael@0: { name:"chain.ogg", type:"audio/ogg", links: 4}, michael@0: { name:"chain.opus", type:"audio/ogg; codec=opus", links: 4}, michael@0: // Those files are chained files with a different number of channels in each michael@0: // part. This is not supported and should stop playing after the first part. michael@0: { name:"variable-channel.ogg", type:"audio/ogg", links: 1 }, michael@0: { name:"variable-channel.opus", type:"audio/ogg; codec=opus", links: 1 }, michael@0: // Those files are chained files with a different sample rate in each michael@0: // part. This is not supported and should stop playing after the first part. michael@0: { name:"variable-samplerate.ogg", type:"audio/ogg", links: 1 }, michael@0: // Opus decoding in Firefox outputs 48 kHz PCM despite having a different michael@0: // original sample rate, so we can safely play Opus chained media that have michael@0: // different samplerate accross links. michael@0: { name:"variable-samplerate.opus", type:"audio/ogg; codec=opus", links: 2 }, michael@0: // A chained video file. We don't support those, so only one link should be michael@0: // reported. michael@0: { name:"chained-video.ogv", type:"video/ogg", links: 1 }, michael@0: // A file that consist in 4 links of audio, then another link that has video. michael@0: // We should stop right after the 4 audio links. michael@0: { name:"chained-audio-video.ogg", type:"video/ogg", links: 4 }, michael@0: // An opus file that has two links, with a different preskip value for each michael@0: // link. We should be able to play both links. michael@0: { name:"variable-preskip.opus", type:"audio/ogg; codec=opus", links: 2 }, michael@0: { name:"bogus.duh", type:"bogus/duh" } michael@0: ]; michael@0: michael@0: // Videos with an aspect ratio. Used for testing that displaying frames michael@0: // on a canvas works correctly in the case of non-standard aspect ratios. michael@0: // See bug 874897 for an example. michael@0: var gAspectRatioTests = [ michael@0: { name:"VID_0001.ogg", type:"video/ogg", duration:19.966 } michael@0: ]; michael@0: michael@0: // These are files with non-trivial tag sets. michael@0: // Used by test_metadata.html. michael@0: var gMetadataTests = [ michael@0: // Ogg Vorbis files michael@0: { name:"short-video.ogv", tags: { michael@0: TITLE:"Lepidoptera", michael@0: ARTIST:"Epoq", michael@0: ALBUM:"Kahvi Collective", michael@0: DATE:"2002", michael@0: COMMENT:"http://www.kahvi.org", michael@0: } michael@0: }, michael@0: { name:"bug516323.ogv", tags: { michael@0: GENRE:"Open Movie", michael@0: ENCODER:"Audacity", michael@0: TITLE:"Elephants Dream", michael@0: ARTIST:"Silvia Pfeiffer", michael@0: COMMENTS:"Audio Description" michael@0: } michael@0: }, michael@0: { name:"bug516323.indexed.ogv", tags: { michael@0: GENRE:"Open Movie", michael@0: ENCODER:"Audacity", michael@0: TITLE:"Elephants Dream", michael@0: ARTIST:"Silvia Pfeiffer", michael@0: COMMENTS:"Audio Description" michael@0: } michael@0: }, michael@0: { name:"detodos.opus", tags: { michael@0: title:"De todos. Para todos.", michael@0: artist:"Mozilla.org" michael@0: } michael@0: }, michael@0: { name:"sound.ogg", tags: { } }, michael@0: { name:"small-shot.ogg", tags: { michael@0: title:"Pew SFX" michael@0: } michael@0: }, michael@0: { name:"badtags.ogg", tags: { michael@0: // We list only the valid tags here, and verify michael@0: // the invalid ones are filtered out. michael@0: title:"Invalid comments test file", michael@0: empty:"", michael@0: "":"empty", michael@0: "{- [(`!@\"#$%^&')] -}":"valid tag name, surprisingly" michael@0: // The file also includes the following invalid tags. michael@0: // "A description with no separator is a common problem.", michael@0: // "雨":"Likely, but an invalid key (non-ascii).", michael@0: // "not\nval\x1fid":"invalid tag name", michael@0: // "not~valid":"this isn't a valid name either", michael@0: // "not-utf-8":"invalid sequences: \xff\xfe\xfa\xfb\0eol" michael@0: } michael@0: }, michael@0: { name:"wave_metadata.wav", tags: { michael@0: name:"Track Title", michael@0: artist:"Artist Name", michael@0: comments:"Comments", michael@0: } michael@0: }, michael@0: { name:"wave_metadata_utf8.wav", tags: { michael@0: name:"歌曲名稱", michael@0: artist:"作曲者", michael@0: comments:"註解", michael@0: } michael@0: }, michael@0: { name:"wave_metadata_unknown_tag.wav", tags: { michael@0: name:"Track Title", michael@0: comments:"Comments", michael@0: } michael@0: }, michael@0: { name:"wave_metadata_bad_len.wav", tags: { michael@0: name:"Track Title", michael@0: artist:"Artist Name", michael@0: } michael@0: }, michael@0: { name:"wave_metadata_bad_no_null.wav", tags: { michael@0: name:"Track Title", michael@0: artist:"Artist Name", michael@0: comments:"Comments!!", michael@0: } michael@0: }, michael@0: { name:"wave_metadata_bad_utf8.wav", tags: { michael@0: name:"歌曲名稱", michael@0: comments:"註解", michael@0: } michael@0: }, michael@0: { name:"wavedata_u8.wav", tags: { } michael@0: }, michael@0: ]; michael@0: michael@0: function checkMetadata(msg, e, test) { michael@0: if (test.width) { michael@0: is(e.videoWidth, test.width, msg + " video width"); michael@0: } michael@0: if (test.height) { michael@0: is(e.videoHeight, test.height, msg + " video height"); michael@0: } michael@0: if (test.duration) { michael@0: ok(Math.abs(e.duration - test.duration) < 0.1, michael@0: msg + " duration (" + e.duration + ") should be around " + test.duration); michael@0: } michael@0: } michael@0: michael@0: // Returns the first test from candidates array which we can play with the michael@0: // installed video backends. michael@0: function getPlayableVideo(candidates) { michael@0: var v = document.createElement("video"); michael@0: var resources = candidates.filter(function(x){return /^video/.test(x.type) && v.canPlayType(x.type);}); michael@0: if (resources.length > 0) michael@0: return resources[0]; michael@0: return null; michael@0: } michael@0: michael@0: function getPlayableAudio(candidates) { michael@0: var v = document.createElement("audio"); michael@0: var resources = candidates.filter(function(x){return /^audio/.test(x.type) && v.canPlayType(x.type);}); michael@0: if (resources.length > 0) michael@0: return resources[0]; michael@0: return null; michael@0: } michael@0: michael@0: // Returns the type of element that should be created for the given mimetype. michael@0: function getMajorMimeType(mimetype) { michael@0: if (/^video/.test(mimetype)) { michael@0: return "video"; michael@0: } else { michael@0: return "audio"; michael@0: } michael@0: } michael@0: michael@0: function removeNodeAndSource(n) { michael@0: n.remove(); michael@0: // force release of underlying decoder michael@0: n.src = ""; michael@0: while (n.firstChild) { michael@0: n.removeChild(n.firstChild); michael@0: } michael@0: } michael@0: michael@0: // Number of tests to run in parallel. Warning: Each media element requires michael@0: // at least 3 threads (4 on Linux), and on Linux each thread uses 10MB of michael@0: // virtual address space. Beware! michael@0: var PARALLEL_TESTS = 2; michael@0: michael@0: // When true, we'll loop forever on whatever test we run. Use this to debug michael@0: // intermittent test failures. michael@0: const DEBUG_TEST_LOOP_FOREVER = false; michael@0: michael@0: // Manages a run of media tests. Runs them in chunks in order to limit michael@0: // the number of media elements/threads running in parallel. This limits peak michael@0: // memory use, particularly on Linux x86 where thread stacks use 10MB of michael@0: // virtual address space. michael@0: // Usage: michael@0: // 1. Create a new MediaTestManager object. michael@0: // 2. Create a test startTest function. This takes a test object and a token, michael@0: // and performs anything necessary to start the test. The test object is an michael@0: // element in one of the g*Tests above. Your startTest function must call michael@0: // MediaTestManager.start(token) if it starts a test. The test object is michael@0: // guaranteed to be playable by our supported decoders; you don't need to michael@0: // check canPlayType. michael@0: // 3. When your tests finishes, call MediaTestManager.finished(), passing michael@0: // the token back to the manager. The manager may either start the next run michael@0: // or end the mochitest if all the tests are done. michael@0: function MediaTestManager() { michael@0: michael@0: // Sets up a MediaTestManager to runs through the 'tests' array, which needs michael@0: // to be one of, or have the same fields as, the g*Test arrays of tests. Uses michael@0: // the user supplied 'startTest' function to initialize the test. This michael@0: // function must accept two arguments, the test entry from the 'tests' array, michael@0: // and a token. Call MediaTestManager.started(token) if you start the test, michael@0: // and MediaTestManager.finished(token) when the test finishes. You don't have michael@0: // to start every test, but if you call started() you *must* call finish() michael@0: // else you'll timeout. michael@0: this.runTests = function(tests, startTest) { michael@0: this.startTime = new Date(); michael@0: SimpleTest.info("Started " + this.startTime + " (" + this.startTime.getTime()/1000 + "s)"); michael@0: this.testNum = 0; michael@0: this.tests = tests; michael@0: this.startTest = startTest; michael@0: this.tokens = []; michael@0: this.isShutdown = false; michael@0: this.numTestsRunning = 0; michael@0: // Always wait for explicit finish. michael@0: SimpleTest.waitForExplicitFinish(); michael@0: this.nextTest(); michael@0: } michael@0: michael@0: // Registers that the test corresponding to 'token' has been started. michael@0: // Don't call more than once per token. michael@0: this.started = function(token) { michael@0: this.tokens.push(token); michael@0: this.numTestsRunning++; michael@0: is(this.numTestsRunning, this.tokens.length, "[started " + token + "] Length of array should match number of running tests"); michael@0: } michael@0: michael@0: // Registers that the test corresponding to 'token' has finished. Call when michael@0: // you've finished your test. If all tests are complete this will finish the michael@0: // run, otherwise it may start up the next run. It's ok to call multiple times michael@0: // per token. michael@0: this.finished = function(token) { michael@0: var i = this.tokens.indexOf(token); michael@0: if (i != -1) { michael@0: // Remove the element from the list of running tests. michael@0: this.tokens.splice(i, 1); michael@0: } michael@0: this.numTestsRunning--; michael@0: is(this.numTestsRunning, this.tokens.length, "[finished " + token + "] Length of array should match number of running tests"); michael@0: if (this.tokens.length < PARALLEL_TESTS) { michael@0: this.nextTest(); michael@0: } michael@0: } michael@0: michael@0: // Starts the next batch of tests, or finishes if they're all done. michael@0: // Don't call this directly, call finished(token) when you're done. michael@0: this.nextTest = function() { michael@0: // Force an exact GC after every completed testcase. This ensures that any michael@0: // decoders with live threads waiting for the GC are killed promptly, to free michael@0: // up the thread stacks' address space, and destroy decoder resources. michael@0: SpecialPowers.exactGC(window, function(){ michael@0: while (this.testNum < this.tests.length && this.tokens.length < PARALLEL_TESTS) { michael@0: var test = this.tests[this.testNum]; michael@0: var token = (test.name ? (test.name + "-"): "") + this.testNum; michael@0: this.testNum++; michael@0: michael@0: if (DEBUG_TEST_LOOP_FOREVER && this.testNum == this.tests.length) { michael@0: this.testNum = 0; michael@0: } michael@0: michael@0: // Ensure we can play the resource type. michael@0: if (test.type && !document.createElement('video').canPlayType(test.type)) michael@0: continue; michael@0: michael@0: // Do the init. This should start the test. michael@0: this.startTest(test, token); michael@0: } michael@0: michael@0: if (this.testNum == this.tests.length && michael@0: !DEBUG_TEST_LOOP_FOREVER && michael@0: this.tokens.length == 0 && michael@0: !this.isShutdown) michael@0: { michael@0: this.isShutdown = true; michael@0: if (this.onFinished) { michael@0: this.onFinished(); michael@0: } michael@0: mediaTestCleanup(); michael@0: var end = new Date(); michael@0: SimpleTest.info("Finished at " + end + " (" + (end.getTime() / 1000) + "s)"); michael@0: SimpleTest.info("Running time: " + (end.getTime() - this.startTime.getTime())/1000 + "s"); michael@0: SimpleTest.finish(); michael@0: return; michael@0: } michael@0: }.bind(this)); michael@0: } michael@0: } michael@0: michael@0: // Ensures we've got no active video or audio elements in the document, and michael@0: // forces a GC to release the address space reserved by the decoders' threads' michael@0: // stacks. michael@0: function mediaTestCleanup() { michael@0: var V = document.getElementsByTagName("video"); michael@0: for (i=0; i