Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
1256
gaia/distros/spark/apps/customizer/components/observe-utils/test/List.js
Executable file
1256
gaia/distros/spark/apps/customizer/components/observe-utils/test/List.js
Executable file
File diff suppressed because it is too large
Load diff
57
gaia/distros/spark/apps/customizer/components/observe-utils/test/bug.js
Executable file
57
gaia/distros/spark/apps/customizer/components/observe-utils/test/bug.js
Executable file
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright 2012 Kap IT (http://www.kapit.fr/)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the 'License');
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an 'AS IS' BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Author : François de Campredon (http://francois.de-campredon.fr/),
|
||||
|
||||
/*global describe, it, sinon, expect, beforeEach, ObserveUtils */
|
||||
|
||||
|
||||
describe('observer-utils bugs', function () {
|
||||
'use strict';
|
||||
|
||||
var List = ObserveUtils.List;
|
||||
|
||||
var list, notifySpy;
|
||||
beforeEach(function () {
|
||||
list = List(1, 2);
|
||||
var notifier = Object.getNotifier(list);
|
||||
notifySpy = notifier.notify = sinon.spy();
|
||||
});
|
||||
|
||||
function getNotifiedChangesRecords() {
|
||||
return notifySpy.args.map(function (arr) {
|
||||
return arr[0];
|
||||
});
|
||||
}
|
||||
|
||||
function getNotifiedChangesRecordsWithoutSplice() {
|
||||
return getNotifiedChangesRecords().filter(function (record) {
|
||||
return record.type !== 'splice';
|
||||
});
|
||||
}
|
||||
|
||||
// issues #1 (https://github.com/KapIT/observe-utils/issues/1)
|
||||
it('Method like unshift create change records for index that does not have change', function () {
|
||||
list.unshift(1);
|
||||
expect(getNotifiedChangesRecordsWithoutSplice()).to.be.eql([
|
||||
{type: 'update', name: '1', oldValue: 2},
|
||||
{type: 'add', name: '2'},
|
||||
{type: 'update', name: 'length', oldValue: 2}
|
||||
]);
|
||||
});
|
||||
|
||||
it('Method like splice create change records for index that does not have change', function () {
|
||||
list.splice(0, 1, 1);
|
||||
expect(getNotifiedChangesRecordsWithoutSplice()).to.be.eql([]);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,181 @@
|
|||
/*global ObserveUtils, describe, it, expect , sinon*/
|
||||
|
||||
describe('defineObservableProperties', function () {
|
||||
'use strict';
|
||||
|
||||
function getPropertyDescriptor(target, name) {
|
||||
var pd = Object.getOwnPropertyDescriptor(target, name);
|
||||
var proto = Object.getPrototypeOf(target);
|
||||
while (typeof pd === 'undefined' && proto !== null) {
|
||||
pd = Object.getOwnPropertyDescriptor(proto, name);
|
||||
proto = Object.getPrototypeOf(proto);
|
||||
}
|
||||
return pd;
|
||||
}
|
||||
|
||||
function testIsObject(testFunc) {
|
||||
expect(function () {
|
||||
testFunc(5);
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
testFunc('string');
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
testFunc(NaN);
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
testFunc(null);
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
testFunc(undefined);
|
||||
}).to.throwException(function (e) {
|
||||
expect(e).to.be.a(TypeError);
|
||||
});
|
||||
|
||||
expect(function () {
|
||||
testFunc({});
|
||||
}).to.not.throwException();
|
||||
|
||||
expect(function () {
|
||||
testFunc(function () {});
|
||||
}).to.not.throwException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
it('should throw an error when passing an non object at first parameter', function () {
|
||||
testIsObject(function (target) {
|
||||
ObserveUtils.defineObservableProperties(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('should define getter/setter on object', function () {
|
||||
var object = {};
|
||||
|
||||
ObserveUtils.defineObservableProperties(object, 'property');
|
||||
expect(object).to.have.property('property');
|
||||
|
||||
var descriptor = Object.getOwnPropertyDescriptor(object, 'property');
|
||||
expect(descriptor).to.have.property('get');
|
||||
expect(descriptor).to.have.property('set');
|
||||
});
|
||||
|
||||
it('should define multiple property on rest parameter', function () {
|
||||
var object = {};
|
||||
ObserveUtils.defineObservableProperties(object, 'property', 'property1', 'property2');
|
||||
|
||||
expect(object).to.have.property('property');
|
||||
expect(object).to.have.property('property1');
|
||||
expect(object).to.have.property('property2');
|
||||
});
|
||||
|
||||
|
||||
it('should conserve the original value', function () {
|
||||
var value = {};
|
||||
var object = {property: value};
|
||||
ObserveUtils.defineObservableProperties(object, 'property');
|
||||
|
||||
expect(object.property).to.be.equal(value);
|
||||
});
|
||||
|
||||
it('should not redefine property with getter/setter', function () {
|
||||
|
||||
var getter = function () {
|
||||
};
|
||||
var setter = function () {
|
||||
};
|
||||
|
||||
var object = {};
|
||||
Object.defineProperty(object, 'property', {
|
||||
get: getter,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
|
||||
ObserveUtils.defineObservableProperties(object, 'property');
|
||||
expect(Object.getOwnPropertyDescriptor(object, 'property').get).to.be.equal(getter);
|
||||
|
||||
var object1 = {};
|
||||
Object.defineProperty(object1, 'property', {
|
||||
set: setter,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
expect(Object.getOwnPropertyDescriptor(object1, 'property').set).to.be.equal(setter);
|
||||
});
|
||||
|
||||
it('should not redefine property with getter/setter defined in the prototype chain', function () {
|
||||
|
||||
var getter = function () {
|
||||
};
|
||||
var proto = {};
|
||||
|
||||
Object.defineProperty(proto, 'property', {
|
||||
get: getter,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
|
||||
var object = Object.create(proto);
|
||||
|
||||
expect(Object.getOwnPropertyDescriptor(object, 'property')).to.be.equal(undefined);
|
||||
expect(getPropertyDescriptor(object, 'property').get).to.be.equal(getter);
|
||||
});
|
||||
|
||||
|
||||
it('should not define other enumerable property', function () {
|
||||
|
||||
var object = {};
|
||||
|
||||
ObserveUtils.defineObservableProperties(object, 'property');
|
||||
expect(object).to.be.eql({property: undefined});
|
||||
|
||||
});
|
||||
|
||||
it('should define property that notify when they are updated', function () {
|
||||
|
||||
var object = {},
|
||||
notifier = Object.getNotifier(object);
|
||||
notifier.notify = sinon.spy();
|
||||
ObserveUtils.defineObservableProperties(object, 'property');
|
||||
object.property = 5;
|
||||
|
||||
expect(notifier.notify.calledOnce).to.be.ok();
|
||||
expect(notifier.notify.args[0][0]).to.be.eql({
|
||||
type: 'update',
|
||||
name: 'property',
|
||||
oldValue: undefined
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
it('should define property that notify when they are updated, only if value has changed', function () {
|
||||
var object = {},
|
||||
notifier = Object.getNotifier(object);
|
||||
notifier.notify = sinon.spy();
|
||||
ObserveUtils.defineObservableProperties(object, 'property');
|
||||
object.property = 5;
|
||||
object.property = 5;
|
||||
|
||||
expect(notifier.notify.calledOnce).to.be.ok();
|
||||
expect(notifier.notify.args[0][0]).to.be.eql({
|
||||
type: 'update',
|
||||
name: 'property',
|
||||
oldValue: undefined
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
29
gaia/distros/spark/apps/customizer/components/observe-utils/test/index.html
Executable file
29
gaia/distros/spark/apps/customizer/components/observe-utils/test/index.html
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="../components/mocha/mocha.css" type="text/css" >
|
||||
|
||||
<script type="text/javascript" src="../components/expect/expect.js" ></script>
|
||||
<script type="text/javascript" src="../components/mocha/mocha.js" ></script>
|
||||
<script type="text/javascript" src="../components/sinon/index.js" ></script>
|
||||
<script type="text/javascript" src="../components/es5-shim/es5-shim.js"></script>
|
||||
<script type="text/javascript" src="../components/observe-shim/lib/observe-shim.js" ></script>
|
||||
<script type="text/javascript" src="../lib/observe-utils.js" ></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script type="text/javascript">
|
||||
mocha.setup("bdd");
|
||||
</script>
|
||||
<script src="defineObservableProperties.js" type="text/javascript"></script>
|
||||
<script src="List.js" type="text/javascript"></script>
|
||||
<script src="bug.js" type="text/javascript" ></script>
|
||||
<script type="text/javascript" >
|
||||
if ( typeof window.PHANTOMJS === "undefined") {
|
||||
mocha.run();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
// exported expect, sinon
|
||||
|
||||
global.expect = require('expect.js');
|
||||
global.sinon = require('sinon');
|
||||
require('observe-shim');
|
||||
global.ObserveUtils = require('../lib/observe-utils');
|
||||
require('./defineObservableProperties');
|
||||
require('./list');
|
||||
require('./bug');
|
||||
Loading…
Reference in a new issue