content/media/test/test_mediarecorder_state_transition.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/test/test_mediarecorder_state_transition.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,171 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test MediaRecorder State Transition</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +  <script type="text/javascript" src="manifest.js"></script>
    1.11 +</head>
    1.12 +<body>
    1.13 +<pre id="test">
    1.14 +<script class="testbody" type="text/javascript">
    1.15 +var manager = new MediaTestManager;
    1.16 +
    1.17 +// List of operation tests for media recorder objects to verify if running
    1.18 +// these operations should result in an exception or not
    1.19 +var operationTests = [
    1.20 +  {
    1.21 +    operations: ['stop'],
    1.22 +    isValid: false
    1.23 +  },
    1.24 +  {
    1.25 +    operations: ['requestData'],
    1.26 +    isValid: false
    1.27 +  },
    1.28 +  {
    1.29 +    operations: ['pause'],
    1.30 +    isValid: false
    1.31 +  },
    1.32 +  {
    1.33 +    operations: ['resume'],
    1.34 +    isValid: false
    1.35 +  },
    1.36 +  {
    1.37 +    operations: ['start'],
    1.38 +    isValid: true
    1.39 +  },
    1.40 +  {
    1.41 +    operations: ['start'],
    1.42 +    isValid: true,
    1.43 +    timeSlice: 200
    1.44 +  },
    1.45 +  {
    1.46 +    operations: ['start', 'pause'],
    1.47 +    isValid: true
    1.48 +  },
    1.49 +  {
    1.50 +    operations: ['start', 'pause'],
    1.51 +    isValid: true,
    1.52 +    timeSlice: 200
    1.53 +  },
    1.54 +  {
    1.55 +    operations: ['start', 'start'],
    1.56 +    isValid: false
    1.57 +  },
    1.58 +  {
    1.59 +    operations: ['start', 'resume'],
    1.60 +    isValid: false
    1.61 +  },
    1.62 +  {
    1.63 +    operations: ['start', 'stop'],
    1.64 +    isValid: true
    1.65 +  },
    1.66 +  {
    1.67 +    operations: ['start', 'stop'],
    1.68 +    isValid: true,
    1.69 +    timeSlice: 200
    1.70 +  },
    1.71 +  {
    1.72 +    operations: ['start', 'requestData'],
    1.73 +    isValid: true
    1.74 +  },
    1.75 +  {
    1.76 +    operations: ['start', 'requestData'],
    1.77 +    isValid: true,
    1.78 +    timeSlice: 200
    1.79 +  },
    1.80 +  {
    1.81 +    operations: ['start', 'pause', 'stop'],
    1.82 +    isValid: true
    1.83 +  },
    1.84 +  {
    1.85 +    operations: ['start', 'pause', 'start'],
    1.86 +    isValid: false
    1.87 +  },
    1.88 +  {
    1.89 +    operations: ['start', 'pause', 'pause'],
    1.90 +    isValid: false
    1.91 +  },
    1.92 +  {
    1.93 +    operations: ['start', 'pause', 'requestData'],
    1.94 +    isValid: false
    1.95 +  },
    1.96 +  {
    1.97 +    operations: ['start', 'pause', 'resume'],
    1.98 +    isValid: true
    1.99 +  },
   1.100 +  {
   1.101 +    operations: ['start', 'pause', 'resume'],
   1.102 +    isValid: true,
   1.103 +    timeSlice: 200
   1.104 +  }
   1.105 +];
   1.106 +
   1.107 +/**
   1.108 + * Runs through each available state transition test by running all
   1.109 + * available operations on a media recorder object. Then, we report
   1.110 + * back if the test was expected through an exception or not.
   1.111 + *
   1.112 + * @param {MediaStream} testStream the media stream used for media recorder
   1.113 + *                                 operation tests
   1.114 + */
   1.115 +function runStateTransitionTests(testStream) {
   1.116 +  for (operationTest of operationTests) {
   1.117 +    var mediaRecorder = new MediaRecorder(testStream);
   1.118 +    var operationsString = operationTest.operations.toString();
   1.119 +
   1.120 +    try {
   1.121 +      for (operation of operationTest.operations) {
   1.122 +        if (operationTest.timeSlice && operation === 'start') {
   1.123 +          operationsString += ' with timeslice ' + operationTest.timeSlice;
   1.124 +          mediaRecorder[operation](operationTest.timeSlice);
   1.125 +        } else {
   1.126 +          mediaRecorder[operation]();
   1.127 +        }
   1.128 +      }
   1.129 +
   1.130 +      if (operationTest.isValid) {
   1.131 +        ok(true, 'Successful transitions for ' + operationsString);
   1.132 +      } else {
   1.133 +        ok(false, 'Failed transitions for ' + operationsString);
   1.134 +      }
   1.135 +    } catch (err) {
   1.136 +      if (!operationTest.isValid && err.name === 'InvalidStateError') {
   1.137 +        ok(true, 'InvalidStateError fired for ' + operationsString);
   1.138 +      } else {
   1.139 +        ok(false, 'No InvalidStateError for ' + operationsString);
   1.140 +      }
   1.141 +    }
   1.142 +  }
   1.143 +}
   1.144 +
   1.145 +/**
   1.146 + * Starts a test on every media recorder file included to check that various
   1.147 + * state transition flows that can happen in the media recorder object throw
   1.148 + * exceptions when they are expected to and vice versa.
   1.149 + */
   1.150 +function startTest(test, token) {
   1.151 +  var element = document.createElement('audio');
   1.152 +  var expectedMimeType = test.type.substring(0, test.type.indexOf(';'));
   1.153 +
   1.154 +  element.token = token;
   1.155 +  manager.started(token);
   1.156 +
   1.157 +  element.src = test.name;
   1.158 +  element.test = test;
   1.159 +  element.stream = element.mozCaptureStream();
   1.160 +
   1.161 +  element.oncanplaythrough = function () {
   1.162 +    element.oncanplaythrough = null;
   1.163 +    runStateTransitionTests(element.stream);
   1.164 +    manager.finished(token);
   1.165 +  };
   1.166 +
   1.167 +  element.play();
   1.168 +}
   1.169 +
   1.170 +manager.runTests(gMediaRecorderTests, startTest);
   1.171 +</script>
   1.172 +</pre>
   1.173 +</body>
   1.174 +</html>

mercurial