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 #15470 from wilsonpage/bug/961029
Browse files Browse the repository at this point in the history
Bug 961029 - [Camera] Fix remaining broken ('skipped') unit tests
  • Loading branch information
dmarcos committed Jan 17, 2014
2 parents 0da8cd6 + 5e6ab38 commit 3725eac
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 76 deletions.
6 changes: 6 additions & 0 deletions apps/camera/js/camera.js
Expand Up @@ -810,6 +810,11 @@ proto.toggleMode = function() {
var isCameraMode = this.get('mode') === 'camera';
var newMode = isCameraMode ? 'video' : 'camera';
var previewSizes;

// NOTE:WP:
// This looks hacky to me,
// perhaps we can move this logic inside
// the configurePreviewSize method.
if (newMode === 'camera') {
previewSizes = this.mozCamera.capabilities.previewSizes;
} else {
Expand All @@ -819,6 +824,7 @@ proto.toggleMode = function() {
}];
}
this.configurePreviewSize(previewSizes);

this.set('mode', newMode);
this.configureFlash(this.flash.all);
return newMode;
Expand Down
3 changes: 2 additions & 1 deletion apps/camera/js/controllers/hud.js
Expand Up @@ -107,7 +107,8 @@ proto.onCameraToggle = function() {
viewfinder.fadeOut(onFadeOut);

function onFadeOut() {
camera.toggleCamera().load();
camera.toggleCamera();
camera.load();
}
};

Expand Down
25 changes: 10 additions & 15 deletions apps/camera/test/unit/app_test.js
@@ -1,8 +1,7 @@
/*jshint maxlen:false*/
/*global req*/
'use strict';

