dom/camera/test/test_bug975472.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/camera/test/test_bug975472.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,222 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test for bug 975472</title>
     1.8 +  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +</head>
    1.12 +<body>
    1.13 +<video id="viewfinder" width="200" height="200" autoplay></video>
    1.14 +<img src="#" alt="This image is going to load" id="testimage"/>
    1.15 +<script class="testbody" type="text/javascript;version=1.7">
    1.16 +
    1.17 +var whichCamera = navigator.mozCameras.getListOfCameras()[0];
    1.18 +var config = {
    1.19 +  mode: 'picture',
    1.20 +  recorderProfile: 'cif',
    1.21 +  previewSize: {
    1.22 +    width: 352,
    1.23 +    height: 288
    1.24 +  }
    1.25 +};
    1.26 +var options = {
    1.27 +  rotation: 0,
    1.28 +  position: {
    1.29 +    latitude: 43.645687,
    1.30 +    longitude: -79.393661
    1.31 +  },
    1.32 +  dateTime: Date.now()
    1.33 +};
    1.34 +
    1.35 +function onError(e) {
    1.36 +  ok(false, "Error" + JSON.stringify(e));
    1.37 +}
    1.38 +function next() {
    1.39 +  Camera.nextTest();
    1.40 +}
    1.41 +
    1.42 +// The array of tests
    1.43 +var tests = [
    1.44 +  {
    1.45 +    key: "release-after-release",
    1.46 +    func: function testAutoFocus(camera) {
    1.47 +      function onSuccess(success) {
    1.48 +        ok(true, "release() succeeded");
    1.49 +        next();
    1.50 +      }
    1.51 +      function onError(error) {
    1.52 +        ok(false, "release() failed with: " + error);
    1.53 +      }
    1.54 +      camera.release(onSuccess, onError);
    1.55 +    }
    1.56 +  },
    1.57 +  {
    1.58 +    key: "set-picture-size-after-release",
    1.59 +    func: function testSetPictureSize(camera) {
    1.60 +      camera.pictureSize = { width: 0, height: 0 };
    1.61 +      next();
    1.62 +    }
    1.63 +  },
    1.64 +  {
    1.65 +    key: "set-thumbnail-size-after-release",
    1.66 +    func: function testSetThumbnailSize(camera) {
    1.67 +      camera.thumbnailSize = { width: 0, height: 0 };
    1.68 +      next();
    1.69 +    }
    1.70 +  },
    1.71 +  {
    1.72 +    key: "get-sensor-angle-after-release",
    1.73 +    func: function testGetSensorAngle(camera) {
    1.74 +      ok(camera.sensorAngle == 0, "camera.sensorAngle = " + camera.sensorAngle);
    1.75 +      next();
    1.76 +    }
    1.77 +  },
    1.78 +  {
    1.79 +    key: "resume-preview-after-release",
    1.80 +    func: function testResumePreview(camera) {
    1.81 +      camera.resumePreview();
    1.82 +      next();
    1.83 +    }
    1.84 +  },
    1.85 +  {
    1.86 +    key: "auto-focus-after-release",
    1.87 +    func: function testAutoFocus(camera) {
    1.88 +      function onSuccess(success) {
    1.89 +        ok(false, "autoFocus() succeeded incorrectly");
    1.90 +      }
    1.91 +      function onError(error) {
    1.92 +        ok(true, "autoFocus() failed correctly with: " + error);
    1.93 +        next();
    1.94 +      }
    1.95 +      camera.autoFocus(onSuccess, onError);
    1.96 +    }
    1.97 +  },
    1.98 +  {
    1.99 +    key: "take-picture-after-release",
   1.100 +    func: function testTakePicture(camera) {
   1.101 +      function onSuccess(picture) {
   1.102 +        ok(false, "takePicture() succeeded incorrectly");
   1.103 +      }
   1.104 +      function onError(error) {
   1.105 +        ok(true, "takePicture() failed correctly with: " + error);
   1.106 +        next();
   1.107 +      }
   1.108 +      camera.takePicture(null, onSuccess, onError);
   1.109 +    }
   1.110 +  },
   1.111 +  {
   1.112 +    key: "start-recording-after-release",
   1.113 +    func: function testStartRecording(camera) {
   1.114 +      function onSuccess(picture) {
   1.115 +        ok(false, "startRecording() process succeeded incorrectly");
   1.116 +      }
   1.117 +      function onError(error) {
   1.118 +        ok(true, "startRecording() process failed correctly with: " + error);
   1.119 +        next();
   1.120 +      }
   1.121 +      var recordingOptions = {
   1.122 +        profile: 'cif',
   1.123 +        rotation: 0
   1.124 +      };
   1.125 +      camera.startRecording(recordingOptions,
   1.126 +                            navigator.getDeviceStorage('videos'),
   1.127 +                            'bug975472.mp4',
   1.128 +                            onSuccess, onError);
   1.129 +    }
   1.130 +  },
   1.131 +  {
   1.132 +    key: "stop-recording-after-release",
   1.133 +    func: function testStopRecording(camera) {
   1.134 +      camera.stopRecording();
   1.135 +      next();
   1.136 +    }
   1.137 +  },
   1.138 +  {
   1.139 +    key: "set-configuration-after-release",
   1.140 +    func: function testSetConfiguration(camera) {
   1.141 +      function onSuccess(picture) {
   1.142 +        ok(false, "setConfiguration() process succeeded incorrectly");
   1.143 +      }
   1.144 +      function onError(error) {
   1.145 +        ok(true, "setConfiguration() process failed correctly with: " + error);
   1.146 +        next();
   1.147 +      }
   1.148 +      camera.setConfiguration(config, onSuccess, onError);
   1.149 +    }
   1.150 +  },
   1.151 +];
   1.152 +
   1.153 +var testGenerator = function() {
   1.154 +  for (var i = 0; i < tests.length; ++i ) {
   1.155 +    yield tests[i];
   1.156 +  }
   1.157 +}();
   1.158 +
   1.159 +var Camera = {
   1.160 +  cameraObj: null,
   1.161 +  _otherPictureSize: null,
   1.162 +  get viewfinder() {
   1.163 +    return document.getElementById('viewfinder');
   1.164 +  },
   1.165 +  onCameraReady: function () {
   1.166 +    Camera.nextTest = function() {
   1.167 +      try {
   1.168 +        var t = testGenerator.next();
   1.169 +        info("test: " + t.key);
   1.170 +        t.func(Camera.cameraObj);
   1.171 +      } catch(e) {
   1.172 +        if (e instanceof StopIteration) {
   1.173 +          SimpleTest.finish();
   1.174 +        } else {
   1.175 +          throw e;
   1.176 +        }
   1.177 +      }
   1.178 +    };
   1.179 +    // Release the camera hardware, and call all of the asynchronous methods
   1.180 +    // to make sure they properly handle being in this state.
   1.181 +    Camera.cameraObj.release();
   1.182 +    next();
   1.183 +  },
   1.184 +  release: function release() {
   1.185 +    cameraObj = null;
   1.186 +  },
   1.187 +  start: function run_test() {
   1.188 +    function onSuccess(camera, config) {
   1.189 +      Camera.cameraObj = camera;
   1.190 +      Camera.viewfinder.mozSrcObject = camera;
   1.191 +      Camera.viewfinder.play();
   1.192 +      ok(camera.capabilities.pictureSizes.length > 0,
   1.193 +        "capabilities.pictureSizes.length = " +
   1.194 +        camera.capabilities.pictureSizes.length);
   1.195 +      Camera._otherPictureSize = camera.capabilities.pictureSizes.slice(-1)[0];
   1.196 +      camera.pictureSize = camera.capabilities.pictureSizes[0];
   1.197 +      options.pictureSize = Camera._otherPictureSize;
   1.198 +      options.fileFormat = camera.capabilities.fileFormats[0];
   1.199 +      info("getCamera callback, setting pictureSize = " + options.pictureSize.toSource());
   1.200 +      Camera.cameraObj.onPreviewStateChange = function(state) {
   1.201 +        if (state === 'started') {
   1.202 +          info("viewfinder is ready and playing");
   1.203 +          Camera.cameraObj.onPreviewStateChange = null;
   1.204 +          Camera.onCameraReady();
   1.205 +        }
   1.206 +      };
   1.207 +    };
   1.208 +    navigator.mozCameras.getCamera(whichCamera, config, onSuccess, onError);
   1.209 +  }
   1.210 +}
   1.211 +
   1.212 +SimpleTest.waitForExplicitFinish();
   1.213 +
   1.214 +window.addEventListener('beforeunload', function() {
   1.215 +  Camera.viewfinder.mozSrcObject = null;
   1.216 +  Camera.cameraObj.release();
   1.217 +  Camera.cameraObj = null;
   1.218 +});
   1.219 +
   1.220 +Camera.start();
   1.221 +
   1.222 +</script>
   1.223 +</body>
   1.224 +
   1.225 +</html>

mercurial