forked from zz85/robotjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitmap.js
91 lines (75 loc) · 2.24 KB
/
bitmap.js
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
var test = require('tape');
var robot = require('..');
var params =
{
'width': 'number',
'height': 'number',
'byteWidth': 'number',
'bitsPerPixel': 'number',
'bytesPerPixel': 'number',
'image': 'object'
};
test('Get a bitmap.', function(t)
{
t.plan(1);
t.ok(robot.screen.capture(), 'got a bitmap.');
});
test('Get a bitmap and check the parameters.', function(t)
{
t.plan(6);
var img = robot.screen.capture();
for (var x in params)
{
t.equal(typeof img[x], params[x], 'make sure ' + x + ' is a ' + params[x] + '.');
}
});
test('Get a bitmap of a specific size.', function(t)
{
var size = 10;
t.plan(2);
var img = robot.screen.capture(0, 0, size, size);
// Support for higher density screens.
var multi = img.width / size;
var size = size * multi;
t.equals(img.height, size, 'make sure image is expected height.');
t.equals(img.width, size, 'make sure image is expected width.');
});
test('Get a bitmap and make sure the colorAt works as expected.', function(t)
{
t.plan(7);
var img = robot.screen.capture();
var hex = img.colorAt(0, 0);
t.ok(/^[0-9A-F]{6}$/i.test(hex), "colorAt returned valid hex.");
var screenSize = robot.getScreenSize();
var width = screenSize.width;
var height = screenSize.height;
// Support for higher density screens.
var multi = img.width / width;
width = width * multi;
height = height * multi;
t.throws(function()
{
img.colorAt(0, height);
}, /are outside the bitmap/, 'colorAt (0, screen.height) threw an error.');
t.doesNotThrow(function()
{
img.colorAt(0, height-1);
}, /are outside the bitmap/, 'colorAt (0, screen.height-1) did not throw an error.');
t.throws(function()
{
img.colorAt(width, 0);
}, /are outside the bitmap/, 'colorAt (screen.width, 0) threw an error.');
t.doesNotThrow(function()
{
img.colorAt(width-1, 0);
}, /are outside the bitmap/, 'colorAt (screen.width-1, 0) did not throw an error.');
t.throws(function()
{
img.colorAt(9999999999999, 0);
}, /are outside the bitmap/, 'colorAt (9999999999999, 0) threw an error.');
// Regression test for https://github.com/octalmage/robotjs/commit/c41f38217fd73f59e6ca63015b51565cd1e7cfb7
t.throws(function()
{
img.colorAt(0, 9999999999999);
}, /are outside the bitmap/, 'colorAt (0, 9999999999999) threw an error.');
});