summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-negative-size.js
blob: 670fb1c45a33fbb20da85fbb3a85912fa2c1a57b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
description("Test that canvas elements can't have negative height and/or width.");

canvas = document.createElement('canvas');

function createFromMarkup(markup)
{
    var fragmentContainer = document.createElement("div");
    fragmentContainer.innerHTML = markup;
    return fragmentContainer.firstChild;
}

function trySettingWidth(value) {
    canvas.width = 6;
    canvas.width = value;
    return canvas.width;
}

function trySettingHeight(value) {
    canvas.height = 6;
    canvas.height = value;
    return canvas.height;
}

function trySettingWidthAttribute(value) {
    canvas.width = 6;
    canvas.setAttribute('width', value);
    return canvas.width;
}

function trySettingHeightAttribute(value) {
    canvas.height = 6;
    canvas.setAttribute('height', value);
    return canvas.height;
}

function tryCreatingCanvasWithWidth(value) {
    return createFromMarkup("<canvas width=" + value + "></canvas>").width;
}

function tryCreatingCanvasWithHeight(value) {
    return createFromMarkup("<canvas height='" + value + "'></canvas>").height;
}

function tryWidth(value, expected) {
    shouldBe("trySettingWidth(" + value + ")", expected);
    shouldBe("trySettingWidthAttribute(" + value + ")", expected);
    shouldBe("tryCreatingCanvasWithWidth(" + value + ")", expected);
}

function tryHeight(value, expected) {
    shouldBe("trySettingHeight(" + value + ")", expected);
    shouldBe("trySettingHeightAttribute(" + value + ")", expected);
    shouldBe("tryCreatingCanvasWithHeight(" + value + ")", expected);
}

function checkDefaultWidth() {
    return document.createElement("canvas").width;
}

function checkDefaultHeight() {
    return document.createElement("canvas").height;
}

shouldBe("checkDefaultWidth()", "300");
shouldBe("checkDefaultHeight()", "150");

shouldBe("trySettingWidth('abc')", "300");
shouldBe("trySettingWidth('200')", "200");
shouldBe("trySettingWidth('300')", "300");
shouldBe("trySettingWidth(NaN)", "300");
shouldBe("trySettingWidth(Infinity)", "300");
shouldBe("trySettingWidth(null)", "300");
shouldBe("trySettingWidth(true)", "1");
shouldBe("trySettingWidth(false)", "0");

shouldBe("trySettingHeight('abc')", "150");
shouldBe("trySettingHeight('200')", "200");
shouldBe("trySettingHeight('150')", "150");
shouldBe("trySettingHeight(NaN)", "150");
shouldBe("trySettingHeight(Infinity)", "150");
shouldBe("trySettingHeight(null)", "150");
shouldBe("trySettingHeight(true)", "1");
shouldBe("trySettingHeight(false)", "0");

tryWidth("'foo'", "300");
tryWidth("-1", "300");
tryWidth("0", "0");
tryWidth("1", "1");
tryWidth("'+7'", "7");
tryWidth("'-7'", "300");
tryWidth("'123'", "123");

tryHeight("'foo'", "150");
tryHeight("-1", "150");
tryHeight("0", "0");
tryHeight("1", "1");
tryHeight("'+7'", "7");
tryHeight("'-7'", "150");
tryHeight("'123'", "123");