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