Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #24427 from wilsonpage/1069200-v2.0
Browse files Browse the repository at this point in the history
Bug 1069200 - [Camera]Rapidly click take button and switch picture/video mode
  • Loading branch information
rvandermeulen committed Oct 3, 2014
2 parents fa79785 + aa6e1fa commit 092d2b7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
4 changes: 2 additions & 2 deletions apps/camera/js/config/config.js
Expand Up @@ -118,8 +118,8 @@ module.exports = {
},

loadingScreen: {
takingPicture: 1500,
requestingCamera: 600,
takingPicture: 1650,
requestingCamera: 750,
loadingVideo: 100
},

Expand Down
14 changes: 12 additions & 2 deletions apps/camera/js/lib/camera/camera.js
Expand Up @@ -388,6 +388,11 @@ Camera.prototype.configure = function() {
return;
}

// In some extreme cases the mode can
// get changed and configured whilst
// video recording is in progress.
this.stopRecording();

// Indicate 'busy'
this.busy();

Expand Down Expand Up @@ -1407,6 +1412,7 @@ Camera.prototype.busy = function(type) {
debug('busy %s', type || '');
this.isBusy = true;
this.emit('busy', type);
clearTimeout(this.readyTimeout);
};

/**
Expand All @@ -1416,9 +1422,13 @@ Camera.prototype.busy = function(type) {
* @private
*/
Camera.prototype.ready = function() {
debug('ready');
var self = this;
this.isBusy = false;
this.emit('ready');
clearTimeout(this.readyTimeout);
this.readyTimeout = setTimeout(function() {
debug('ready');
self.emit('ready');
}, 150);
};

});
47 changes: 32 additions & 15 deletions apps/camera/test/unit/lib/camera/camera_test.js
Expand Up @@ -60,6 +60,7 @@ suite('lib/camera/camera', function() {
this.storage = this.options.storage;
this.camera = new this.Camera(this.options);
this.sandbox.spy(this.camera, 'ready');
this.sandbox.spy(this.camera, 'busy');
this.sandbox.spy(this.camera, 'emit');
this.sandbox.spy(this.camera, 'once');
});
Expand Down Expand Up @@ -616,11 +617,10 @@ suite('lib/camera/camera', function() {

suite('Camera#onPreviewStateChange()', function() {
setup(function() {
this.camera = new this.Camera();
sinon.stub(this.camera, 'emit');

});

test('Should fire \'busy\' event if \'stopped\' or \'paused\'', function() {
test('It fires \'busy\' event if \'stopped\' or \'paused\'', function() {
this.camera.onPreviewStateChange('stopped');
assert.ok(this.camera.emit.calledWith('busy'));
this.camera.emit.reset();
Expand All @@ -629,13 +629,13 @@ suite('lib/camera/camera', function() {
assert.ok(this.camera.emit.calledWith('busy'));
});

test('Should not fire \'ready\' event for all other states', function() {
test('It fires \'ready\' event for all other states', function() {
this.camera.onPreviewStateChange('something else');
assert.ok(this.camera.emit.calledWith('ready'));
this.camera.emit.reset();
sinon.assert.called(this.camera.ready);
this.camera.ready.reset();

this.camera.onPreviewStateChange('other');
assert.ok(this.camera.emit.calledWith('ready'));
sinon.assert.called(this.camera.ready);
});
});

Expand Down Expand Up @@ -737,11 +737,10 @@ suite('lib/camera/camera', function() {
this.camera.selectedCamera = 'back';
});

test('Should emit a \'busy\', then \'ready\' event', function(done) {
navigator.mozCameras.getCamera.callsArgWithAsync(2, this.mozCamera);
test('Should emit a \'busy\', then \'ready\' event', function() {
navigator.mozCameras.getCamera.callsArgWith(2, this.mozCamera);
this.camera.requestCamera();
sinon.assert.calledWith(this.camera.emit, 'busy');
this.camera.on('ready', done);
assert.isTrue(this.camera.busy.calledBefore(this.camera.ready));
});

test('Should call `navigator.mozCameras.getCamera()` with currently selected camera', function() {
Expand Down Expand Up @@ -873,7 +872,7 @@ suite('lib/camera/camera', function() {
sinon.assert.notCalled(this.mozCamera.setConfiguration);

this.camera.ready();
this.clock.tick(1);
this.clock.tick(151);

sinon.assert.called(this.mozCamera.setConfiguration);
sinon.assert.calledWith(this.camera.emit, 'configured');
Expand All @@ -893,7 +892,6 @@ suite('lib/camera/camera', function() {
});

test('Should flag as busy, then ready', function() {
var self = this;

// Use async for this case
this.mozCamera.setConfiguration = sinon.stub();
Expand All @@ -910,8 +908,8 @@ suite('lib/camera/camera', function() {
// Manually call the callback
onSuccess();

assert.isFalse(self.camera.isBusy);
sinon.assert.calledWith(self.camera.emit, 'ready');
assert.isFalse(this.camera.isBusy);
sinon.assert.called(this.camera.ready);
});

test('Should abort if `mozCamera` has since been released', function() {
Expand All @@ -930,6 +928,13 @@ suite('lib/camera/camera', function() {

assert.isFalse(this.camera.emit.calledWith('configured'));
});

test('It stops any recording that make be in progress', function() {
sinon.stub(this.camera, 'stopRecording');
this.camera.configure();
this.clock.tick(1);
sinon.assert.called(this.camera.stopRecording);
});
});

suite('Camera#release()', function() {
Expand Down Expand Up @@ -1204,4 +1209,16 @@ suite('lib/camera/camera', function() {
sinon.assert.called(this.camera.setThumbnailSize);
});
});

suite('Camera#busy()', function() {
setup(function() {
this.camera.readyTimeout = '<ready-timeout>';
this.sandbox.stub(window, 'clearTimeout');
});

test('It clears the ready timeout', function() {
this.camera.busy();
sinon.assert.calledWith(window.clearTimeout, '<ready-timeout>');
});
});
});

0 comments on commit 092d2b7

Please sign in to comment.