blob: ef25073e96f7a941693061705b8ee38cbb60559b [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/mojo-helpers.js"></script>
<script src="resources/mock-imagecapture.js"></script>
<body>
<canvas id='canvas' width=10 height=10/>
</body>
<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().
async_test(function(t) {
var canvas = document.getElementById('canvas');
var context = canvas.getContext("2d");
context.fillStyle = "red";
context.fillRect(0, 0, 10, 10);
var mock_settings;
mockImageCaptureReady
.then(mock => {
mock_settings = mock.capabilities();
// |stream| must be created _after_ |mock| is constructed to give the
// latter time to override the bindings.
var stream = canvas.captureStream();
var 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.
setTimeout(() => {
settings = videoTrack.getSettings();
assert_equals(typeof settings, 'object');
assert_equals(
settings.whiteBalanceMode,
meteringModeNames[mock_settings.current_white_balance_mode],
'whiteBalanceMode');
assert_equals(settings.exposureMode,
meteringModeNames[mock_settings.current_exposure_mode],
'exposureMode;');
assert_equals(settings.focusMode,
meteringModeNames[mock_settings.current_focus_mode],
'focusMode');
assert_equals(settings.pointsOfInterest.length,
mock_settings.points_of_interest.length,
'pointsOfInterest');
for (i = 0; i < settings.pointsOfInterest.length; ++i) {
assert_approx_equals(settings.pointsOfInterest[i].x,
mock_settings.points_of_interest[i].x, 0.01,
'pointsOfInterest x');
assert_approx_equals(settings.pointsOfInterest[i].y,
mock_settings.points_of_interest[i].y, 0.01,
'pointsOfInterest y');
}
assert_equals(settings.exposureCompensation,
mock_settings.exposure_compensation.current);
assert_equals(settings.colorTemperature,
mock_settings.color_temperature.current);
assert_equals(settings.iso, mock_settings.iso.current);
assert_equals(settings.brightness, mock_settings.brightness.current);
assert_equals(settings.contrast, mock_settings.contrast.current);
assert_equals(settings.saturation, mock_settings.saturation.current);
assert_equals(settings.sharpness, mock_settings.sharpness.current);
assert_equals(settings.zoom, mock_settings.zoom.current);
assert_equals(settings.torch, mock_settings.torch, 'torch');
t.done();
}, 100);
},
error => {
assert_unreached("Error creating MockImageCapture: " + error);
});
}, 'exercises MediaStreamTrack.getSettings()');
</script>