1 description("Test that canvas elements can't have negative height and/or width.");
3 canvas
= document
.createElement('canvas');
5 function createFromMarkup(markup
)
7 var fragmentContainer
= document
.createElement("div");
8 fragmentContainer
.innerHTML
= markup
;
9 return fragmentContainer
.firstChild
;
12 function trySettingWidth(value
) {
18 function trySettingHeight(value
) {
20 canvas
.height
= value
;
24 function trySettingWidthAttribute(value
) {
26 canvas
.setAttribute('width', value
);
30 function trySettingHeightAttribute(value
) {
32 canvas
.setAttribute('height', value
);
36 function tryCreatingCanvasWithWidth(value
) {
37 return createFromMarkup("<canvas width=" + value
+ "></canvas>").width
;
40 function tryCreatingCanvasWithHeight(value
) {
41 return createFromMarkup("<canvas height='" + value
+ "'></canvas>").height
;
44 function tryWidth(value
, expected
) {
45 shouldBe("trySettingWidth(" + value
+ ")", expected
);
46 shouldBe("trySettingWidthAttribute(" + value
+ ")", expected
);
47 shouldBe("tryCreatingCanvasWithWidth(" + value
+ ")", expected
);
50 function tryHeight(value
, expected
) {
51 shouldBe("trySettingHeight(" + value
+ ")", expected
);
52 shouldBe("trySettingHeightAttribute(" + value
+ ")", expected
);
53 shouldBe("tryCreatingCanvasWithHeight(" + value
+ ")", expected
);
56 function checkDefaultWidth() {
57 return document
.createElement("canvas").width
;
60 function checkDefaultHeight() {
61 return document
.createElement("canvas").height
;
64 shouldBe("checkDefaultWidth()", "300");
65 shouldBe("checkDefaultHeight()", "150");
67 shouldBe("trySettingWidth('abc')", "300");
68 shouldBe("trySettingWidth('200')", "200");
69 shouldBe("trySettingWidth('300')", "300");
70 shouldBe("trySettingWidth(NaN)", "300");
71 shouldBe("trySettingWidth(Infinity)", "300");
72 shouldBe("trySettingWidth(null)", "300");
73 shouldBe("trySettingWidth(true)", "1");
74 shouldBe("trySettingWidth(false)", "0");
76 shouldBe("trySettingHeight('abc')", "150");
77 shouldBe("trySettingHeight('200')", "200");
78 shouldBe("trySettingHeight('150')", "150");
79 shouldBe("trySettingHeight(NaN)", "150");
80 shouldBe("trySettingHeight(Infinity)", "150");
81 shouldBe("trySettingHeight(null)", "150");
82 shouldBe("trySettingHeight(true)", "1");
83 shouldBe("trySettingHeight(false)", "0");
85 tryWidth("'foo'", "300");
86 tryWidth("-1", "300");
89 tryWidth("'+7'", "7");
90 tryWidth("'-7'", "300");
91 tryWidth("'123'", "123");
93 tryHeight("'foo'", "150");
94 tryHeight("-1", "150");
97 tryHeight("'+7'", "7");
98 tryHeight("'-7'", "150");
99 tryHeight("'123'", "123");