dom/camera/test/test_camera_hardware_failures.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/camera/test/test_camera_hardware_failures.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,145 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=940424
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Bug 940424 - Test camera hardware API failure handling</title>
    1.11 +  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
    1.12 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <script type="text/javascript" src="camera_common.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.15 +</head>
    1.16 +<body>
    1.17 +  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=940424">Mozilla Bug 940424</a>
    1.18 +  <video id="viewfinder" width = "200" height = "200" autoplay></video>
    1.19 +  <img src="#" alt="This image is going to load" id="testimage"/>
    1.20 +
    1.21 +<script class="testbody" type="text/javascript;version=1.7">
    1.22 +
    1.23 +var whichCamera = navigator.mozCameras.getListOfCameras()[0];
    1.24 +var initialConfig = {
    1.25 +  mode: 'picture',
    1.26 +  recorderProfile: 'cif',
    1.27 +  previewSize: {
    1.28 +    width: 352,
    1.29 +    height: 288
    1.30 +  }
    1.31 +};
    1.32 +
    1.33 +var cameraObj;
    1.34 +
    1.35 +// Shorthand functions
    1.36 +function end() {
    1.37 +  CameraTest.end();
    1.38 +}
    1.39 +function next() {
    1.40 +  CameraTest.next();
    1.41 +}
    1.42 +
    1.43 +// The array of tests
    1.44 +var tests = [
    1.45 +  {
    1.46 +    key: "auto-focus-failure",
    1.47 +    func: function testAutoFocusApiFailure(camera) {
    1.48 +      function onSuccess(success) {
    1.49 +        ok(false, "autoFocus() succeeded incorrectly");
    1.50 +        end();
    1.51 +      }
    1.52 +      function onError(error) {
    1.53 +        ok(true, "autoFocus() failed correctly with: " + error);
    1.54 +        next();
    1.55 +      }
    1.56 +      camera.autoFocus(onSuccess, onError);
    1.57 +    }
    1.58 +  },
    1.59 +  {
    1.60 +    key: "auto-focus-process-failure",
    1.61 +    func: function testAutoFocusProcessFailure(camera) {
    1.62 +      function onSuccess(success) {
    1.63 +        if (success) {
    1.64 +          ok(false, "autoFocus() process succeeded incorrectly");
    1.65 +          end();
    1.66 +        } else {
    1.67 +          ok(true, "autoFocus() process failed correctly");
    1.68 +          next();
    1.69 +        }
    1.70 +      }
    1.71 +      function onError(error) {
    1.72 +        ok(false, "autoFocus() process failed incorrectly with: " + error);
    1.73 +        end();
    1.74 +      }
    1.75 +      camera.autoFocus(onSuccess, onError);
    1.76 +    }
    1.77 +  },
    1.78 +  {
    1.79 +    key: "take-picture-failure",
    1.80 +    func: function testTakePictureApiFailure(camera) {
    1.81 +      function onSuccess(picture) {
    1.82 +        ok(false, "takePicture() succeeded incorrectly");
    1.83 +        end();
    1.84 +      }
    1.85 +      function onError(error) {
    1.86 +        ok(true, "takePicture() failed correctly with: " + error);
    1.87 +        next();
    1.88 +      }
    1.89 +      camera.takePicture(null, onSuccess, onError);
    1.90 +    }
    1.91 +  },
    1.92 +  {
    1.93 +    key: "take-picture-process-failure",
    1.94 +    func: function testTakePictureProcessFailure(camera) {
    1.95 +      function onSuccess(picture) {
    1.96 +        ok(false, "takePicture() process succeeded incorrectly");
    1.97 +        end();
    1.98 +      }
    1.99 +      function onError(error) {
   1.100 +        ok(true, "takePicture() process failed correctly with: " + error);
   1.101 +        next();
   1.102 +      }
   1.103 +      camera.takePicture(null, onSuccess, onError);
   1.104 +    }
   1.105 +  },
   1.106 +];
   1.107 +
   1.108 +var testGenerator = function() {
   1.109 +  for (var i = 0; i < tests.length; ++i ) {
   1.110 +    yield tests[i];
   1.111 +  }
   1.112 +}();
   1.113 +
   1.114 +window.addEventListener('beforeunload', function() {
   1.115 +  document.getElementById('viewfinder').mozSrcObject = null;
   1.116 +  cameraObj.release();
   1.117 +  cameraObj = null;
   1.118 +});
   1.119 +
   1.120 +CameraTest.begin("hardware", function(test) {
   1.121 +  function onSuccess(camera, config) {
   1.122 +    document.getElementById('viewfinder').mozSrcObject = camera;
   1.123 +    cameraObj = camera;
   1.124 +    CameraTest.next = function() {
   1.125 +      try {
   1.126 +        var t = testGenerator.next();
   1.127 +        test.set(t.key, t.func.bind(undefined, camera));
   1.128 +      } catch(e) {
   1.129 +        if (e instanceof StopIteration) {
   1.130 +          end();
   1.131 +        } else {
   1.132 +          throw e;
   1.133 +        }
   1.134 +      }
   1.135 +    };
   1.136 +    next();
   1.137 +  }
   1.138 +  function onError(error) {
   1.139 +    ok(false, "getCamera() failed with: " + error);
   1.140 +    end();
   1.141 +  }
   1.142 +  navigator.mozCameras.getCamera(whichCamera, initialConfig, onSuccess, onError);
   1.143 +});
   1.144 +
   1.145 +</script>
   1.146 +</body>
   1.147 +
   1.148 +</html>

mercurial