mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 18:42:40 +08:00
Merge branch 'master' of github.com:fireball-x/engine
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
test('CallbacksInvoker', function () {
|
||||
module('CallbacksInvoker');
|
||||
|
||||
test('test', function () {
|
||||
var ci = new cc._Test.CallbacksInvoker();
|
||||
|
||||
var cb1 = new Callback();
|
||||
@@ -41,6 +43,100 @@ test('CallbacksInvoker', function () {
|
||||
ci.invoke('a');
|
||||
});
|
||||
|
||||
test('remove self during invoking', function () {
|
||||
var ci = new cc._Test.CallbacksInvoker();
|
||||
var cb1 = new Callback(function () {
|
||||
ci.remove('eve', cb1);
|
||||
}).enable();
|
||||
var cb2 = new Callback().enable();
|
||||
|
||||
ci.add('eve', cb1);
|
||||
ci.add('eve', cb2);
|
||||
ci.invoke('eve');
|
||||
cb2.once('it should be called correctly if previous callback deregistered itself');
|
||||
|
||||
cb1.disable('should not call after removed');
|
||||
ci.invoke('eve');
|
||||
});
|
||||
|
||||
test('remove self with target during invoking', function () {
|
||||
var ci = new cc._Test.CallbacksInvoker();
|
||||
var cb1 = new Callback(function () {
|
||||
ci.remove('eve', cb1, target);
|
||||
}).enable();
|
||||
var cb2 = new Callback().enable();
|
||||
var target = {};
|
||||
|
||||
ci.add('eve', cb1, target);
|
||||
ci.add('eve', cb2, target);
|
||||
ci.invoke('eve');
|
||||
cb2.once('it should be called correctly if previous callback deregistered itself');
|
||||
|
||||
cb1.disable('should not call after removed');
|
||||
ci.invoke('eve');
|
||||
});
|
||||
|
||||
test('remove previous during invoking', function () {
|
||||
var ci = new cc._Test.CallbacksInvoker();
|
||||
var cb1 = new Callback().enable();
|
||||
var cb2 = new Callback(function () {
|
||||
ci.remove('eve', cb1);
|
||||
}).enable();
|
||||
|
||||
ci.add('eve', cb1);
|
||||
ci.add('eve', cb2);
|
||||
ci.invoke('eve');
|
||||
|
||||
strictEqual(ci.has('eve', cb1), false, 'previous callback should be removed');
|
||||
strictEqual(ci.has('eve', cb2), true, 'self callback should not be removed');
|
||||
});
|
||||
|
||||
test('remove previous with target during invoking', function () {
|
||||
var ci = new cc._Test.CallbacksInvoker();
|
||||
var cb1 = new Callback().enable();
|
||||
var cb2 = new Callback(function () {
|
||||
ci.remove('eve', cb1, target);
|
||||
}).enable();
|
||||
var target = {};
|
||||
|
||||
ci.add('eve', cb1, target);
|
||||
ci.add('eve', cb2, target);
|
||||
ci.invoke('eve');
|
||||
|
||||
strictEqual(ci.has('eve', cb1, target), false, 'previous callback should be removed');
|
||||
strictEqual(ci.has('eve', cb2, target), true, 'self callback should not be removed');
|
||||
});
|
||||
|
||||
test('remove last during invoking', function () {
|
||||
var ci = new cc._Test.CallbacksInvoker();
|
||||
var cb1 = new Callback().enable();
|
||||
var cb2 = new Callback(function () {
|
||||
ci.remove('eve', cb2);
|
||||
}).enable();
|
||||
|
||||
ci.add('eve', cb1);
|
||||
ci.add('eve', cb2);
|
||||
ci.invoke('eve');
|
||||
|
||||
strictEqual(ci.has('eve', cb1), true, 'previous callback should not be removed');
|
||||
strictEqual(ci.has('eve', cb2), false, 'self callback should be removed');
|
||||
});
|
||||
|
||||
test('remove last with target during invoking', function () {
|
||||
var ci = new cc._Test.CallbacksInvoker();
|
||||
var cb1 = new Callback().enable();
|
||||
var cb2 = new Callback(function () {
|
||||
ci.remove('eve', cb2, target);
|
||||
}).enable();
|
||||
var target = {};
|
||||
ci.add('eve', cb1, target);
|
||||
ci.add('eve', cb2, target);
|
||||
ci.invoke('eve');
|
||||
|
||||
strictEqual(ci.has('eve', cb1, target), true, 'previous callback should not be removed');
|
||||
strictEqual(ci.has('eve', cb2, target), false, 'self callback should be removed');
|
||||
});
|
||||
|
||||
test('CallbacksInvoker support target', function () {
|
||||
var ci = new cc._Test.CallbacksInvoker();
|
||||
var cb1 = function () {
|
||||
|
||||
@@ -11,18 +11,11 @@ asyncTest('basic test', function () {
|
||||
|
||||
deepEqual(render._sgNode.color, Color.RED, 'color set success');
|
||||
|
||||
var texture = new cc.Texture2D();
|
||||
texture.url = url;
|
||||
cc.loader.load(texture.url, function (err) {
|
||||
texture.handleLoadedTexture(cc.path.extname(url) === '.png');
|
||||
});
|
||||
cc.textureCache.cacheImage(url, texture);
|
||||
|
||||
var newSprite = new cc.SpriteFrame();
|
||||
newSprite.setTexture(texture);
|
||||
newSprite.initWithTexture(url, cc.rect(0, 0, 10, 10));
|
||||
render.sprite = newSprite;
|
||||
|
||||
render.sprite.on('load', function () {
|
||||
var tex = newSprite.getTexture();
|
||||
tex.once('load', function () {
|
||||
strictEqual(render._sgNode._scale9Image.texture.url, url, 'texture set success');
|
||||
start();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user