Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an error message when setting wrong value for the property element of a component #1964

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
8 changes: 6 additions & 2 deletions core/gate.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,13 @@ var Gate = exports.Gate = Montage.specialize(/** @lends Gate.prototype # */ {
i,
iField,
result = "";
for (i = 0; (iField = fieldNames[i]); i++) {
result += iField + "[" + (this._value & fieldNames[iField]) + "], ";

if (fieldNames) {
for (i = 0; (iField = fieldNames[i]); i++) {
result += iField + "[" + (this._value & fieldNames[iField]) + "], ";
}
}

return result;
}
}
Expand Down
39 changes: 5 additions & 34 deletions core/media-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,14 @@ var MediaController = exports.MediaController = Target.specialize(/** @lends Med
}
},

_duration: {
value: null
},

/**
* @type {Function}
* @default null
*/
duration: {
set: function (time) {
if (isNaN(time)) {
if (logger.isDebug) {
logger.debug("MediaController:setDuration: duration is not valid");
}
return;
}
if (logger.isDebug) {
logger.debug("MediaController:setDuration: duration=" + time);
}
this._duration = time;
},
get: function () {
return this._duration;
return !isNaN(this._mediaElement.duration) ?
this._mediaElement.duration : null;
}
},

Expand Down Expand Up @@ -248,7 +233,8 @@ var MediaController = exports.MediaController = Target.specialize(/** @lends Med
return this._playbackRate;
},
set: function (playbackRate) {
if (this._playbackRate !== playbackRate) {
// playbackRate can't be negative
if (this._playbackRate !== playbackRate && playbackRate > 0) {
this._playbackRate = playbackRate;
this._mediaElement.playbackRate = this._playbackRate;
}
Expand Down Expand Up @@ -300,21 +286,6 @@ var MediaController = exports.MediaController = Target.specialize(/** @lends Med
}
},

/**
* @function
*/
rewind: {
value: function () {
if (this.status === this.PLAYING) {
if (logger.isDebug) {
logger.debug("MediaController:rewind()");
}

this.playbackRate = -4.0;
}
}
},

/**
* @function
*/
Expand Down Expand Up @@ -438,7 +409,7 @@ var MediaController = exports.MediaController = Target.specialize(/** @lends Med
}
return;
}
this.duration = this._mediaElement.duration;

if (this.autoplay) {
if (logger.isDebug) {
logger.debug("MediaController:handleLoadedmetadata: autoplay");
Expand Down
32 changes: 17 additions & 15 deletions test/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,23 @@ module.exports = require("montage-testing").run(require, [
{name: "spec/core/media-controller-spec", node: false},
{name: "spec/core/radio-button-controller-spec", node: false},
// Base
{name: "spec/base/abstract-control-spec", node: false},
{name: "spec/base/abstract-alert-spec", node: false},
{name: "spec/base/abstract-button-spec", node: false},
{name: "spec/base/abstract-checkbox-spec", node: false},
{name: "spec/base/abstract-confirm-spec", node: false},
{name: "spec/base/abstract-image-spec", node: false, karma: false},
{name: "spec/base/abstract-link-spec", node: false},
{name: "spec/base/abstract-number-field-spec", node: false},
{name: "spec/base/abstract-radio-button-spec", node: false},
{name: "spec/base/abstract-select-spec", node: false},
{name: "spec/base/abstract-slider-spec", node: false},
{name: "spec/base/abstract-text-area-spec", node: false},
{name: "spec/base/abstract-text-field-spec", node: false},
{name: "spec/base/abstract-toggle-button-spec", node: false},
{name: "spec/base/abstract-video-spec", node: false},

// Should be removed once the base components will be ported to control components.
// {name: "spec/base/abstract-control-spec", node: false},
// {name: "spec/base/abstract-alert-spec", node: false},
// {name: "spec/base/abstract-button-spec", node: false},
// {name: "spec/base/abstract-checkbox-spec", node: false},
// {name: "spec/base/abstract-confirm-spec", node: false},
// {name: "spec/base/abstract-image-spec", node: false, karma: false},
// {name: "spec/base/abstract-link-spec", node: false},
// {name: "spec/base/abstract-number-field-spec", node: false},
// {name: "spec/base/abstract-radio-button-spec", node: false},
// {name: "spec/base/abstract-select-spec", node: false},
// {name: "spec/base/abstract-slider-spec", node: false},
// {name: "spec/base/abstract-text-area-spec", node: false},
// {name: "spec/base/abstract-text-field-spec", node: false},
// {name: "spec/base/abstract-toggle-button-spec", node: false},
// {name: "spec/base/abstract-video-spec", node: false},
// Composer
{name: "spec/composer/composer-spec", node: false, karma: false},
{name: "spec/composer/press-composer-spec", node: false, karma: false},
Expand Down
Binary file added test/assets/sample.mp4
Binary file not shown.
5 changes: 0 additions & 5 deletions test/spec/core/extras/url.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
var Montage = require("montage").Montage,
URL = require("montage/core/mini-url");

/*
var MockDOM = require("mocks/dom"),
_document = MockDOM.document();
*/
// TODO MockDOM
var _document = document;

describe("core/extras/url", function () {
Expand Down
138 changes: 66 additions & 72 deletions test/spec/core/media-controller-spec.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
var Montage = require("montage").Montage,
MediaController = require("montage/core/media-controller").MediaController,
MockDOM = require("mocks/dom"),
MockEvent = require("mocks/event");
MediaController = require("montage/core/media-controller").MediaController;

describe("core/media-controller-spec", function () {

var aMediaController,
var aMediaController, MediaControllerReadyPromise,
mediaElement;

beforeEach(function () {
aMediaController = new MediaController();
mediaElement = MockDOM.element();
mediaElement = document.createElement('video');
mediaElement.muted = false;
mediaElement.src = 'assets/sample.mp4';
mediaElement.currentTime = 0;
mediaElement.volume = 1;
mediaElement.duration = 200;
mediaElement.play = Function.noop;
mediaElement.pause = Function.noop;
mediaElement.stop = Function.noop;

MediaControllerReadyPromise = new Promise (function (resolve, reject) {
var oldHandleLoadedmetadata = aMediaController.handleLoadedmetadata;

aMediaController.handleLoadedmetadata = function (event) {
oldHandleLoadedmetadata.call(aMediaController, event);
resolve();
};
});

aMediaController.mediaElement = mediaElement;
});

Expand All @@ -41,22 +47,20 @@ describe("core/media-controller-spec", function () {
aMediaController.playbackRate = 0.5;
expect(aMediaController.playbackRate).toEqual(0.5);
});

it("can be negative", function () {
aMediaController.playbackRate = -0.5;
expect(aMediaController.playbackRate).toEqual(-0.5);
});
});

describe("currentTime", function () {
it("should have correct default value", function () {
expect(aMediaController.currentTime).toEqual(0);
});

it("can be set", function () {
aMediaController.status = aMediaController.PLAYING;
aMediaController.currentTime = 142;
expect(aMediaController.currentTime).toEqual(142);
it("can be set", function (done) {
return MediaControllerReadyPromise.then(function () {
aMediaController.status = aMediaController.PLAYING;
aMediaController.currentTime = 2;
expect(aMediaController.currentTime).toEqual(2);
done();
});
});

it("can not be set when status is EMPTY", function () {
Expand All @@ -71,9 +75,11 @@ describe("core/media-controller-spec", function () {
expect(aMediaController.duration).toBeNull();
});

it("can be set", function () {
aMediaController.duration = 5256;
expect(aMediaController.duration).toEqual(5256);
it("should have correct value once metadaloaded", function (done) {
return MediaControllerReadyPromise.then(function () {
expect(aMediaController.duration).not.toBeNull();
done();
});
});
});

Expand Down Expand Up @@ -166,23 +172,6 @@ describe("core/media-controller-spec", function () {
});
});

describe("rewind", function () {
it("should set playback rate to -4.0 when playing", function () {
aMediaController.playbackRate = 1.0;
aMediaController.status = aMediaController.PLAYING;
aMediaController.rewind();
expect(aMediaController.playbackRate).toEqual(-4.0);
});

it("should not change playback rate if not playing", function () {
aMediaController.playbackRate = 1.0;
aMediaController.status = aMediaController.STOPPED;
aMediaController.rewind();
expect(aMediaController.playbackRate).toEqual(1.0);
});

});

describe("fastForward", function () {
it("should set playback rate to 4.0 when playing", function () {
aMediaController.playbackRate = 1.0;
Expand Down Expand Up @@ -249,59 +238,64 @@ describe("core/media-controller-spec", function () {
describe("events", function () {

describe("loadedmetadata", function () {
var anEvent;

beforeEach(function () {
anEvent = MockEvent.event("loadedmetadata", true, true, null);
});

it("should set status to STOPPED", function () {
it("should set status to STOPPED", function (done) {
aMediaController.status = aMediaController.EMPTY;
mediaElement.dispatchEvent(anEvent);
expect(aMediaController.status).toEqual(aMediaController.STOPPED);

return MediaControllerReadyPromise.then(function () {
expect(aMediaController.status).toEqual(aMediaController.STOPPED);
done();
});
});

it("should start playing if autoplay=true", function () {
it("should start playing if autoplay=true", function (done) {
var wasCalled = false;
aMediaController.play = function () {
wasCalled = true;
};

aMediaController.autoplay = true;

mediaElement.dispatchEvent(anEvent);
expect(wasCalled).toEqual(true);
return MediaControllerReadyPromise.then(function () {
expect(wasCalled).toEqual(true);
done();
});
});
});

describe("timeupdate", function () {
var anEvent;

beforeEach(function () {
anEvent = MockEvent.event("timeupdate", true, true, null);
});

it("should update the position value", function () {
aMediaController.status = aMediaController.PLAYING;
aMediaController.position = 26;
aMediaController.currentTime = 34;
mediaElement.dispatchEvent(anEvent);
expect(aMediaController.position).toEqual(34);
});

it("should not update the position value if stopped", function () {
aMediaController.position = 26;
aMediaController.status = aMediaController.STOPPED;
aMediaController.currentTime = 34;
mediaElement.dispatchEvent(anEvent);
expect(aMediaController.position).toEqual(26);
anEvent = new Event('timeupdate');
});

it("should update the position value", function (done) {
return MediaControllerReadyPromise.then(function () {
aMediaController.status = aMediaController.PLAYING;
aMediaController.position = 2;
aMediaController.currentTime = 3;
mediaElement.dispatchEvent(anEvent);
expect(aMediaController.position).toEqual(3);
done();
});
});

it("should not update the position value if stopped", function (done) {
return MediaControllerReadyPromise.then(function () {
aMediaController.position = 2;
aMediaController.status = aMediaController.STOPPED;
aMediaController.currentTime = 3;
mediaElement.dispatchEvent(anEvent);
expect(aMediaController.position).toEqual(2);
done();
});
});
});

describe("play", function () {
it("should set the status to PLAYING", function () {
aMediaController.status = aMediaController.EMPTY;
var anEvent = MockEvent.event("play", true, true, null);
var anEvent = new Event('play');

mediaElement.dispatchEvent(anEvent);
expect(aMediaController.status).toEqual(aMediaController.PLAYING);
Expand All @@ -311,7 +305,7 @@ describe("core/media-controller-spec", function () {
describe("playing", function () {
it("should set the status to PLAYING", function () {
aMediaController.status = aMediaController.EMPTY;
var anEvent = MockEvent.event("playing", true, true, null);
var anEvent = new Event('playing');

mediaElement.dispatchEvent(anEvent);
expect(aMediaController.status).toEqual(aMediaController.PLAYING);
Expand All @@ -322,7 +316,7 @@ describe("core/media-controller-spec", function () {
var anEvent;

beforeEach(function () {
anEvent = MockEvent.event("pause", true, true, null);
anEvent = new Event('pause');
});

it("should set the status to PAUSED", function () {
Expand All @@ -341,7 +335,7 @@ describe("core/media-controller-spec", function () {
describe("abort", function () {
it("should set the status to STOPPED", function () {
aMediaController.status = aMediaController.EMPTY;
var anEvent = MockEvent.event("abort", true, true, null);
var anEvent = new Event('abort');

mediaElement.dispatchEvent(anEvent);
expect(aMediaController.status).toEqual(aMediaController.STOPPED);
Expand All @@ -351,7 +345,7 @@ describe("core/media-controller-spec", function () {
describe("error", function () {
it("should set the status to STOPPED", function () {
aMediaController.status = aMediaController.EMPTY;
var anEvent = MockEvent.event("error", true, true, null);
var anEvent = new Event('error');

mediaElement.dispatchEvent(anEvent);
expect(aMediaController.status).toEqual(aMediaController.STOPPED);
Expand All @@ -360,7 +354,7 @@ describe("core/media-controller-spec", function () {

describe("emptied", function () {
it("should set the status to STOPPED", function () {
var anEvent = MockEvent.event("emptied", true, true, null);
var anEvent = new Event("emptied");
aMediaController.status = aMediaController.EMPTY;

mediaElement.dispatchEvent(anEvent);
Expand All @@ -370,7 +364,7 @@ describe("core/media-controller-spec", function () {

describe("ended", function () {
it("should set the status to STOPPED", function () {
var anEvent = MockEvent.event("ended", true, true, null);
var anEvent = new Event("ended");
aMediaController.status = aMediaController.EMPTY;

mediaElement.dispatchEvent(anEvent);
Expand Down
Loading