Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / script-tests / canvas-negative-size.js
blob670fb1c45a33fbb20da85fbb3a85912fa2c1a57b
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) {
13 canvas.width = 6;
14 canvas.width = value;
15 return canvas.width;
18 function trySettingHeight(value) {
19 canvas.height = 6;
20 canvas.height = value;
21 return canvas.height;
24 function trySettingWidthAttribute(value) {
25 canvas.width = 6;
26 canvas.setAttribute('width', value);
27 return canvas.width;
30 function trySettingHeightAttribute(value) {
31 canvas.height = 6;
32 canvas.setAttribute('height', value);
33 return canvas.height;
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");
87 tryWidth("0", "0");
88 tryWidth("1", "1");
89 tryWidth("'+7'", "7");
90 tryWidth("'-7'", "300");
91 tryWidth("'123'", "123");
93 tryHeight("'foo'", "150");
94 tryHeight("-1", "150");
95 tryHeight("0", "0");
96 tryHeight("1", "1");
97 tryHeight("'+7'", "7");
98 tryHeight("'-7'", "150");
99 tryHeight("'123'", "123");