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 for multiple calls to mozCameras.getCamera()</title> |
michael@0 | 5 | <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <video id="viewfinder" width="200" height="200" autoplay></video> |
michael@0 | 11 | <img src="#" alt="This image is going to load" id="testimage"/> |
michael@0 | 12 | <script class="testbody" type="text/javascript;version=1.7"> |
michael@0 | 13 | |
michael@0 | 14 | var whichCamera = navigator.mozCameras.getListOfCameras()[0]; |
michael@0 | 15 | var options = { |
michael@0 | 16 | mode: 'picture', |
michael@0 | 17 | recorderProfile: 'cif', |
michael@0 | 18 | previewSize: { |
michael@0 | 19 | width: 352, |
michael@0 | 20 | height: 288 |
michael@0 | 21 | } |
michael@0 | 22 | }; |
michael@0 | 23 | |
michael@0 | 24 | function onError(e) { |
michael@0 | 25 | ok(false, "Error" + JSON.stringify(e)); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | var Camera = { |
michael@0 | 29 | cameraObj: null, |
michael@0 | 30 | get viewfinder() { |
michael@0 | 31 | return document.getElementById('viewfinder'); |
michael@0 | 32 | }, |
michael@0 | 33 | onReady: function take_two() { |
michael@0 | 34 | function onSuccess(camera, config) { |
michael@0 | 35 | ok(false, "Unexpectedly got second camera instance: " + config.toSource); |
michael@0 | 36 | } |
michael@0 | 37 | function onFailure(error) { |
michael@0 | 38 | ok(true, "Correctly failed to get camera again"); |
michael@0 | 39 | SimpleTest.finish(); |
michael@0 | 40 | } |
michael@0 | 41 | navigator.mozCameras.getCamera(whichCamera, options, onSuccess, onFailure); |
michael@0 | 42 | }, |
michael@0 | 43 | release: function release() { |
michael@0 | 44 | cameraObj = null; |
michael@0 | 45 | }, |
michael@0 | 46 | start: function run_test() { |
michael@0 | 47 | function onSuccess(camera, config) { |
michael@0 | 48 | Camera.cameraObj = camera; |
michael@0 | 49 | Camera.viewfinder.mozSrcObject = camera; |
michael@0 | 50 | Camera.viewfinder.play(); |
michael@0 | 51 | Camera.cameraObj.onPreviewStateChange = function(state) { |
michael@0 | 52 | if (state === 'started') { |
michael@0 | 53 | ok(true, "viewfinder is ready and playing"); |
michael@0 | 54 | Camera.cameraObj.onPreviewStateChange = null; |
michael@0 | 55 | Camera.onReady(); |
michael@0 | 56 | } |
michael@0 | 57 | }; |
michael@0 | 58 | }; |
michael@0 | 59 | navigator.mozCameras.getCamera(whichCamera, options, onSuccess, onError); |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 64 | |
michael@0 | 65 | window.addEventListener('beforeunload', function() { |
michael@0 | 66 | Camera.viewfinder.mozSrcObject = null; |
michael@0 | 67 | Camera.cameraObj.release(); |
michael@0 | 68 | Camera.cameraObj = null; |
michael@0 | 69 | }); |
michael@0 | 70 | |
michael@0 | 71 | Camera.start(); |
michael@0 | 72 | |
michael@0 | 73 | </script> |
michael@0 | 74 | </body> |
michael@0 | 75 | |
michael@0 | 76 | </html> |