DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (409f3966645a)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
<!DOCTYPE HTML>
<html>
<head>
  <title>Test MediaRecorder State Transition</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;

// List of operation tests for media recorder objects to verify if running
// these operations should result in an exception or not
var operationTests = [
  {
    operations: ['stop'],
    isValid: false
  },
  {
    operations: ['requestData'],
    isValid: false
  },
  {
    operations: ['pause'],
    isValid: false
  },
  {
    operations: ['resume'],
    isValid: false
  },
  {
    operations: ['start'],
    isValid: true
  },
  {
    operations: ['start'],
    isValid: true,
    timeSlice: 200
  },
  {
    operations: ['start', 'pause'],
    isValid: true
  },
  {
    operations: ['start', 'pause'],
    isValid: true,
    timeSlice: 200
  },
  {
    operations: ['start', 'start'],
    isValid: false
  },
  {
    operations: ['start', 'resume'],
    isValid: false
  },
  {
    operations: ['start', 'stop'],
    isValid: true
  },
  {
    operations: ['start', 'stop'],
    isValid: true,
    timeSlice: 200
  },
  {
    operations: ['start', 'requestData'],
    isValid: true
  },
  {
    operations: ['start', 'requestData'],
    isValid: true,
    timeSlice: 200
  },
  {
    operations: ['start', 'pause', 'stop'],
    isValid: true
  },
  {
    operations: ['start', 'pause', 'start'],
    isValid: false
  },
  {
    operations: ['start', 'pause', 'pause'],
    isValid: false
  },
  {
    operations: ['start', 'pause', 'requestData'],
    isValid: false
  },
  {
    operations: ['start', 'pause', 'resume'],
    isValid: true
  },
  {
    operations: ['start', 'pause', 'resume'],
    isValid: true,
    timeSlice: 200
  }
];

/**
 * Runs through each available state transition test by running all
 * available operations on a media recorder object. Then, we report
 * back if the test was expected through an exception or not.
 *
 * @param {MediaStream} testStream the media stream used for media recorder
 *                                 operation tests
 */
function runStateTransitionTests(testStream) {
  for (operationTest of operationTests) {
    var mediaRecorder = new MediaRecorder(testStream);
    var operationsString = operationTest.operations.toString();

    try {
      for (operation of operationTest.operations) {
        if (operationTest.timeSlice && operation === 'start') {
          operationsString += ' with timeslice ' + operationTest.timeSlice;
          mediaRecorder[operation](operationTest.timeSlice);
        } else {
          mediaRecorder[operation]();
        }
      }

      if (operationTest.isValid) {
        ok(true, 'Successful transitions for ' + operationsString);
      } else {
        ok(false, 'Failed transitions for ' + operationsString);
      }
    } catch (err) {
      if (!operationTest.isValid && err.name === 'InvalidStateError') {
        ok(true, 'InvalidStateError fired for ' + operationsString);
      } else {
        ok(false, 'No InvalidStateError for ' + operationsString);
      }
    }
  }
}

/**
 * Starts a test on every media recorder file included to check that various
 * state transition flows that can happen in the media recorder object throw
 * exceptions when they are expected to and vice versa.
 */
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.mozCaptureStream();

  element.oncanplaythrough = function () {
    element.oncanplaythrough = null;
    runStateTransitionTests(element.stream);
    manager.finished(token);
  };

  element.play();
}

manager.runTests(gMediaRecorderTests, startTest);
</script>
</pre>
</body>
</html>