Bug 1144211 - Improve code coverage of camera mochitests. r=mikeh

This commit is contained in:
Andrew Osmond 2015-03-17 13:01:24 -04:00
parent 9de0330eec
commit 49e2dcf407
20 changed files with 1286 additions and 367 deletions

View File

@ -74,9 +74,15 @@ MozCameraTestHardware.prototype = {
},
dispatchEvent: function(evt) {
if (this._handler) {
this._handler.handleEvent(evt);
}
var self = this;
/* We should not dispatch the event in the current thread
context because it may be directly from a driver call
and we could hit a deadlock situation. */
this._window.setTimeout(function() {
if (self._handler) {
self._handler.handleEvent(evt);
}
}, 0);
},
reset: function(aWindow) {

View File

@ -958,8 +958,10 @@ nsDOMCameraControl::TakePicture(const CameraPictureOptions& aOptions,
if (s.width && s.height) {
mCameraControl->Set(CAMERA_PARAM_PICTURE_SIZE, s);
}
if (!aOptions.mFileFormat.IsEmpty()) {
mCameraControl->Set(CAMERA_PARAM_PICTURE_FILEFORMAT, aOptions.mFileFormat);
}
mCameraControl->Set(CAMERA_PARAM_PICTURE_ROTATION, aOptions.mRotation);
mCameraControl->Set(CAMERA_PARAM_PICTURE_FILEFORMAT, aOptions.mFileFormat);
mCameraControl->Set(CAMERA_PARAM_PICTURE_DATETIME, aOptions.mDateTime);
mCameraControl->SetLocation(p);
}

View File

@ -269,6 +269,8 @@ namespace android {
return 320;
} else if (strcmp(aParameter, "vid.height") == 0) {
return 240;
} else if (strcmp(aParameter, "vid.fps") == 0) {
return 30;
}
return 0;
case CAMCORDER_QUALITY_HIGH:
@ -277,6 +279,8 @@ namespace android {
return 640;
} else if (strcmp(aParameter, "vid.height") == 0) {
return 480;
} else if (strcmp(aParameter, "vid.fps") == 0) {
return 30;
}
return 0;
default:

View File

@ -1255,7 +1255,7 @@ nsGonkCameraControl::StopRecordingImpl()
class RecordingComplete : public nsRunnable
{
public:
RecordingComplete(DeviceStorageFile* aFile)
RecordingComplete(already_AddRefed<DeviceStorageFile> aFile)
: mFile(aFile)
{ }
@ -1285,6 +1285,11 @@ nsGonkCameraControl::StopRecordingImpl()
mRecorder->stop();
mRecorder = nullptr;
#else
if (!mVideoFile) {
return NS_OK;
}
#endif
OnRecorderStateChange(CameraControlListener::kRecorderStopped);
{
@ -1299,10 +1304,7 @@ nsGonkCameraControl::StopRecordingImpl()
}
// notify DeviceStorage that the new video file is closed and ready
return NS_DispatchToMainThread(new RecordingComplete(mVideoFile));
#else
return NS_OK;
#endif
return NS_DispatchToMainThread(new RecordingComplete(mVideoFile.forget()));
}
nsresult

View File

@ -412,6 +412,32 @@ TestGonkCameraHardware::AutoFocus()
return OK;
}
int
TestGonkCameraHardware::CancelAutoFocus()
{
class Delegate : public ControlMessage
{
public:
Delegate(TestGonkCameraHardware* aTestHw)
: ControlMessage(aTestHw)
{ }
protected:
NS_IMETHOD
RunImpl() override
{
return mJSTestWrapper->CancelAutoFocus();
}
};
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
nsresult rv = WaitWhileRunningOnMainThread(new Delegate(this));
if (NS_WARN_IF(NS_FAILED(rv))) {
return UNKNOWN_ERROR;
}
return OK;
}
int
TestGonkCameraHardware::StartFaceDetection()
{

View File

@ -33,6 +33,7 @@ class TestGonkCameraHardware : public android::GonkCameraHardware
public:
virtual nsresult Init() override;
virtual int AutoFocus() override;
virtual int CancelAutoFocus() override;
virtual int StartFaceDetection() override;
virtual int StopFaceDetection() override;
virtual int TakePicture() override;

View File

@ -103,6 +103,14 @@ CameraTestSuite.prototype = {
_lowMemSet: false,
_reloading: false,
_setupPermission: function(permission) {
if (!SpecialPowers.hasPermission(permission, document)) {
info("requesting " + permission + " permission");
SpecialPowers.addPermission(permission, true, document);
this._reloading = true;
}
},
/* Returns a promise which is resolved when the test suite is ready
to be executing individual test cases. One may provide the expected
hardware type here if desired; the default is to use the JS test
@ -111,24 +119,28 @@ CameraTestSuite.prototype = {
/* Depending on how we run the mochitest, we may not have the necessary
permissions yet. If we do need to request them, then we have to reload
the window to ensure the reconfiguration propogated properly. */
if (!SpecialPowers.hasPermission("camera", document)) {
info("requesting camera permission");
this._reloading = true;
SpecialPowers.addPermission("camera", true, document);
this._setupPermission("camera");
this._setupPermission("device-storage:videos");
this._setupPermission("device-storage:videos-create");
this._setupPermission("device-storage:videos-write");
if (this._reloading) {
window.location.reload();
return Promise.reject();
}
info("has camera permission");
info("has necessary permissions");
if (!isDefined(hwType)) {
hwType = 'hardware';
}
this._hwType = hwType;
return new Promise(function(resolve, reject) {
SpecialPowers.pushPrefEnv({'set': [['camera.control.test.permission', true]]}, function() {
SpecialPowers.pushPrefEnv({'set': [['camera.control.test.enabled', hwType]]}, function() {
resolve();
SpecialPowers.pushPrefEnv({'set': [['device.storage.prompt.testing', true]]}, function() {
SpecialPowers.pushPrefEnv({'set': [['camera.control.test.permission', true]]}, function() {
SpecialPowers.pushPrefEnv({'set': [['camera.control.test.enabled', hwType]]}, function() {
resolve();
});
});
});
});

View File

@ -1,21 +1,20 @@
[DEFAULT]
support-files = camera_common.js
[test_camera_configuration.html]
[test_camera_release.html]
[test_camera_auto_focus.html]
[test_camera_take_picture.html]
[test_camera_record.html]
skip-if = toolkit == 'gonk'
[test_camera_face_detection.html]
[test_camera_fake_parameters.html]
[test_camera_hardware_init_failure.html]
[test_camera.html]
skip-if = toolkit != 'gonk'
[test_camera_2.html]
skip-if = toolkit != 'gonk'
[test_camera_3.html]
skip-if = toolkit != 'gonk'
[test_camera_hardware_init_failure.html]
[test_camera_hardware_failures.html]
[test_bug975472.html]
[test_camera_fake_parameters.html]
[test_camera_hardware_face_detection.html]
[test_camera_hardware_auto_focus_moving_cb.html]
[test_bug1022766.html]
[test_bug1037322.html]
[test_bug1099390.html]
[test_bug1104913.html]
skip-if = toolkit != 'gonk'
[test_camera_bad_initial_config.html]

View File

@ -1,63 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for bug 1022766</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 suite = new CameraTestSuite();
suite.test('bug-1022766', function() {
function triggerAutoFocus(p) {
return new Promise(function(resolve, reject) {
var firstCall = false;
var secondCall = false;
function end() {
if (firstCall && secondCall) {
resolve();
}
}
// It doesn't matter if the emulator supports focus or not;
// this is just testing the sequencing.
suite.camera.autoFocus().then(function(p) {
ok(false, "First call to autoFocus() succeeded unexpectedly");
firstCall = true;
end();
}, function(e) {
ok(e.name === 'NS_ERROR_IN_PROGRESS', 'First call to autoFocus() failed with: ' + e);
firstCall = true;
end();
});
suite.camera.autoFocus().then(function(p) {
ok(true, "Second call to autoFocus() succeeded");
secondCall = true;
end();
}, function(e) {
ok(false, "Second call to autoFocus() failed unexpectedly with: " + e);
secondCall = true;
end();
});
});
}
return suite.getCamera()
.then(triggerAutoFocus, suite.rejectGetCamera)
});
suite.setup()
.then(suite.run);
</script>
</body>
</html>

View File

@ -1,69 +0,0 @@
<!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 suite = new CameraTestSuite();
suite.test('bug-1037322', function() {
var cameraManager = navigator.mozCameras;
var whichCamera = cameraManager.getListOfCameras()[0];
var postConfig = {
mode: 'picture',
recorderProfile: 'low',
previewSize: {
width: 320,
height: 240
}
};
function resolveGetCamera(p) {
suite.camera = p.camera;
// Check the default configuration
var cfg = p.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 === "default",
"Initial recorder profile = '" + cfg.recorderProfile + "'");
}
function configure(p) {
// Apply our specific configuration
return suite.camera.setConfiguration(postConfig);
}
function resolveConfigure(cfg) {
// Check our specific configuration
ok(cfg.mode === postConfig.mode, "Configured mode = " + cfg.mode);
ok(cfg.previewSize.width === postConfig.previewSize.width &&
cfg.previewSize.height === postConfig.previewSize.height,
"Configured preview size = " + cfg.previewSize.width + "x" + cfg.previewSize.height);
ok(cfg.recorderProfile === postConfig.recorderProfile,
"Configured recorder profile = '" + cfg.recorderProfile + "'");
}
return cameraManager.getCamera(whichCamera, {mode: 'unspecified'})
.then(resolveGetCamera, suite.rejectGetCamera)
.then(configure)
.then(resolveConfigure, suite.rejectConfigure);
});
suite.setup()
.then(suite.run);
</script>
</body>
</html>

View File

@ -1,55 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for bug 1099390</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 suite = new CameraTestSuite();
suite.test('bug-1099390', function() {
function release(p) {
return new Promise(function(resolve, reject) {
var gotCloseEvent = false;
var gotReleasePromise = false;
var onClosed = function(e) {
suite.camera.removeEventListener('close', onClosed);
ok(!gotCloseEvent, "gotCloseEvent was " + gotCloseEvent);
ok(e.reason === "HardwareReleased", "'close' event reason is: " + e.reason);
gotCloseEvent = true;
if (gotReleasePromise) {
resolve();
}
};
suite.camera.addEventListener('close', onClosed);
suite.camera.release().then(function(p) {
ok(true, "released camera");
gotReleasePromise = true;
if (gotCloseEvent) {
resolve();
}
}).catch(reject);
});
}
return suite.getCamera()
.then(release, suite.rejectGetCamera);
});
suite.setup()
.then(suite.run);
</script>
</body>
</html>

View File

@ -1,20 +1,15 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=940424
-->
<head>
<title>Bug 940424 - Test camera hardware API failure handling</title>
<title>Test for auto focus</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>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=940424">Mozilla Bug 940424</a>
<video id="viewfinder" width = "200" height = "200" autoplay></video>
<img src="#" alt="This image is going to load" id="testimage"/>
<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 suite = new CameraTestSuite();
@ -129,39 +124,109 @@ suite.test('auto-focus-failures', function() {
.then(suite.expectedRejectAutoFocus, rejectAutoFocusError)
});
suite.test('take-picture-failures', function() {
function startTakePictureProcessError(p) {
suite.hw.attach({
takePicture: function() {
suite.hw.fireTakePictureError();
suite.test('auto-focus-moving', function() {
function triggerAutoFocusMoving(p) {
var sync = new Promise(function(resolve, reject) {
function onEvent(e) {
suite.camera.removeEventListener('focus', onEvent);
ok(e.newState === 'focusing', 'autofocus event state focusing == ' + e.newState);
resolve();
}
suite.camera.addEventListener('focus', onEvent);
});
return suite.camera.takePicture();
suite.hw.fireAutoFocusMoving(true);
return sync;
}
function rejectTakePictureProcessError(e) {
ok(e.name === 'NS_ERROR_FAILURE', 'takePicture() process should fail: ' + e);
}
function startTakePictureError(p) {
suite.hw.attach({
takePicture: function() {
throw SpecialPowers.Cr.NS_ERROR_FAILURE;
function waitAutoFocusComplete(p) {
var sync = new Promise(function(resolve, reject) {
function onEvent(e) {
suite.camera.removeEventListener('focus', onEvent);
ok(e.newState === 'focused', 'autofocus event state focused == ' + e.newState);
resolve();
}
suite.camera.addEventListener('focus', onEvent);
});
return suite.camera.takePicture();
// Missing the fireAutoFocusComplete but it should timeout on its own
suite.hw.fireAutoFocusMoving(false);
return sync;
}
function rejectTakePictureError(e) {
ok(e.name === 'NS_ERROR_FAILURE', 'takePicture() should fail: ' + e);
function runAutoFocusCycle(p) {
return triggerAutoFocusMoving(p)
.then(waitAutoFocusComplete);
}
/* If the driver doesn't supply an onAutoFocusComplete notification,
gecko will timeout and provide it. After three times, it will no
longer rely upon a timeout and fire it immediately. */
return suite.getCamera()
.then(runAutoFocusCycle)
.then(runAutoFocusCycle)
.then(runAutoFocusCycle)
.then(runAutoFocusCycle);
});
suite.test('auto-focus-interrupted', function() {
// bug 1022766
function triggerAutoFocus(p) {
return new Promise(function(resolve, reject) {
var firstCall = false;
var secondCall = false;
function end() {
if (firstCall && secondCall) {
resolve();
}
}
// It doesn't matter if the emulator supports focus or not;
// this is just testing the sequencing.
suite.camera.autoFocus().then(function(p) {
ok(false, "First call to autoFocus() succeeded unexpectedly");
firstCall = true;
end();
}, function(e) {
ok(e.name === 'NS_ERROR_IN_PROGRESS', 'First call to autoFocus() failed with: ' + e);
firstCall = true;
end();
});
suite.camera.autoFocus().then(function(p) {
ok(true, "Second call to autoFocus() succeeded");
secondCall = true;
end();
}, function(e) {
ok(false, "Second call to autoFocus() failed unexpectedly with: " + e);
secondCall = true;
end();
});
});
}
return suite.getCamera()
.catch(suite.rejectGetCamera)
.then(startTakePictureProcessError)
.then(suite.expectedRejectTakePicture, rejectTakePictureProcessError)
.then(startTakePictureError)
.then(suite.expectedRejectTakePicture, rejectTakePictureError)
.then(triggerAutoFocus, suite.rejectGetCamera)
});
suite.test('cancel-auto-focus', function() {
function cancelAutoFocus(p) {
var promise = new Promise(function(resolve, reject) {
suite.hw.attach({
cancelAutoFocus: function() {
ok(true, 'got cancel auto focus');
resolve();
}
});
});
suite.camera.resumeContinuousFocus();
return promise;
}
return suite.getCamera()
.then(cancelAutoFocus, suite.rejectGetCamera);
});
suite.setup()

View File

@ -1,44 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for bad initial configuration</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 suite = new CameraTestSuite();
suite.test('bad-initial-config', function() {
function getCamera() {
var whichCamera = navigator.mozCameras.getListOfCameras()[0];
var config = {
mode: 'picture',
recorderProfile: 'foobar',
};
return navigator.mozCameras.getCamera(whichCamera, config);
}
function rejectGetCamera(error) {
ok(error.name === "NS_ERROR_NOT_AVAILABLE",
"getCamera() failed with: " + error.name);
return Promise.resolve();
}
return getCamera()
.then(suite.expectedRejectGetCamera, rejectGetCamera);
});
suite.setup()
.then(suite.run);
</script>
</body>
</html>

View File

@ -0,0 +1,545 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for camera configuration</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 suite = new CameraTestSuite();
function verifyConfig(cfg, expConfig)
{
ok(cfg.mode === expConfig.mode, "Configured mode = " + cfg.mode +
", expected = " + expConfig.mode);
ok(cfg.previewSize.width === expConfig.previewSize.width &&
cfg.previewSize.height === expConfig.previewSize.height,
"Configured preview size = " + cfg.previewSize.width + "x" + cfg.previewSize.height +
", expected = " + expConfig.previewSize.width + "x" + expConfig.previewSize.height);
ok(cfg.pictureSize.width === expConfig.pictureSize.width &&
cfg.pictureSize.height === expConfig.pictureSize.height,
"Configured picture size = " + cfg.pictureSize.width + "x" + cfg.pictureSize.height +
", expected = " + expConfig.pictureSize.width + "x" + expConfig.pictureSize.height);
ok(cfg.recorderProfile === expConfig.recorderProfile,
"Configured recorder profile = '" + cfg.recorderProfile + "'" +
", expected = '" + expConfig.recorderProfile + "'");
}
function setAndVerifyConfig(setConfig, expConfig)
{
return suite.getCamera(undefined, setConfig)
.catch(suite.rejectGetCamera)
.then(function(p) {
verifyConfig(p.configuration, expConfig);
});
}
suite.test('bad-initial-config', function() {
function getCamera() {
var whichCamera = navigator.mozCameras.getListOfCameras()[0];
var config = {
mode: 'picture',
recorderProfile: 'foobar',
};
return navigator.mozCameras.getCamera(whichCamera, config);
}
function rejectGetCamera(error) {
ok(error.name === "NS_ERROR_NOT_AVAILABLE",
"getCamera() failed with: " + error.name);
return Promise.resolve();
}
return getCamera()
.then(suite.expectedRejectGetCamera, rejectGetCamera);
});
suite.test('start-unspecified', function() {
// bug 1037322
var cameraManager = navigator.mozCameras;
var whichCamera = cameraManager.getListOfCameras()[0];
var postConfig = {
mode: 'picture',
recorderProfile: 'low',
previewSize: {
width: 320,
height: 240
},
pictureSize: {
width: 320,
height: 240
}
};
function resolveGetCamera(p) {
suite.camera = p.camera;
// Check the default configuration
var cfg = p.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 === "default",
"Initial recorder profile = '" + cfg.recorderProfile + "'");
}
function configure(p) {
// Apply our specific configuration
return suite.camera.setConfiguration(postConfig);
}
function resolveConfigure(cfg) {
// Check our specific configuration
verifyConfig(cfg, postConfig);
}
return cameraManager.getCamera(whichCamera, {mode: 'unspecified'})
.then(resolveGetCamera, suite.rejectGetCamera)
.then(configure)
.then(resolveConfigure, suite.rejectConfigure);
});
suite.test('picture-mode', function() {
suite.hw.params['preview-size'] = '1x1';
suite.hw.params['picture-size'] = '1x1';
suite.hw.params['preview-size-values'] = '640x480,320x240,1x1';
suite.hw.params['picture-size-values'] = '640x480,320x240,1x1';
suite.hw.params['video-size-values'] = '320x240';
var setConfig = {
mode: 'picture',
previewSize: {
width: 640,
height: 480
}
};
var expConfig = {
mode: 'picture',
recorderProfile: 'qvga',
previewSize: {
width: 640,
height: 480
},
pictureSize: {
width: 640,
height: 480
}
};
return setAndVerifyConfig(setConfig, expConfig);
});
suite.test('picture-mode-larger-picture-size', function() {
suite.hw.params['preview-size'] = '1x1';
suite.hw.params['picture-size'] = '1x1';
suite.hw.params['preview-size-values'] = '640x480,320x240,1x1';
suite.hw.params['picture-size-values'] = '1280x960,640x480,320x240,1x1';
suite.hw.params['video-size-values'] = '320x240';
var setConfig = {
mode: 'picture',
previewSize: {
width: 640,
height: 480
}
};
var expConfig = {
mode: 'picture',
recorderProfile: 'qvga',
previewSize: {
width: 640,
height: 480
},
pictureSize: {
width: 1280,
height: 960
}
};
return setAndVerifyConfig(setConfig, expConfig);
});
suite.test('picture-mode-size-unsupported-big', function() {
suite.hw.params['preview-size'] = '1x1';
suite.hw.params['picture-size'] = '1x1';
suite.hw.params['preview-size-values'] = '640x480,320x240,1x1';
suite.hw.params['picture-size-values'] = '1280x960,640x480,320x240,1x1';
suite.hw.params['video-size-values'] = '320x240';
var setConfig = {
mode: 'picture',
previewSize: {
width: 640,
height: 480
},
pictureSize: {
width: 2000,
height: 2000
},
};
var expConfig = {
mode: 'picture',
recorderProfile: 'qvga',
previewSize: {
width: 640,
height: 480
},
pictureSize: {
width: 1280,
height: 960
},
};
return setAndVerifyConfig(setConfig, expConfig);
});
suite.test('picture-mode-size-unsupported', function() {
suite.hw.params['preview-size'] = '1x1';
suite.hw.params['picture-size'] = '1x1';
suite.hw.params['preview-size-values'] = '640x480,320x240,1x1';
suite.hw.params['picture-size-values'] = '1280x960,640x480,320x240,100x100,1x1';
suite.hw.params['video-size-values'] = '320x240';
var setConfig = {
mode: 'picture',
previewSize: {
width: 640,
height: 480
},
pictureSize: {
width: 641,
height: 481,
},
};
var expConfig = {
mode: 'picture',
recorderProfile: 'qvga',
previewSize: {
width: 640,
height: 480
},
pictureSize: {
width: 640,
height: 480
},
};
return setAndVerifyConfig(setConfig, expConfig);
});
suite.test('picture-mode-asr-mismatch', function() {
suite.hw.params['preview-size'] = '320x240';
suite.hw.params['picture-size'] = '640x480';
suite.hw.params['preview-size-values'] = '640x480,320x240,50x50';
suite.hw.params['picture-size-values'] = '1280x960,640x480,320x240,100x100';
suite.hw.params['video-size-values'] = '320x240';
var setConfig = {
mode: 'picture',
previewSize: {
width: 640,
height: 480
},
pictureSize: {
width: 100,
height: 100,
},
};
var expConfig = {
mode: 'picture',
recorderProfile: 'qvga',
previewSize: {
width: 50,
height: 50
},
pictureSize: {
width: 100,
height: 100,
},
};
return setAndVerifyConfig(setConfig, expConfig);
});
suite.test('picture-mode-update-video-size', function() {
suite.hw.params['preview-size'] = '320x240';
suite.hw.params['picture-size'] = '640x480';
suite.hw.params['video-size'] = '50x50';
suite.hw.params['preview-size-values'] = '640x480,320x240,50x50';
suite.hw.params['video-size-values'] = '1280x960,640x480,320x240,50x50';
suite.hw.params['picture-size-values'] = '1280x960,640x480,320x240,100x100';
var setConfig = {
mode: 'picture',
recorderProfile: 'qvga',
previewSize: {
width: 320,
height: 240
},
pictureSize: {
width: 320,
height: 240,
},
};
var expConfig = {
mode: 'picture',
recorderProfile: 'qvga',
previewSize: {
width: 320,
height: 240
},
pictureSize: {
width: 320,
height: 240,
},
};
function checkVideoSize(p) {
ok(suite.hw.params['video-size'] === '320x240', 'video size reset with picture mode switch');
}
return setAndVerifyConfig(setConfig, expConfig)
.then(checkVideoSize);
});
suite.test('picture-mode-no-update-video-size', function() {
suite.hw.params['preview-size'] = '320x240';
suite.hw.params['picture-size'] = '640x480';
suite.hw.params['video-size'] = '1280x960';
suite.hw.params['preview-size-values'] = '640x480,320x240,50x50';
suite.hw.params['video-size-values'] = '1280x960,640x480,320x240,50x50';
suite.hw.params['picture-size-values'] = '1280x960,640x480,320x240,100x100';
var setConfig = {
mode: 'picture',
recorderProfile: 'qvga',
previewSize: {
width: 640,
height: 480
},
pictureSize: {
width: 640,
height: 480,
},
};
var expConfig = {
mode: 'picture',
recorderProfile: 'qvga',
previewSize: {
width: 640,
height: 480
},
pictureSize: {
width: 640,
height: 480,
},
};
function checkVideoSize(p) {
ok(suite.hw.params['video-size'] === '1280x960', 'video size retained with picture mode switch');
}
return setAndVerifyConfig(setConfig, expConfig)
.then(checkVideoSize);
});
suite.test('video-mode-preview-size', function() {
suite.hw.params['preview-size'] = '1x1';
suite.hw.params['picture-size'] = '1x1';
suite.hw.params['recording-hint'] = 'false';
suite.hw.params['preview-size-values'] = '640x480,320x240,1x1';
suite.hw.params['picture-size-values'] = '700x700,640x480,320x240,1x1';
var setConfig = {
mode: 'video',
recorderProfile: 'qvga'
};
var expConfig = {
mode: 'video',
recorderProfile: 'qvga',
previewSize: {
width: 320,
height: 240
},
pictureSize: {
width: 700,
height: 700
}
};
function checkRecordingHint(p) {
ok(suite.hw.params['recording-hint'] === 'true', 'recording hint enabled');
}
return setAndVerifyConfig(setConfig, expConfig)
.then(checkRecordingHint);
});
suite.test('video-mode', function() {
suite.hw.params['preview-size'] = '1x1';
suite.hw.params['picture-size'] = '1x1';
suite.hw.params['video-size'] = '1x1';
suite.hw.params['recording-hint'] = 'false';
suite.hw.params['preferred-preview-size-for-video'] = '640x480';
suite.hw.params['preview-size-values'] = '640x480,320x240,1x1';
suite.hw.params['picture-size-values'] = '700x700,640x480,320x240,1x1';
suite.hw.params['video-size-values'] = '700x700,640x480,320x240,1x1';
var setConfig = {
mode: 'video',
recorderProfile: 'qvga',
previewSize: {
width: 320,
height: 240
}
};
var expConfig = {
mode: 'video',
recorderProfile: 'qvga',
previewSize: {
width: 320,
height: 240
},
pictureSize: {
width: 700,
height: 700
}
};
function checkRecordingHint(p) {
ok(suite.hw.params['recording-hint'] === 'true', 'recording hint enabled');
}
return setAndVerifyConfig(setConfig, expConfig)
.then(checkRecordingHint);
});
suite.test('video-mode-larger-preview-size', function() {
suite.hw.params['preview-size'] = '1x1';
suite.hw.params['picture-size'] = '1x1';
suite.hw.params['video-size'] = '1x1';
suite.hw.params['recording-hint'] = 'false';
suite.hw.params['preferred-preview-size-for-video'] = '640x480';
suite.hw.params['preview-size-values'] = '640x480,320x240,1x1';
suite.hw.params['picture-size-values'] = '700x700,640x480,320x240,1x1';
suite.hw.params['video-size-values'] = '700x700,640x480,320x240,1x1';
var setConfig = {
mode: 'video',
recorderProfile: 'qvga',
previewSize: {
width: 640,
height: 480
}
};
var expConfig = {
mode: 'video',
recorderProfile: 'qvga',
previewSize: {
width: 320,
height: 240
},
pictureSize: {
width: 700,
height: 700
}
};
return setAndVerifyConfig(setConfig, expConfig);
});
suite.test('video-mode-smaller-preview-size', function() {
suite.hw.params['preview-size'] = '1x1';
suite.hw.params['picture-size'] = '1x1';
suite.hw.params['video-size'] = '1x1';
suite.hw.params['recording-hint'] = 'false';
suite.hw.params['preferred-preview-size-for-video'] = '640x480';
suite.hw.params['preview-size-values'] = '640x480,320x240,160x120,1x1';
suite.hw.params['picture-size-values'] = '700x700,640x480,320x240,1x1';
suite.hw.params['video-size-values'] = '700x700,640x480,320x240,1x1';
var setConfig = {
mode: 'video',
recorderProfile: 'qvga',
previewSize: {
width: 160,
height: 120
}
};
var expConfig = {
mode: 'video',
recorderProfile: 'qvga',
previewSize: {
width: 160,
height: 120
},
pictureSize: {
width: 700,
height: 700
}
};
return setAndVerifyConfig(setConfig, expConfig);
});
suite.test('video-mode-larger-preview-size-than-preferred', function() {
suite.hw.params['preview-size'] = '1x1';
suite.hw.params['picture-size'] = '1x1';
suite.hw.params['video-size'] = '1x1';
suite.hw.params['recording-hint'] = 'false';
suite.hw.params['preferred-preview-size-for-video'] = '200x200';
suite.hw.params['preview-size-values'] = '640x480,320x240,160x120,1x1';
suite.hw.params['picture-size-values'] = '700x700,640x480,320x240,1x1';
suite.hw.params['video-size-values'] = '700x700,640x480,400x400,320x240,1x1';
var setConfig = {
mode: 'video',
recorderProfile: 'qvga',
previewSize: {
width: 320,
height: 240
}
};
var expConfig = {
mode: 'video',
recorderProfile: 'qvga',
previewSize: {
width: 160,
height: 120
},
pictureSize: {
width: 700,
height: 700
}
};
return setAndVerifyConfig(setConfig, expConfig);
});
suite.setup()
.then(suite.run);
</script>
</body>
</html>

View File

@ -92,8 +92,93 @@ function compareFace(aFace, expected)
var suite = new CameraTestSuite();
suite.test('face-detection-op', function() {
function start(p) {
return new Promise(function(resolve, reject) {
suite.hw.attach({
startFaceDetection: function() {
ok(true, "startFaceDetection() requested");
resolve();
}
});
try {
suite.camera.startFaceDetection();
ok(true, "startFaceDetection() succeeded");
} catch(e) {
ok(false, "startFaceDetection() failed with: " + e.name);
resolve();
}
});
}
function stop(p) {
return new Promise(function(resolve, reject) {
suite.hw.attach({
stopFaceDetection: function() {
ok(true, "stopFaceDetection() requested");
resolve();
}
});
try {
suite.camera.stopFaceDetection();
ok(true, "stopFaceDetection() succeeded");
} catch(e) {
ok(false, "stopFaceDetection() failed with: " + e.name);
resolve();
}
});
}
function startFailure(p) {
return new Promise(function(resolve, reject) {
suite.hw.attach({
startFaceDetection: function() {
ok(true, "startFaceDetection() requested and failed");
resolve();
throw SpecialPowers.Cr.NS_ERROR_FAILURE;
}
});
try {
suite.camera.startFaceDetection();
ok(true, "startFaceDetection() succeeded and error swallowed");
} catch(e) {
ok(false, "startFaceDetection() failed with: " + e.name);
resolve();
}
});
}
function stopFailure(p) {
return new Promise(function(resolve, reject) {
suite.hw.attach({
stopFaceDetection: function() {
ok(true, "stopFaceDetection() requested and failed");
resolve();
throw SpecialPowers.Cr.NS_ERROR_FAILURE;
}
});
try {
suite.camera.stopFaceDetection();
ok(true, "stopFaceDetection() succeeded and error swallowed");
} catch(e) {
ok(false, "stopFaceDetection() failed with: " + e.name);
resolve();
}
});
}
return suite.getCamera()
.then(start, suite.rejectGetCamera)
.then(stop)
.then(startFailure)
.then(stopFailure);
});
suite.test('face-detection', function() {
function detectFace(msg, expected) {
function detectFace(msg, given, expected) {
if (expected === undefined) {
expected = given;
}
var sync = new Promise(function(resolve, reject) {
function onEvent(evt) {
try {
@ -108,7 +193,7 @@ suite.test('face-detection', function() {
suite.camera.addEventListener('facesdetected', onEvent);
});
suite.hw.fireFacesDetected(expected);
suite.hw.fireFacesDetected(given);
return sync;
}
@ -220,11 +305,47 @@ suite.test('face-detection', function() {
);
}
function detectOneFaceExcessScore() {
return detectFace('one-face-excess-score',
{
faces: [ {
id: 1,
score: 120,
bounds: {
left: 3,
top: 4,
right: 5,
bottom: 6
},
leftEye: null,
rightEye: null,
mouth: null
} ]
},
{
faces: [ {
id: 1,
score: 100,
bounds: {
left: 3,
top: 4,
right: 5,
bottom: 6
},
leftEye: null,
rightEye: null,
mouth: null
} ]
}
);
}
return suite.getCamera()
.then(detectOneFace, suite.rejectGetCamera)
.then(detectTwoFaces)
.then(detectOneFaceNoFeatures)
.then(detectNoFaces);
.then(detectNoFaces)
.then(detectOneFaceExcessScore);
});
suite.setup()

View File

@ -132,6 +132,133 @@ suite.test('fake-low-memory-platform', function() {
.then(resolve, suite.rejectGetCamera);
});
suite.test('fake-effects', function() {
var supportedValues = ['none', 'mono', 'negative', 'solarize', 'sepia', 'posterize', 'whiteboard', 'blackboard', 'aqua'];
suite.hw.params['effect'] = 'none';
suite.hw.params['effect-values'] = supportedValues.join(',');
function resolve(p) {
var cap = suite.camera.capabilities;
ok(cap.effects.length == supportedValues.length, "Effects length = " + cap.effects.length);
// make sure expected values are present
supportedValues.forEach(function(val) {
ok(cap.effects.indexOf(val) != -1, "Effect '" + val + "' is present");
});
}
return suite.getCamera()
.then(resolve, suite.rejectGetCamera);
});
suite.test('fake-flash-modes', function() {
var supportedValues = ['off', 'auto', 'on', 'red-eye', 'torch'];
suite.hw.params['flash-mode'] = 'auto';
suite.hw.params['flash-mode-values'] = supportedValues.join(',');
function resolve(p) {
var cam = suite.camera;
var cap = cam.capabilities;
ok(cap.flashModes.length == supportedValues.length, "Flash modes length = " + cap.flashModes.length);
// make sure expected values are present
supportedValues.forEach(function(val) {
ok(cap.flashModes.indexOf(val) != -1, "Flash mode '" + val + "' is present");
});
// test setters/getters
cap.flashModes.forEach(function(val, index) {
cam.flashMode = val;
ok(cam.flashMode === val,
"Flash Mode [" + index + "] = " + val + ", cam.flashMode = " + cam.flashMode);
});
}
return suite.getCamera()
.then(resolve, suite.rejectGetCamera);
});
suite.test('fake-focus-modes', function() {
var supportedValues = ['auto', 'infinity', 'macro', 'fixed', 'edof', 'continuous-video'];
suite.hw.params['focus-mode'] = 'auto';
suite.hw.params['focus-mode-values'] = supportedValues.join(',');
function resolve(p) {
var cam = suite.camera;
var cap = cam.capabilities;
ok(cap.focusModes.length == supportedValues.length, "Focus modes length = " + cap.focusModes.length);
// make sure expected values are present
supportedValues.forEach(function(val) {
ok(cap.focusModes.indexOf(val) != -1, "Focus mode '" + val + "' is present");
});
// test setters/getters
cap.focusModes.forEach(function(val, index) {
cam.focusMode = val;
ok(cam.focusMode === val,
"Focus Mode [" + index + "] = " + val + ", cam.focusMode = " + cam.focusMode);
});
}
return suite.getCamera()
.then(resolve, suite.rejectGetCamera);
});
suite.test('fake-white-balance-modes', function() {
var supportedValues = ['auto', 'incandescent', 'fluorescent', 'warm-fluorescent', 'daylight', 'cloudy-daylight', 'twilight', 'shade'];
suite.hw.params['whitebalance'] = 'auto';
suite.hw.params['whitebalance-values'] = supportedValues.join(',');
function resolve(p) {
var cam = suite.camera;
var cap = cam.capabilities;
ok(cap.whiteBalanceModes.length == supportedValues.length, "White balance modes length = " + cap.whiteBalanceModes.length);
// make sure expected values are present
supportedValues.forEach(function(val) {
ok(cap.whiteBalanceModes.indexOf(val) != -1, "White balance mode '" + val + "' is present");
});
// test setters/getters
cap.whiteBalanceModes.forEach(function(val, index) {
cam.whiteBalanceMode = val;
ok(cam.whiteBalanceMode === val,
"White balance mode [" + index + "] = " + val + ", cam.whiteBalanceMode = " + cam.whiteBalanceMode);
});
}
return suite.getCamera()
.then(resolve, suite.rejectGetCamera);
});
suite.test('fake-video-sizes', function() {
var supportedValues = ['auto', 'incandescent', 'fluorescent', 'warm-fluorescent', 'daylight', 'cloudy-daylight', 'twilight', 'shade'];
suite.hw.params['whitebalance'] = 'auto';
suite.hw.params['whitebalance-values'] = supportedValues.join(',');
function resolve(p) {
var cam = suite.camera;
var cap = cam.capabilities;
ok(cap.whiteBalanceModes.length == supportedValues.length, "White balance modes length = " + cap.whiteBalanceModes.length);
// make sure expected values are present
supportedValues.forEach(function(val) {
ok(cap.whiteBalanceModes.indexOf(val) != -1, "White balance mode '" + val + "' is present");
});
// test setters/getters
cap.whiteBalanceModes.forEach(function(val, index) {
cam.whiteBalanceMode = val;
ok(cam.whiteBalanceMode === val,
"White balance mode [" + index + "] = " + val + ", cam.whiteBalanceMode = " + cam.whiteBalanceMode);
});
}
return suite.getCamera()
.then(resolve, suite.rejectGetCamera);
});
suite.test('fake-iso', function() {
suite.hw.params['iso'] = 'auto';
suite.hw.params['iso-values'] = 'auto,ISO_HJR,ISO100,foo,ISObar,ISO150moz,ISO200,400,ISO800,1600';
@ -158,9 +285,9 @@ suite.test('fake-iso', function() {
// test setters/getters for individual ISO modes
cap.isoModes.forEach(function(iso, index) {
cam.iso = iso;
ok(cam.iso === iso,
"ISO[" + index + "] = " + iso + ", cam.iso = " + cam.iso);
cam.isoMode = iso;
ok(cam.isoMode === iso,
"ISO[" + index + "] = " + iso + ", cam.iso = " + cam.isoMode);
});
}
@ -168,6 +295,19 @@ suite.test('fake-iso', function() {
.then(resolve, suite.rejectGetCamera);
});
suite.test('fake-faces-detected', function() {
suite.hw.params['max-num-detected-faces-hw'] = '5';
function resolve(p) {
var cap = suite.camera.capabilities;
ok(cap.maxDetectedFaces == 5, "maxDetectedFaces = " + cap.maxDetectedFaces);
}
return suite.getCamera()
.then(resolve, suite.rejectGetCamera);
});
suite.test('fake-metering-areas', function() {
suite.hw.params['max-num-metering-areas'] = '1';

View File

@ -1,73 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=965421
-->
<head>
<title>Bug 965421 - Test camera hardware API for Auto focus moving Callback</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>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=965421">Mozilla Bug 965421</a>
<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 suite = new CameraTestSuite();
suite.test('auto-focus-moving', function() {
function triggerAutoFocusMoving(p) {
var sync = new Promise(function(resolve, reject) {
function onEvent(e) {
suite.camera.removeEventListener('focus', onEvent);
ok(e.newState === 'focusing', 'autofocus event state focusing == ' + e.newState);
resolve();
}
suite.camera.addEventListener('focus', onEvent);
});
suite.hw.fireAutoFocusMoving(true);
return sync;
}
function waitAutoFocusComplete(p) {
var sync = new Promise(function(resolve, reject) {
function onEvent(e) {
suite.camera.removeEventListener('focus', onEvent);
ok(e.newState === 'focused', 'autofocus event state focused == ' + e.newState);
resolve();
}
suite.camera.addEventListener('focus', onEvent);
});
// Missing the fireAutoFocusComplete but it should timeout on its own
suite.hw.fireAutoFocusMoving(false);
return sync;
}
function runAutoFocusCycle(p) {
return triggerAutoFocusMoving(p)
.then(waitAutoFocusComplete);
}
/* If the driver doesn't supply an onAutoFocusComplete notification,
gecko will timeout and provide it. After three times, it will no
longer rely upon a timeout and fire it immediately. */
return suite.getCamera()
.then(runAutoFocusCycle)
.then(runAutoFocusCycle)
.then(runAutoFocusCycle)
.then(runAutoFocusCycle);
});
suite.setup()
.then(suite.run);
</script>
</body>
</html>

View File

@ -0,0 +1,75 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test Camera Recording</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 suite = new CameraTestSuite();
var baseConfig = {
mode: 'video',
};
var storage = navigator.getDeviceStorage("videos");
suite.test('recording', function() {
storage.delete("test.3gp");
function startRecording(p) {
var eventPromise = new Promise(function(resolve, reject) {
function onEvent(evt) {
ok(evt.newState === 'Started', 'recorder state change event = ' + evt.newState);
suite.camera.removeEventListener('recorderstatechange', onEvent);
resolve();
}
suite.camera.addEventListener('recorderstatechange', onEvent);
});
var domPromise = suite.camera.startRecording({}, storage, "test.3gp");
return Promise.all([domPromise, eventPromise]);
}
function stopRecording(p) {
var eventPromise = new Promise(function(resolve, reject) {
function onEvent(evt) {
ok(evt.newState === 'Stopped', 'recorder state change event = ' + evt.newState);
suite.camera.removeEventListener('recorderstatechange', onEvent);
resolve();
}
suite.camera.addEventListener('recorderstatechange', onEvent);
});
var domPromise = new Promise(function(resolve, reject) {
try {
suite.camera.stopRecording();
resolve();
} catch(e) {
reject(e);
}
});
return Promise.all([domPromise, eventPromise]);
}
return suite.getCamera(undefined, baseConfig)
.then(startRecording, suite.rejectGetCamera)
.then(stopRecording, suite.rejectStartRecording)
.catch(suite.rejectStopRecording);
});
suite.setup()
.then(suite.run);
</script>
</body>
</html>

View File

@ -18,6 +18,39 @@ function cameraRelease(p) {
return suite.camera.release();
}
suite.test('release-close-event', function() {
// bug 1099390
function release(p) {
return new Promise(function(resolve, reject) {
var gotCloseEvent = false;
var gotReleasePromise = false;
var onClosed = function(e) {
suite.camera.removeEventListener('close', onClosed);
ok(!gotCloseEvent, "gotCloseEvent was " + gotCloseEvent);
ok(e.reason === "HardwareReleased", "'close' event reason is: " + e.reason);
gotCloseEvent = true;
if (gotReleasePromise) {
resolve();
}
};
suite.camera.addEventListener('close', onClosed);
suite.camera.release().then(function(p) {
ok(true, "released camera");
gotReleasePromise = true;
if (gotCloseEvent) {
resolve();
}
}).catch(reject);
});
}
return suite.getCamera()
.then(release, suite.rejectGetCamera);
});
suite.test('release-after-release', function() {
return suite.getCamera()
.then(cameraRelease, suite.rejectGetCamera)
@ -157,6 +190,33 @@ suite.test('stop-recording-after-release', function() {
.then(stopRecording, suite.rejectRelease);
});
suite.test('face-detection-after-release', function() {
function startFaceDetection(p) {
try {
suite.camera.startFaceDetection();
ok(false, "startFaceDetection() should have failed");
} catch(e) {
ok(e.result === SpecialPowers.Cr.NS_ERROR_NOT_AVAILABLE,
"startFaceDetection() failed with: " + e.name);
}
}
function stopFaceDetection(p) {
try {
suite.camera.stopFaceDetection();
ok(false, "stopFaceDetection() should have failed");
} catch(e) {
ok(e.result === SpecialPowers.Cr.NS_ERROR_NOT_AVAILABLE,
"stopFaceDetection() failed with: " + e.name);
}
}
return suite.getCamera()
.then(cameraRelease, suite.rejectGetCamera)
.then(startFaceDetection, suite.rejectRelease)
.then(stopFaceDetection);
});
suite.test('set-configuration-after-release', function() {
function configure(p) {
return suite.camera.setConfiguration(null);

View File

@ -0,0 +1,165 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=940424
-->
<head>
<title>Bug 940424 - Test camera hardware API failure handling</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>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=940424">Mozilla Bug 940424</a>
<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 suite = new CameraTestSuite();
suite.test('take-picture-failures', function() {
function startTakePictureProcessError(p) {
suite.hw.attach({
takePicture: function() {
suite.hw.fireTakePictureError();
}
});
return suite.camera.takePicture();
}
function rejectTakePictureProcessError(e) {
ok(e.name === 'NS_ERROR_FAILURE', 'takePicture() process should fail: ' + e);
}
function startTakePictureError(p) {
suite.hw.attach({
takePicture: function() {
throw SpecialPowers.Cr.NS_ERROR_FAILURE;
}
});
return suite.camera.takePicture();
}
function rejectTakePictureError(e) {
ok(e.name === 'NS_ERROR_FAILURE', 'takePicture() should fail: ' + e);
}
return suite.getCamera()
.catch(suite.rejectGetCamera)
.then(startTakePictureProcessError)
.then(suite.expectedRejectTakePicture, rejectTakePictureProcessError)
.then(startTakePictureError)
.then(suite.expectedRejectTakePicture, rejectTakePictureError)
});
suite.test('shutter', function() {
function shutter(p) {
return new Promise(function(resolve, reject) {
function onShutter(e) {
ok(true, 'received shutter event');
suite.camera.removeEventListener('shutter', onShutter);
resolve();
}
suite.camera.addEventListener('shutter', onShutter);
suite.hw.fireShutter();
});
}
return suite.getCamera()
.then(shutter, suite.rejectGetCamera)
});
suite.test('take-picture', function() {
suite.hw.params['picture-format-values'] = 'jpeg,png';
suite.hw.params['picture-format'] = 'jpeg';
var config = {
fileFormat: 'png',
latitude: 1.0,
longitude: 2.0,
altitude: 3.0,
timestamp: 4
};
var data = 'this is a test';
var eventPromise;
function takePicture(p) {
eventPromise = new Promise(function(resolve, reject) {
function onPicture(evt) {
ok(true, 'got picture event');
try {
verifyPicture(evt.data);
} catch(e) {
reject(e);
}
suite.camera.removeEventListener('picture', onPicture);
resolve();
}
suite.camera.addEventListener('picture', onPicture);
});
suite.hw.attach({
takePicture: function() {
ok(suite.hw.params['picture-format'] === 'png', "requested format is '" + suite.hw.params['picture-format'] + "'");
suite.hw.fireTakePictureComplete(new window.Blob([data], {'type': config.fileFormat}));
}
});
return suite.camera.takePicture(config);
}
function verifyPicture(blob) {
ok(blob.size == data.length, "picture blob is " + blob.size + " bytes");
ok(blob.type === 'image/' + config.fileFormat, "picture blob format is '" + blob.type + "'");
}
function tookPicture(p) {
ok(true, 'got picture promise');
verifyPicture(p);
return eventPromise;
}
return suite.getCamera()
.then(takePicture, suite.rejectGetCamera)
.then(tookPicture, suite.rejectTakePicture);
});
suite.test('take-picture-no-config', function() {
var data = 'this is a test';
var format = 'jpeg';
suite.hw.params['picture-format-values'] = 'jpeg,png';
suite.hw.params['picture-format'] = format;
function takePicture(p) {
suite.hw.attach({
takePicture: function() {
ok(suite.hw.params['picture-format'] === format, "requested format is '" + suite.hw.params['picture-format'] + "'");
suite.hw.fireTakePictureComplete(new window.Blob([data], {'type': format}));
}
});
return suite.camera.takePicture();
}
function verifyPicture(blob) {
ok(blob.size == data.length, "picture blob is " + blob.size + " bytes");
ok(blob.type === 'image/' + format, "picture blob format is '" + blob.type + "'");
}
return suite.getCamera()
.then(takePicture, suite.rejectGetCamera)
.then(verifyPicture, suite.rejectTakePicture);
});
suite.setup()
.then(suite.run);
</script>
</body>
</html>