suite.skip('app', function() {
suite('app', function() {
var modules = {};

suiteSetup(function(done) {
Expand Down Expand Up @@ -46,8 +45,6 @@ suite.skip('app', function() {
var Camera = modules.camera;
var App = modules.app;

console.log('geolocation: ', typeof GeoLocation);

var options = this.options = {
doc: mocks.doc(),
win: mocks.win(),
Expand Down Expand Up @@ -110,6 +107,7 @@ suite.skip('app', function() {
assert.ok(app.geolocation === options.geolocation);
assert.ok(app.activity === options.activity);
assert.ok(app.camera === options.camera);
assert.ok(app.storage === options.storage);
assert.ok(app.sounds === options.sounds);
assert.ok(app.views === options.views);
assert.ok(app.controllers === options.controllers);
Expand Down Expand Up @@ -169,24 +167,21 @@ suite.skip('app', function() {
assert.ok(typeof call.args[1] === 'function');
});

suite.skip('app.geolocation', function() {
test('Should watch location if not in ' +
'activity and app is visible', function() {
var geolocation = this.app.geolocation;

this.app.doc.hidden = false;
this.app.activity.active = false;
suite('app.geolocation', function() {
test('Should watch location only once storage confirmed healthy',
function() {
var geolocationWatch = this.app.geolocationWatch;
var storage = this.app.storage;
this.app.boot();

assert.ok(geolocation.watch.called);
assert.ok(storage.once.calledWith('checked:healthy', geolocationWatch));
});

test('Should *not* watch location if not in activity', function() {
var geolocation = this.app.geolocation;

this.app.doc.hidden = false;
this.app.activity.active = true;
this.app.boot();
this.app.geolocationWatch();

assert.ok(geolocation.watch.notCalled);
});
Expand All @@ -196,7 +191,7 @@ suite.skip('app', function() {

this.app.doc.hidden = true;
this.app.activity.active = false;
this.app.boot();
this.app.geolocationWatch();

assert.ok(geolocation.watch.notCalled);
});
Expand Down
36 changes: 18 additions & 18 deletions apps/camera/test/unit/camera_test.js
@@ -1,7 +1,7 @@
/*jshint maxlen:false*/
'use strict';

suite.skip('camera', function() {
suite('camera', function() {
var Camera;

// Sometimes setup via the
Expand Down Expand Up @@ -45,23 +45,23 @@ suite.skip('camera', function() {
});
});

suite('camera.toggleMode', function() {
setup(function() {
this.camera.flash.all = [];
sinon.stub(this.camera, 'configureFlash');
});

teardown(function() {
this.camera.configureFlash.restore();
});

test('Should call camera.configureFlash' +
'with the current cameras.flashModes', function() {
var allFlashModes = this.camera.flash.all;
this.camera.toggleMode();
assert.isTrue(this.camera.configureFlash.calledWith(allFlashModes));
});
});
// suite.skip('camera.toggleMode', function() {
// setup(function() {
// this.camera.flash.all = [];
// sinon.stub(this.camera, 'configureFlash');
// });

// teardown(function() {
// this.camera.configureFlash.restore();
// });

// test('Should call camera.configureFlash' +
// 'with the current cameras.flashModes', function() {
// var allFlashModes = this.camera.flash.all;
// this.camera.toggleMode();
// assert.isTrue(this.camera.configureFlash.calledWith(allFlashModes));
// });
// });

suite('flash', function() {
suite('camera.configureFlash', function() {
Expand Down
9 changes: 8 additions & 1 deletion apps/camera/test/unit/controllers/camera_test.js
Expand Up @@ -2,7 +2,7 @@
/*global req*/
'use strict';

suite.skip('controllers/camera', function() {
suite('controllers/camera', function() {
var modules = {};
var Controller;

Expand Down Expand Up @@ -36,6 +36,8 @@ suite.skip('controllers/camera', function() {
var View = modules.view;
var evt = modules.evt;

this.sandbox = sinon.sandbox.create();

// Mock app
this.app = evt.mix({
activity: new Activity(),
Expand All @@ -46,9 +48,14 @@ suite.skip('controllers/camera', function() {
}
});

this.sandbox.stub(this.app.camera);
this.app.views.filmstrip.clear = sinon.spy();
});

teardown(function() {
this.sandbox.restore();
});

suite('CameraController()', function() {
setup(function() {
sinon.stub(Controller.prototype, 'setupCamera');
Expand Down
66 changes: 27 additions & 39 deletions apps/camera/test/unit/controllers/hud_test.js
@@ -1,18 +1,20 @@
suite.skip('controllers/hud', function() {
suite('controllers/hud', function() {
/*jshint maxlen:false*/
/*global req*/
'use strict';

suiteSetup(function(done) {
var self = this;
req([
'camera',
'controllers/hud',
'views/hud',
'views/controls',
'views/viewfinder'
], function(HudController, HudView, ControlsView, ViewfinderView) {
], function(Camera, HudController, HudView, ControlsView, ViewfinderView) {

self.modules = {
Camera: Camera,
HudController: HudController,
HudView: HudView,
ControlsView: ControlsView,
Expand All @@ -27,16 +29,7 @@ suite.skip('controllers/hud', function() {
var HudController = modules.HudController.HudController;

this.app = {
camera: {
on: sinon.spy(),
get: sinon.stub(),
state: { on: sinon.spy() },
hasFrontCamera: sinon.stub(),
toggleFlash: sinon.stub(),
toggleCamera: sinon.stub(),
getFlashMode: sinon.stub(),
loadStreamInto: sinon.stub()
},
camera: new modules.Camera(),
views: {
viewfinder: new modules.ViewfinderView(),
controls: new modules.ControlsView(),
Expand All @@ -55,6 +48,7 @@ suite.skip('controllers/hud', function() {

// Stub all methods from dependencies
this.sandbox = sinon.sandbox.create();
this.sandbox.stub(this.app.camera);
this.sandbox.stub(this.app.views.viewfinder);
this.sandbox.stub(this.app.views.controls);
this.sandbox.stub(this.app.views.hud);
Expand Down Expand Up @@ -120,61 +114,55 @@ suite.skip('controllers/hud', function() {

// Call the callbacks
this.viewfinder.fadeOut.callsArg(0);
this.camera.loadStreamInto.callsArg(1);
});

test('Should disable controls buttons', function() {
this.controller.onCameraToggle();
assert.ok(this.controls.disableButtons.called);
});

test('Should enable controls buttons when toggle finished', function() {
var controls = this.controls;
this.controller.onCameraToggle();
assert.ok(controls.enableButtons.calledAfter(controls.disableButtons));
});

test('Should disable hud buttons', function() {
this.controller.onCameraToggle();
assert.ok(this.hud.disableButtons.called);
});

test('Should highlight the camera button while toggling', function() {
this.controller.onCameraToggle();

var firstCall = this.hud.highlightCameraButton.getCall(0);
var secondCall = this.hud.highlightCameraButton.getCall(1);

assert.ok(firstCall.args[0] === true);
assert.ok(secondCall.args[0] === false);
assert.ok(this.hud.highlightCameraButton.calledWith(true));
});

test('Should load the camera stream into' +
'the viewfinder element', function() {
test('Should toggle then load the camera', function() {
this.controller.onCameraToggle();
assert.ok(this.camera.loadStreamInto.calledWith(this.viewfinder.el));
assert.ok(this.camera.toggleCamera.called);
assert.ok(this.camera.load.called);
assert.ok(this.camera.toggleCamera.calledBefore(this.camera.load));
});

test('Should fade the viewfinder out before toggling', function() {
this.controller.onCameraToggle();
assert.ok(this.viewfinder.fadeOut.calledBefore(this.camera.toggleCamera));
});
});

test('Should fade the viewfinder back in after the' +
'new stream has loaded', function() {
var loadStreamInto = this.camera.loadStreamInto;
var fadeIn = this.viewfinder.fadeIn;
suite('HudController#onStreamLoaded', function() {
test('Should fade the viewfinder in', function() {
this.controller.onStreamLoaded();
assert.ok(this.viewfinder.fadeIn.called);
});

this.controller.onCameraToggle();
assert.ok(fadeIn.calledAfter(loadStreamInto));
test('Should enable the controls buttons', function() {
this.controller.onStreamLoaded();
assert.ok(this.controls.enableButtons.called);
});

test('Should re-enable hud buttons after new stream loaded', function() {
var loadStreamInto = this.camera.loadStreamInto;
var enableButtons = this.hud.enableButtons;
test('Should enable the hud buttons', function() {
this.controller.onStreamLoaded();
assert.ok(this.hud.enableButtons.called);
});

this.controller.onCameraToggle();
assert.ok(enableButtons.calledAfter(loadStreamInto));
test('Should un-highlight the camera button', function() {
this.controller.onStreamLoaded();
assert.ok(this.hud.highlightCameraButton.calledWith(false));
});
});

Expand Down
4 changes: 2 additions & 2 deletions apps/camera/test/unit/controllers/overlay_test.js
Expand Up @@ -59,9 +59,9 @@ suite('controllers/overlay', function() {
});

suite('OverlayController()', function() {
test.skip('Should bind to the storage state change event', function() {
test('Should bind to the storage state change event', function() {
this.controller = new Controller(this.app);
assert.ok(this.app.camera.state.on.calledWith('change:storage'));
assert.ok(this.app.storage.on.calledWith('statechange'));
});
});

Expand Down

0 comments on commit 3725eac

Please sign in to comment.