dom/camera/test/test_bug1037322.html
author Jim Mathies <jmathies@mozilla.com>
Wed, 12 Nov 2014 14:59:19 -0600
changeset 239674 dcc233b91a99e7d8cfaa39b508d2eb2c2496fab6
parent 231884 05df8323b82079743e8af61b83625739bbadf905
child 246063 ce9707a48002c8fd80f1c921b13e8f6e40d54f43
permissions -rw-r--r--
Bug 669200 - Various widget changes to support two new types of plugin widget. r=roc

<!DOCTYPE HTML>
<html>
<head>
  <title>Test for bug 1037322</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="camera_common.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<video id="viewfinder" width="200" height="200" autoplay></video>
<img src="#" alt="This image is going to load" id="testimage"/>
<script class="testbody" type="text/javascript;version=1.7">

var whichCamera = navigator.mozCameras.getListOfCameras()[0];
var config = {
  mode: 'picture',
  recorderProfile: 'cif',
  previewSize: {
    width: 352,
    height: 288
  }
};

function onError(e) {
  ok(false, "Error: " + JSON.stringify(e));
}

var Camera = {
  cameraObj: null,

  get viewfinder() {
    return document.getElementById('viewfinder');
  },

  start: function test_start() {
    function setConfig_onSuccess(cfg) {
      // Check our specific configuration
      ok(cfg.mode === config.mode, "Configured mode = " + cfg.mode);
      ok(cfg.previewSize.width === config.previewSize.width &&
         cfg.previewSize.height === config.previewSize.height,
         "Configured preview size = " + cfg.previewSize.width + "x" + cfg.previewSize.height);
      ok(cfg.recorderProfile === config.recorderProfile,
         "Configured recorder profile = '" + cfg.recorderProfile + "'");

      SimpleTest.finish();
    }

    function getCamera_onSuccess(d) {
      var camera = d.camera;
      var cfg = d.configuration;
      Camera.cameraObj = camera;
      Camera.viewfinder.mozSrcObject = camera;
      Camera.viewfinder.play();

      // Check the default configuration
      ok(cfg.mode === "unspecified", "Initial mode = " + cfg.mode);
      ok(cfg.previewSize.width === 0 && cfg.previewSize.height === 0,
         "Initial preview size = " + cfg.previewSize.width + "x" + cfg.previewSize.height);
      ok(cfg.recorderProfile === "",
         "Initial recorder profile = '" + cfg.recorderProfile + "'");

      // Apply our specific configuration
      camera.setConfiguration(config).then(setConfig_onSuccess, onError);
    }

    navigator.mozCameras.getCamera(whichCamera, {}).then(getCamera_onSuccess, onError);
  }
}

SimpleTest.waitForExplicitFinish();

window.addEventListener('beforeunload', function() {
  Camera.viewfinder.mozSrcObject = null;
  if (Camera.cameraObj) {
    Camera.cameraObj.release();
    Camera.cameraObj = null;
  }
});

Camera.start();

</script>
</body>

</html>