content/media/test/test_mediarecorder_state_transition.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test MediaRecorder State Transition</title>
     5   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     7   <script type="text/javascript" src="manifest.js"></script>
     8 </head>
     9 <body>
    10 <pre id="test">
    11 <script class="testbody" type="text/javascript">
    12 var manager = new MediaTestManager;
    14 // List of operation tests for media recorder objects to verify if running
    15 // these operations should result in an exception or not
    16 var operationTests = [
    17   {
    18     operations: ['stop'],
    19     isValid: false
    20   },
    21   {
    22     operations: ['requestData'],
    23     isValid: false
    24   },
    25   {
    26     operations: ['pause'],
    27     isValid: false
    28   },
    29   {
    30     operations: ['resume'],
    31     isValid: false
    32   },
    33   {
    34     operations: ['start'],
    35     isValid: true
    36   },
    37   {
    38     operations: ['start'],
    39     isValid: true,
    40     timeSlice: 200
    41   },
    42   {
    43     operations: ['start', 'pause'],
    44     isValid: true
    45   },
    46   {
    47     operations: ['start', 'pause'],
    48     isValid: true,
    49     timeSlice: 200
    50   },
    51   {
    52     operations: ['start', 'start'],
    53     isValid: false
    54   },
    55   {
    56     operations: ['start', 'resume'],
    57     isValid: false
    58   },
    59   {
    60     operations: ['start', 'stop'],
    61     isValid: true
    62   },
    63   {
    64     operations: ['start', 'stop'],
    65     isValid: true,
    66     timeSlice: 200
    67   },
    68   {
    69     operations: ['start', 'requestData'],
    70     isValid: true
    71   },
    72   {
    73     operations: ['start', 'requestData'],
    74     isValid: true,
    75     timeSlice: 200
    76   },
    77   {
    78     operations: ['start', 'pause', 'stop'],
    79     isValid: true
    80   },
    81   {
    82     operations: ['start', 'pause', 'start'],
    83     isValid: false
    84   },
    85   {
    86     operations: ['start', 'pause', 'pause'],
    87     isValid: false
    88   },
    89   {
    90     operations: ['start', 'pause', 'requestData'],
    91     isValid: false
    92   },
    93   {
    94     operations: ['start', 'pause', 'resume'],
    95     isValid: true
    96   },
    97   {
    98     operations: ['start', 'pause', 'resume'],
    99     isValid: true,
   100     timeSlice: 200
   101   }
   102 ];
   104 /**
   105  * Runs through each available state transition test by running all
   106  * available operations on a media recorder object. Then, we report
   107  * back if the test was expected through an exception or not.
   108  *
   109  * @param {MediaStream} testStream the media stream used for media recorder
   110  *                                 operation tests
   111  */
   112 function runStateTransitionTests(testStream) {
   113   for (operationTest of operationTests) {
   114     var mediaRecorder = new MediaRecorder(testStream);
   115     var operationsString = operationTest.operations.toString();
   117     try {
   118       for (operation of operationTest.operations) {
   119         if (operationTest.timeSlice && operation === 'start') {
   120           operationsString += ' with timeslice ' + operationTest.timeSlice;
   121           mediaRecorder[operation](operationTest.timeSlice);
   122         } else {
   123           mediaRecorder[operation]();
   124         }
   125       }
   127       if (operationTest.isValid) {
   128         ok(true, 'Successful transitions for ' + operationsString);
   129       } else {
   130         ok(false, 'Failed transitions for ' + operationsString);
   131       }
   132     } catch (err) {
   133       if (!operationTest.isValid && err.name === 'InvalidStateError') {
   134         ok(true, 'InvalidStateError fired for ' + operationsString);
   135       } else {
   136         ok(false, 'No InvalidStateError for ' + operationsString);
   137       }
   138     }
   139   }
   140 }
   142 /**
   143  * Starts a test on every media recorder file included to check that various
   144  * state transition flows that can happen in the media recorder object throw
   145  * exceptions when they are expected to and vice versa.
   146  */
   147 function startTest(test, token) {
   148   var element = document.createElement('audio');
   149   var expectedMimeType = test.type.substring(0, test.type.indexOf(';'));
   151   element.token = token;
   152   manager.started(token);
   154   element.src = test.name;
   155   element.test = test;
   156   element.stream = element.mozCaptureStream();
   158   element.oncanplaythrough = function () {
   159     element.oncanplaythrough = null;
   160     runStateTransitionTests(element.stream);
   161     manager.finished(token);
   162   };
   164   element.play();
   165 }
   167 manager.runTests(gMediaRecorderTests, startTest);
   168 </script>
   169 </pre>
   170 </body>
   171 </html>

mercurial