forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform-helper.js
48 lines (40 loc) · 1.09 KB
/
platform-helper.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
function isGtk()
{
// Set in Tools/WebKitTestRunner/gtk/TestControllerGTK.cpp.
return navigator.userAgent.includes("WebKitTestRunnerGTK");
}
function isWPE()
{
// Set in Tools/WebKitTestRunner/wpe/TestControllerWPE.cpp.
return navigator.userAgent.includes("WebKitTestRunnerWPE");
}
function videoCanvasPixelComparisonTolerance()
{
if (isGtk())
return 6;
return 2;
}
function checkPixelColorWithTolerance(pixel, r, g, b, a)
{
const tolerance = videoCanvasPixelComparisonTolerance();
return Math.abs(pixel[0] - r) <= tolerance
&& Math.abs(pixel[1] - g) <= tolerance
&& Math.abs(pixel[2] - b) <= tolerance
&& Math.abs(pixel[3] - a) <= tolerance;
}
function isPixelBlack(pixel)
{
return checkPixelColorWithTolerance(pixel, 0, 0, 0, 255);
}
function isPixelTransparent(pixel)
{
return checkPixelColorWithTolerance(pixel, 0, 0, 0, 0);
}
function isPixelWhite(pixel)
{
return checkPixelColorWithTolerance(pixel, 255, 255, 255, 255);
}
function isPixelGray(pixel)
{
return checkPixelColorWithTolerance(pixel, 128, 128, 128, 255);
}