summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mediacapture-image/MediaStreamTrack-getSettings.https.html
blob: bd8a1ea1008659405c128359150e7e79ce4b12e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/mediacapture-image/resources/imagecapture-helpers.js"></script>
<script>

const meteringModeNames = ['none', 'manual', 'single-shot', 'continuous'];

// This test verifies that the settings defined in the mock Mojo service
// implementation are the same as those returned by the corresponding
// MediaStreamTrack.getSettings(), except for PTZ settings when PTZ
// permission is denied.

function makeImageCaptureTest(hasPanTiltZoomPermissionGranted) {
  image_capture_test(async (t, imageCaptureTest) => {
    const ptzPermission = hasPanTiltZoomPermissionGranted ? 'granted' : 'denied';
    await test_driver.set_permission({name: 'camera', panTiltZoom: true},
        ptzPermission);

    let mockSettings = imageCaptureTest.mockImageCapture().state();

    // |stream| must be created _after_ |mock| is constructed to give the
    // latter time to override the bindings.
    let stream = await navigator.mediaDevices.getUserMedia({video: true});
    let videoTrack = stream.getVideoTracks()[0];

    // |videoTrack|s settings retrieval, just like the actual capture, is a
    // process kicked right after creation, we introduce a small delay to
    // allow for those to be collected.
    await new Promise(resolve => step_timeout(resolve, 100));

    let settings = videoTrack.getSettings();
    assert_equals(typeof settings, 'object');

    assert_equals(settings.whiteBalanceMode,
                  meteringModeNames[mockSettings.currentWhiteBalanceMode],
                  'whiteBalanceMode');
    assert_equals(settings.exposureMode,
                  meteringModeNames[mockSettings.currentExposureMode],
                  'exposureMode;');
    assert_equals(settings.focusMode,
                  meteringModeNames[mockSettings.currentFocusMode],
                  'focusMode');

    assert_point2d_array_approx_equals(
        settings.pointsOfInterest, mockSettings.pointsOfInterest, 0.01);

    assert_equals(settings.exposureCompensation,
                  mockSettings.exposureCompensation.current);
    assert_equals(settings.exposureTime,
                  mockSettings.exposureTime.current);
    assert_equals(settings.colorTemperature,
                  mockSettings.colorTemperature.current);
    assert_equals(settings.iso, mockSettings.iso.current);

    assert_equals(settings.brightness, mockSettings.brightness.current);
    assert_equals(settings.contrast, mockSettings.contrast.current);
    assert_equals(settings.saturation, mockSettings.saturation.current);
    assert_equals(settings.sharpness, mockSettings.sharpness.current);

    assert_equals(settings.focusDistance, mockSettings.focusDistance.current);

    if (ptzPermission === 'granted') {
      assert_equals(settings.pan, mockSettings.pan.current);
      assert_equals(settings.tilt, mockSettings.tilt.current);
      assert_equals(settings.zoom, mockSettings.zoom.current);
    } else if (ptzPermission === 'denied') {
      assert_false('pan' in settings);
      assert_false('tilt' in settings);
      assert_false('zoom' in settings);
    }

    assert_equals(settings.torch, mockSettings.torch, 'torch');
  });
}

generate_tests(makeImageCaptureTest, [
  [
    "exercises MediaStreamTrack.getSettings() with PTZ permission denied",
    false,
  ],
  [
    "exercises MediaStreamTrack.getSettings() with PTZ permission granted",
    true,
  ],
]);
</script>