1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
7 class RgbaColor(collections
.namedtuple('RgbaColor', ['r', 'g', 'b', 'a'])):
8 """Encapsulates an RGBA color retrieved from an image."""
9 def __new__(cls
, r
, g
, b
, a
=255):
10 return super(RgbaColor
, cls
).__new
__(cls
, r
, g
, b
, a
)
13 return (self
.r
<< 16) |
(self
.g
<< 8) | self
.b
15 def IsEqual(self
, expected_color
, tolerance
=0):
16 """Verifies that the color is within a given tolerance of
17 the expected color."""
18 r_diff
= abs(self
.r
- expected_color
.r
)
19 g_diff
= abs(self
.g
- expected_color
.g
)
20 b_diff
= abs(self
.b
- expected_color
.b
)
21 a_diff
= abs(self
.a
- expected_color
.a
)
22 return (r_diff
<= tolerance
and g_diff
<= tolerance
23 and b_diff
<= tolerance
and a_diff
<= tolerance
)
25 def AssertIsRGB(self
, r
, g
, b
, tolerance
=0):
26 assert self
.IsEqual(RgbaColor(r
, g
, b
), tolerance
)
28 def AssertIsRGBA(self
, r
, g
, b
, a
, tolerance
=0):
29 assert self
.IsEqual(RgbaColor(r
, g
, b
, a
), tolerance
)
32 WEB_PAGE_TEST_ORANGE
= RgbaColor(222, 100, 13)
33 WHITE
= RgbaColor(255, 255, 255)