Bug 454683 - Media element setVolume should fail on invalid values; r+sr=roc
authorChris Pearce <chris@pearce.org.nz>
Mon, 29 Sep 2008 00:28:26 +0200
changeset 19859 62b670248ab799fd8816bc2fb39a45a881f65e66
parent 19858 ce3fd20cce9fc718deed140d2b21525a31c45e47
child 19860 ad3074e580096ffd6a8cb29b1e91effeee176fd6
push id2498
push usersgautherie.bz@free.fr
push dateSun, 28 Sep 2008 22:28:42 +0000
treeherdermozilla-central@62b670248ab7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs454683
milestone1.9.1b1pre
Bug 454683 - Media element setVolume should fail on invalid values; r+sr=roc
content/html/content/src/nsHTMLMediaElement.cpp
content/media/video/test/Makefile.in
content/media/video/test/test_volume.html
--- a/content/html/content/src/nsHTMLMediaElement.cpp
+++ b/content/html/content/src/nsHTMLMediaElement.cpp
@@ -345,16 +345,19 @@ NS_IMETHODIMP nsHTMLMediaElement::GetVol
     *aVolume = mMutedVolume;
   else
     *aVolume = mDecoder ? mDecoder->GetVolume() : 0.0;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsHTMLMediaElement::SetVolume(float aVolume)
 {
+  if (aVolume < 0.0f || aVolume > 1.0f)
+    return NS_ERROR_DOM_INDEX_SIZE_ERR;
+
   if (mMuted) 
     mMutedVolume = aVolume;
   else {
     if (mDecoder)
       mDecoder->SetVolume(aVolume);
 
     DispatchSimpleEvent(NS_LITERAL_STRING("volumechange"));
   }
--- a/content/media/video/test/Makefile.in
+++ b/content/media/video/test/Makefile.in
@@ -48,14 +48,15 @@ include $(topsrcdir)/config/rules.mk
                 test_controls.html \
                 test_currentTime.html \
                 test_defaultPlaybackRate.html \
                 test_networkState.html \
                 test_paused.html \
                 test_playbackRate.html \
                 test_readyState.html \
                 test_start.html \
+                test_volume.html \
 #               test_bug448534.html \
                 320x240.ogg \
                 $(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/content/media/video/test/test_volume.html
@@ -0,0 +1,40 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Media test: volume attribute set</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.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>
+
+<video id='v1'></video><audio id='a1'></audio>
+
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+function test(element, value, shouldThrow) {
+  var threw = false;
+  try {
+    element.volume = value;
+  } catch (err if err == "NS_ERROR_DOM_INDEX_SIZE_ERR") {
+    threw = true;
+  }
+  is(shouldThrow, threw, "Case: " +element.id+ " setVolume=" + value);
+}
+
+
+var ids = new Array(document.getElementById('v1'), document.getElementById('a1'));
+
+for (i=0; i<ids.length; i++) {
+  var element = ids[i];
+  test(element, 0.0,false);
+  test(element, 1.0, false);
+  test(element, -0.1, true);
+  test(element, 1.1, true);
+}  
+ 
+</script>
+</pre>
+</body>
+</html>