Bug 899935 - Mochitest for stopping the recorder right after starting it. r=jsmith
authorShelly Lin <slin@mozilla.com>
Tue, 06 Aug 2013 22:13:37 -0700
changeset 145038 af09edead9b84d7c8dba0bfe5c5f0cd06c26bda8
parent 145037 b3668dd7f9550e71bed652f40aaca398ac3d6483
child 145039 5f2ab76773e0be54a233af1efb77353de064403d
push id623
push userryanvm@gmail.com
push dateFri, 30 Aug 2013 12:07:31 +0000
treeherderb2g-inbound@5f2ab76773e0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsmith
bugs899935
milestone26.0a1
Bug 899935 - Mochitest for stopping the recorder right after starting it. r=jsmith
content/media/test/Makefile.in
content/media/test/test_mediarecorder_record_immediate_stop.html
--- a/content/media/test/Makefile.in
+++ b/content/media/test/Makefile.in
@@ -122,16 +122,17 @@ MOCHITEST_FILES = \
 		test_mozHasAudio.html \
 		test_source_media.html \
 		test_autoplay_contentEditable.html \
 		test_bug448534.html \
 		test_bug463162.xhtml \
 		test_decoder_disable.html \
 		test_mediarecorder_record_no_timeslice.html \
 		test_mediarecorder_reload_crash.html \
+		test_mediarecorder_record_immediate_stop.html \
 		test_media_selection.html \
 		test_playback.html \
 		test_seekLies.html \
 		test_media_sniffer.html \
 		contentType.sjs \
 		test_streams_srcObject.html \
 		test_reset_src.html \
 		test_streams_autoplay.html \
new file mode 100644
--- /dev/null
+++ b/content/media/test/test_mediarecorder_record_immediate_stop.html
@@ -0,0 +1,113 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test MediaRecorder Immediate Stop</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <script type="text/javascript" src="manifest.js"></script>
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+var manager = new MediaTestManager;
+
+/**
+ * Stops the media recorder immediately after starting the recorder. This test
+ * verifies whether the media recorder can handle this scenario nicely. The
+ * return blob size should be greater than zero, but its duration would be zero
+ * length when play.
+ */
+function startTest(test, token) {
+  var element = document.createElement('audio');
+  var expectedMimeType = test.type.substring(0, test.type.indexOf(';'));
+
+  element.token = token;
+  manager.started(token);
+
+  element.src = test.name;
+  element.test = test;
+  element.stream = element.mozCaptureStreamUntilEnded();
+
+  var mediaRecorder = new MediaRecorder(element.stream);
+  var onStopFired = false;
+  var onDataAvailableFired = false;
+
+  mediaRecorder.onerror = function () {
+    ok(false, 'Unexpected onerror callback fired');
+  };
+
+  mediaRecorder.onwarning = function () {
+    ok(false, 'Unexpected onwarning callback fired');
+  };
+
+  // This handler verifies that only a single onstop event handler is fired.
+  mediaRecorder.onstop = function () {
+    if (onStopFired) {
+      ok(false, 'onstop unexpectedly fired more than once');
+    } else {
+      onStopFired = true;
+
+      // ondataavailable should always fire before onstop
+      if (onDataAvailableFired) {
+        manager.finished(token);
+      } else {
+        ok(false, 'onstop fired without an ondataavailable event first');
+      }
+    }
+  };
+
+  // This handler verifies that only a single ondataavailable event handler
+  // is fired with the blob generated having greater than zero size
+  // and a correct mime type.
+  mediaRecorder.ondataavailable = function (evt) {
+    if (onDataAvailableFired) {
+        ok(false, 'ondataavailable unexpectedly fired more than once');
+    } else {
+      onDataAvailableFired = true;
+
+      ok(evt instanceof BlobEvent,
+         'Events fired from ondataavailable should be BlobEvent');
+      is(evt.type, 'dataavailable',
+         'Event type should dataavailable');
+      ok(evt.data.size > 0,
+         'Blob data received should be greater than zero');
+      is(evt.data.type, expectedMimeType,
+         'Blob data received should have type = ' + expectedMimeType);
+
+      is(mediaRecorder.mimeType, expectedMimeType,
+         'Mime type in ondataavailable = ' + expectedMimeType);
+
+      // onstop should not have fired before ondataavailable
+      if (onStopFired) {
+        ok(false, 'ondataavailable unexpectedly fired later than onstop');
+        manager.finished(token);
+      }
+    }
+  };
+
+  // This handler completes a start and stop of recording and verifies
+  // respective media recorder state.
+  var canPlayThrough = function() {
+    element.removeEventListener('canplaythrough', canPlayThrough, false);
+
+    mediaRecorder.start();
+    is(mediaRecorder.state, 'recording', 'Media recorder should be recording');
+    is(mediaRecorder.stream, element.stream,
+       'Media recorder stream = element stream at the start of recording');
+
+    mediaRecorder.stop();
+    is(mediaRecorder.state, 'inactive',
+       'Media recorder is inactive after being stopped');
+    is(mediaRecorder.stream, element.stream,
+       'Media recorder stream = element stream post recording');
+  };
+
+  element.addEventListener('canplaythrough', canPlayThrough, false);
+  element.play();
+}
+
+manager.runTests(gMediaRecorderTests, startTest);
+</script>
+</pre>
+</body>
+</html>