Chromium Code Reviews| Index: chrome/test/functional/ispy/common/ispy_utils.py |
| diff --git a/chrome/test/functional/ispy/common/ispy_utils.py b/chrome/test/functional/ispy/common/ispy_utils.py |
| index 6fa7d08fe33f66e3ee9a66a17b6550271153594d..9e4a739c81f010dcc07bc68dc7caac96a14c444a 100644 |
| --- a/chrome/test/functional/ispy/common/ispy_utils.py |
| +++ b/chrome/test/functional/ispy/common/ispy_utils.py |
| @@ -13,6 +13,16 @@ import sys |
| import image_tools |
| +_INVALID_EXPECTATION_CHARS = ['/', '\\', ' ', '"', '\''] |
| + |
| + |
| +def IsValidExpectationName(expectationName): |
|
craigdh
2013/12/03 00:30:50
return any(c in _INVALID_EXPECTATION_CHARS for c i
craigdh
2013/12/03 00:30:50
expectationName -> expectation_name
baxley
2013/12/03 00:53:16
Done.
baxley
2013/12/03 00:53:16
Done.
|
| + for char in _INVALID_EXPECTATION_CHARS: |
| + if expectationName.find(char) != -1: |
| + return False |
| + return True |
| + |
| + |
| def GetExpectationPath(expectation, file_name=''): |
| """Get the path to a test file in the given test run and expectation. |
| @@ -96,7 +106,14 @@ class ISpyUtils(object): |
| expectation: name for this expectation, any existing expectation with the |
| name will be replaced. |
| images: a list of RGB encoded PIL.Images |
| + |
| + Raises: |
| + ValueError: if the expectation name is invalid. |
| """ |
| + if not IsValidExpectationName(expectation): |
| + raise ValueError("Expectation contains an illegal value: %s." % |
| + str(_INVALID_EXPECTATION_CHARS)) |
| + |
| mask = image_tools.InflateMask(image_tools.CreateMask(images), 7) |
| self.UploadImage( |
| GetExpectationPath(expectation, 'expected.png'), images[0]) |
| @@ -112,7 +129,12 @@ class ISpyUtils(object): |
| Raises: |
| cloud_bucket.NotFoundError: if the given expectation is not found. |
| + ValueError: if the expectation name is invalid. |
| """ |
| + if not IsValidExpectationName(expectation): |
| + raise ValueError("Expectation name contains an illegal character: %s." % |
| + str(_INVALID_EXPECTATION_CHARS)) |
| + |
| expectation_tuple = self.GetExpectation(expectation) |
| if not image_tools.SameImage( |
| actual, expectation_tuple.expected, mask=expectation_tuple.mask): |
| @@ -198,7 +220,14 @@ class ISpyUtils(object): |
| images: a json encoded list of base64 encoded png images. |
| pink_out: an image. |
| RGB: a json list representing the RGB values of a color to mask out. |
| + |
| + Raises: |
| + ValueError: if expectation name is invalid. |
| """ |
| + if not IsValidExpectationName(expectation): |
| + raise ValueError("Expectation name contains an illegal character: %s." % |
| + str(_INVALID_EXPECTATION_CHARS)) |
| + |
| # convert the pink_out into a mask |
| black = (0, 0, 0, 255) |
| white = (255, 255, 255, 255) |