author | Paul Adenot <paul@paul.cx> |
Wed, 13 Feb 2013 19:04:00 +0100 | |
changeset 122323 | b143a7fb7f396327fadfaabb68ec2eb7d8522b0f |
parent 122322 | a1534b828aa7b66666b09a622af4ae4564fc41fd |
child 122324 | a093423c5e5b642b142746d1f3f71728c236d0eb |
push id | 24336 |
push user | ryanvm@gmail.com |
push date | Wed, 20 Feb 2013 12:07:46 +0000 |
treeherder | mozilla-central@1bcc3c56b011 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | kinetik |
bugs | 835381 |
milestone | 21.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
new file mode 100644 index 0000000000000000000000000000000000000000..4618cda03239e688550786a758114e588d01ff21 GIT binary patch literal 512 zc$|}Ry}y`|0SuI#+8P<1z60^6Mi!^fjT}x*9l41mMft_qiB9c}OirzhOcKEj>0srI z$Gil6XO}qG`0nlwUfm+<xiT$yP2+vv-912_Sjf8U;5AK*E)cFz$l-J#m-&qE?p`2Q zCU`ecwwdvm;2WsTQy2yz0C@@OzDTX>8=Lu^9I97N3<+>@bn{jS^;XEsS12w`D)w#Y z^+_yCGd0mOHrF#WFbH=<<rgoRVDhMaYt^sR-<HmeSzmp(g}QWhIQ0Jjn+ysmh$T!l z>!7yPUT<V9KHA7Qr;$Nv>zwA)y!4Jn#<u>jc;5h5cN2ZjV1Iqb;DF{vM&-xNElf#K z3=g0hg*G&?GVE$%x)1_lgn(Gdi`E0<Y6DOK<JL}LAPH2)sK9Wfw}auV21}HPGXPBR BcTfNT
new file mode 100644 index 0000000000000000000000000000000000000000..7bc738b8b4e82a69c4856fe96fabfe3dae5d6858 GIT binary patch literal 512 zc$|}Ry}!8Msi~zrH7VDry^+bOwUJ38xFKEH^PHgX?2=W!ySsx|w}^VKObcGqs1M<Z zg{;d4@|Hn(GQqn+yo(?;pL`pZ=42)T&B`%SC^OKr)H7GmRsf3RCYBWC7iT9zMJ>V| z=jCQ6=cFd)DH!M(>6t2|73JqD_#~F4nF4v{dWOYIChX_x>FiazGbwq~R{fxA-8(Lw z9S-Xq7(l=!v4cfU%{hSa0|Ur0%hoNq-pE*dw2^U6BZJb`InAYcDQ&G`@nHcL&5eu? z+BY;YI_zrv0CMTs-94Kd8Me27Z)E(~#HhTxcXJc70+hQgc6Z<ACN_ud9UyKqV{|r% z&zS(_Gcn48_&g0T{t5+o=WV45NqNs385T!(HZm|YTqtLl%c$i5bQc3VM{8?GYfA@1 zll1+*=YP-NydZqA&iZ%#Bm0-vzrCM2yZ!6=o%2`iziIhl)%`8}x%-^|RsQJx*Zr*g z$NVq*@73r0i~HaHZ}-3Zcbxy+|E&M=e&@Zf_t)P0TEDV>{lC?3s(<ExvH$r0cJ0mj zmH(su?R~-gj`y$h&-NJox9uC<KdyfvZ~wp4{$c%zdaoaKf7Aax{#*U9|7&vC=?}8i R_49vi{_6kXeScl?4*<NT`>+52
new file mode 100644 --- /dev/null +++ b/toolkit/components/mediasniffer/test/unit/test_mediasniffer_webm.js @@ -0,0 +1,100 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const Ci = Components.interfaces; +const Cu = Components.utils; +const Cc = Components.classes; +const CC = Components.Constructor; + +var BinaryOutputStream = CC("@mozilla.org/binaryoutputstream;1", + "nsIBinaryOutputStream", + "setOutputStream"); + +Cu.import("resource://testing-common/httpd.js"); + +var httpserver = new HttpServer(); + +var testRan = 0; + +// The tests files we want to test, and the type we should have after sniffing. +// Those file are real webm and mkv files truncated to 512 bytes. +const tests = [ + { path: "data/file.webm", expected: "video/webm" }, + { path: "data/file.mkv", expected: "application/octet-stream" }, +]; + +// A basic listener that reads checks the if we sniffed properly. +var listener = { + onStartRequest: function(request, context) { + do_check_eq(request.QueryInterface(Ci.nsIChannel).contentType, tests[testRan].expected); + }, + + onDataAvailable: function(request, context, stream, offset, count) { + try { + var bis = Components.classes["@mozilla.org/binaryinputstream;1"] + .createInstance(Components.interfaces.nsIBinaryInputStream); + bis.setInputStream(stream); + var array = bis.readByteArray(bis.available()); + } catch (ex) { + do_throw("Error in onDataAvailable: " + ex); + } + }, + + onStopRequest: function(request, context, status) { + testRan++; + runNext(); + } +}; + +function setupChannel(url) { + var ios = Components.classes["@mozilla.org/network/io-service;1"]. + getService(Ci.nsIIOService); + var chan = ios.newChannel("http://localhost:4444" + url, "", null); + var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); + return httpChan; +} + +function runNext() { + if (testRan == tests.length) { + do_test_finished(); + return; + } + var channel = setupChannel("/"); + channel.asyncOpen(listener, channel, null); +} + +function getFileContents(aFile) { + const PR_RDONLY = 0x01; + var fileStream = Cc["@mozilla.org/network/file-input-stream;1"] + .createInstance(Ci.nsIFileInputStream); + fileStream.init(aFile, 1, -1, null); + var bis = Components.classes["@mozilla.org/binaryinputstream;1"] + .createInstance(Components.interfaces.nsIBinaryInputStream); + bis.setInputStream(fileStream); + + var data = bis.readByteArray(bis.available()); + + return data; +} + +function handler(metadata, response) { + response.setStatusLine(metadata.httpVersion, 200, "OK"); + // Send an empty Content-Type, so we are guaranteed to sniff. + response.setHeader("Content-Type", "", false); + var body = getFileContents(do_get_file(tests[testRan].path)); + var bos = new BinaryOutputStream(response.bodyOutputStream); + bos.writeByteArray(body, body.length); +} + +function run_test() { + // We use a custom handler so we can change the header to force sniffing. + httpserver.registerPathHandler("/", handler); + httpserver.start(4444); + do_test_pending(); + try { + runNext(); + } catch (e) { + print("ERROR - " + e + "\n"); + } +}