Skip to content
This repository was archived by the owner on Feb 9, 2018. It is now read-only.

Commit edcee12

Browse files
committed
Update braces, start looking at async test
1 parent ffef302 commit edcee12

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/css-image-value.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
this.state = "loaded";
1919
this.intrinsicWidth = this._image.naturalWidth;
2020
this.intrinsicHeight = this._image.naturalHeight;
21-
if (this.intrinsicHeight != 0)
21+
if (this.intrinsicHeight != 0) {
2222
this.intrinsicRatio = this.intrinsicWidth / this.intrinsicHeight;
23+
}
2324
}
2425

2526
function onError() {
@@ -44,13 +45,17 @@
4445
}
4546

4647
this._image = image;
47-
this.state = "unloaded";
48-
this.intrinsicWidth = null;
49-
this.intrinsicHeight = null;
50-
this.intrinsicRatio = null;
51-
this._image.onload = onLoad.bind(this);
52-
this._image.onerror = onError.bind(this);
53-
this._image.onprogess = onProgress.bind(this);
48+
//if (image.complete) {
49+
// onLoad.call(this);
50+
//} else {
51+
this.state = "unloaded";
52+
this.intrinsicWidth = null;
53+
this.intrinsicHeight = null;
54+
this.intrinsicRatio = null;
55+
this._image.onload = onLoad.bind(this);
56+
this._image.onerror = onError.bind(this);
57+
this._image.onprogess = onProgress.bind(this);
58+
//}
5459
}
5560
CSSImageValue.prototype = Object.create(scope.CSSImageValue.prototype);
5661

test/js/css-image-value.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ suite('CSSImageValue', function() {
2424
assert.instanceOf(new typedOM.internal.CSSImageValue(new Image()), CSSStyleValue);
2525
});
2626

27-
test('CSSImageValue only accepts Image object', function() {
27+
test('CSSImageValue only accepts Image objects', function() {
2828
var imageErr = /image must be an Image object/;
2929
assert.throws(function() { new typedOM.internal.CSSImageValue(); }, TypeError, imageErr);
3030
assert.throws(function() { new typedOM.internal.CSSImageValue(1); }, TypeError, imageErr);
@@ -33,7 +33,21 @@ suite('CSSImageValue', function() {
3333
assert.throws(function() { new typedOM.internal.CSSImageValue({ x: 1, y: 2 }); }, TypeError, imageErr);
3434
});
3535

36-
test('CSSImageValue\'s state and dimensions are correct before and after loaded', function(done) {
36+
/*
37+
test('Can accept an already loaded image', function(done) {
38+
var image = new Image();
39+
//image.src = "resources/1x1-green.png";
40+
image.onload = function() {
41+
var cssImageValue = new typedOM.internal.CSSImageValue(image);
42+
assert.strictEqual(image.state, "loaded");
43+
assert.strictEqual(image.intrinsicWidth, 1);
44+
assert.strictEqual(image.intrinsicHeight, 1);
45+
assert.strictEqual(image.intrinsicRatio, 1);
46+
done();
47+
};
48+
});*/
49+
50+
test('State and dimensions are correct before and after loading', function(done) {
3751
var image = new typedOM.internal.CSSImageValue(new Image());
3852
assert.strictEqual(image.state, "unloaded");
3953
assert.strictEqual(image.intrinsicWidth, null);
@@ -44,7 +58,7 @@ suite('CSSImageValue', function() {
4458
image._image.onload = function() {
4559
oldOnload();
4660
assert.strictEqual(image.state, "loaded");
47-
assert.strictEqual(image.intrinsicWidth, 1);
61+
assert.strictEqual(image.intrinsicWidth, 2);
4862
assert.strictEqual(image.intrinsicHeight, 1);
4963
assert.strictEqual(image.intrinsicRatio, 1);
5064
done();

0 commit comments

Comments
 (0)