Bug 546700 - Recover gracefully from servers that send Accept-Ranges but don't. r=roc a=roc
authorMatthew Gregan <kinetik@flim.org>
Mon, 21 Feb 2011 16:38:29 +1300
changeset 62891 d30bc9781cfd23b7cd2dcb8720dd91863c098015
parent 62890 b5a403b079d3b8c65d37e912de81b7f53c5c2e89
child 62892 df4d35ffa99f3a787a2655fafe92aaf2311646a2
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersroc, roc
bugs546700
milestone2.0b12pre
Bug 546700 - Recover gracefully from servers that send Accept-Ranges but don't. r=roc a=roc
content/media/nsMediaStream.cpp
content/media/test/Makefile.in
content/media/test/seekLies.sjs
content/media/test/test_seekLies.html
--- a/content/media/nsMediaStream.cpp
+++ b/content/media/nsMediaStream.cpp
@@ -230,16 +230,19 @@ nsMediaChannelStream::OnStartRequest(nsI
     }
 
     if (mOffset > 0 && responseStatus == HTTP_OK_CODE) {
       // If we get an OK response but we were seeking, we have to assume
       // that seeking doesn't work. We also need to tell the cache that
       // it's getting data for the start of the stream.
       mCacheStream.NotifyDataStarted(0);
       mOffset = 0;
+
+      // The server claimed it supported range requests.  It lied.
+      acceptsRanges = PR_FALSE;
     } else if (mOffset == 0 &&
                (responseStatus == HTTP_OK_CODE ||
                 responseStatus == HTTP_PARTIAL_RESPONSE_CODE)) {
       // We weren't seeking and got a valid response status,
       // set the length of the content.
       PRInt32 cl = -1;
       hc->GetContentLength(&cl);
       if (cl >= 0) {
--- a/content/media/test/Makefile.in
+++ b/content/media/test/Makefile.in
@@ -86,16 +86,17 @@ include $(topsrcdir)/config/rules.mk
 		seek6.js \
 		seek7.js \
 		seek8.js \
 		seek9.js \
 		seek10.js \
 		seek11.js \
 		seek12.js \
 		seek13.js \
+		seekLies.sjs \
 		test_access_control.html \
 		test_audio1.html \
 		test_audio2.html \
 		test_autoplay.html \
 		test_autoplay_contentEditable.html \
 		test_buffered.html \
 		test_bug448534.html \
 		test_bug463162.xhtml \
@@ -130,16 +131,17 @@ include $(topsrcdir)/config/rules.mk
 		test_preload_actions.html \
 		test_preload_attribute.html \
 		test_progress.html \
 		test_reactivate.html \
 		test_readyState.html \
 		test_replay_metadata.html \
 		test_seek.html \
 		test_seek2.html \
+		test_seekLies.html \
 		test_seek_out_of_range.html \
 		test_source.html \
 		test_source_write.html \
 		test_standalone.html \
 		test_timeupdate_small_files.html \
 		test_volume.html \
 		test_video_to_canvas.html \
 		use_large_cache.js \
new file mode 100644
--- /dev/null
+++ b/content/media/test/seekLies.sjs
@@ -0,0 +1,23 @@
+function handleRequest(request, response)
+{
+  var file = Components.classes["@mozilla.org/file/directory_service;1"].
+                        getService(Components.interfaces.nsIProperties).
+                        get("CurWorkD", Components.interfaces.nsILocalFile);
+  var fis  = Components.classes['@mozilla.org/network/file-input-stream;1'].
+                        createInstance(Components.interfaces.nsIFileInputStream);
+  var bis  = Components.classes["@mozilla.org/binaryinputstream;1"].
+                        createInstance(Components.interfaces.nsIBinaryInputStream);
+  var paths = "tests/content/media/test/seek.ogv";
+  var split = paths.split("/");
+  for(var i = 0; i < split.length; ++i) {
+    file.append(split[i]);
+  }
+  fis.init(file, -1, -1, false);
+  bis.setInputStream(fis);
+  var bytes = bis.readBytes(bis.available());
+  response.setHeader("Content-Length", ""+bytes.length, false);
+  response.setHeader("Content-Type", "video/ogg", false);
+  response.setHeader("Accept-Ranges", "bytes", false);
+  response.write(bytes, bytes.length);
+  bis.close();
+}
new file mode 100644
--- /dev/null
+++ b/content/media/test/test_seekLies.html
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Media test: server lies about range requests</title>
+  <script type="text/javascript" src="/MochiKit/packed.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body onunload="mediaTestCleanup();">
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+function on_metadataloaded() {
+  var v = document.getElementById('v');
+  var d = Math.round(v.duration*1000);
+  ok(d == 3999, "Checking duration: " + d);
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+</script>
+</pre>
+<video id='v'
+       src='seekLies.sjs'
+       onloadedmetadata='on_metadataloaded();'></video>
+</body>
+</html>