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..a5d140af58f1972e736bd638e09c9ec532b82fed 100644 |
--- a/chrome/test/functional/ispy/common/ispy_utils.py |
+++ b/chrome/test/functional/ispy/common/ispy_utils.py |
@@ -13,6 +13,13 @@ import sys |
import image_tools |
+_INVALID_EXPECTATION_CHARS = ['/', '\\', ' ', '"', '\''] |
+ |
+ |
+def IsValidExpectationName(expectation_name): |
+ return not any(c in _INVALID_EXPECTATION_CHARS for c in expectation_name) |
+ |
+ |
def GetExpectationPath(expectation, file_name=''): |
"""Get the path to a test file in the given test run and expectation. |
@@ -96,7 +103,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 name contains an illegal character: %s." % |
+ str(_INVALID_EXPECTATION_CHARS)) |
+ |
mask = image_tools.InflateMask(image_tools.CreateMask(images), 7) |
self.UploadImage( |
GetExpectationPath(expectation, 'expected.png'), images[0]) |
@@ -112,7 +126,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 +217,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) |