chromium/chrome/test/data/webrtc/webrtc_pan_tilt_zoom_test.html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
  <title>WebRTC Automated Test</title>
  <script type="text/javascript" src="test_functions.js"></script>
  <script>
  'use strict';
  let stream;
  let waitForImageCapture;

  let microphonePermissionStatus;
  let cameraPermissionStatus;
  let panTiltZoomPermissionStatus;

  let queryPermissions = Promise.all([
    navigator.permissions.query({ name: "microphone" }),
    navigator.permissions.query({ name: "camera" }),
    navigator.permissions.query({ name: "camera", panTiltZoom: true }),
  ]).then((permissionStatuses) => {
    [
      microphonePermissionStatus,
      cameraPermissionStatus,
      panTiltZoomPermissionStatus,
    ] = permissionStatuses;
  });

  async function runGetUserMedia(constraints) {
    try {
      await queryPermissions;
      stream = await navigator.mediaDevices.getUserMedia(constraints);
      waitForImageCapture = new Promise(resolve => setTimeout(resolve, 100));
      return logAndReturn("runGetUserMedia-success");
    } catch (error) {
      return logAndReturn("runGetUserMedia-failure");
    }
  }

  async function runRequestPanTiltZoom() {
    try {
      await queryPermissions;
      await navigator.permissions.request({ name: "camera", panTiltZoom: true });
      return logAndReturn("runRequestPanTiltZoom-success");
    } catch (error) {
      return logAndReturn("runRequestPanTiltZoom-failure");
    }
  }

  function getTrackSetting(settingName) {
    const videoTrack = stream.getVideoTracks()[0];
    const settings = videoTrack.getSettings();
    return settings[settingName];
  }

  function checkConstraints(expectedConstraints) {
    const videoTrack = stream.getVideoTracks()[0];
    const constraints = videoTrack.getConstraints();

    const s = (o) => Object.entries(o).sort().map(i => {
      if(i[1] instanceof Object) i[1] = s(i[1]);
      return i
    })
    const constraintsString = JSON.stringify(s(constraints));
    const expectedConstraintsString = JSON.stringify(s(expectedConstraints));
    if  (constraintsString !== expectedConstraintsString) {
      debug(`Expected ${expectedConstraintsString} - got ${constraintsString}`)
      return logAndReturn("checkConstraints-failure");
    }

    return logAndReturn("checkConstraints-success");
  }

  async function applyConstraints(constraints) {
    try {
      const videoTrack = stream.getVideoTracks()[0];
      await videoTrack.applyConstraints(constraints);
      return logAndReturn("applyConstraints-success");
    } catch (error) {
      return logAndReturn(`applyConstraints-failure-${error.name}`);
    }
  }

  function getMicrophonePermission() {
    return logAndReturn(microphonePermissionStatus.state);
  }

  function getCameraPermission() {
    return logAndReturn(cameraPermissionStatus.state);
  }

  function getPanTiltZoomPermission() {
    return logAndReturn(panTiltZoomPermissionStatus.state);
  }

  document.addEventListener('visibilitychange', () => {
    document.title = document.visibilityState;
  });
  </script>
</head>
<body>
</body>
</html>