OLD | NEW |
1 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Classes for failures that occur during tests.""" | 5 """Classes for failures that occur during tests.""" |
6 | 6 |
| 7 import os |
| 8 |
7 class FailureSort(object): | 9 class FailureSort(object): |
8 """A repository for failure sort orders and tool to facilitate sorting.""" | 10 """A repository for failure sort orders and tool to facilitate sorting.""" |
9 | 11 |
10 # Each failure class should have an entry in this dictionary. Sort order 1 | 12 # Each failure class should have an entry in this dictionary. Sort order 1 |
11 # will be sorted first in the list. Failures with the same numeric sort | 13 # will be sorted first in the list. Failures with the same numeric sort |
12 # order will be sorted alphabetically by Message(). | 14 # order will be sorted alphabetically by Message(). |
13 SORT_ORDERS = { | 15 SORT_ORDERS = { |
14 'FailureTextMismatch': 1, | 16 'FailureTextMismatch': 1, |
15 'FailureImageHashMismatch': 2, | 17 'FailureImageHashMismatch': 2, |
16 'FailureTimeout': 3, | 18 'FailureTimeout': 3, |
(...skipping 19 matching lines...) Expand all Loading... |
36 raise NotImplemented | 38 raise NotImplemented |
37 | 39 |
38 def ResultHtmlOutput(self, filename): | 40 def ResultHtmlOutput(self, filename): |
39 """Returns an HTML string to be included on the results.html page.""" | 41 """Returns an HTML string to be included on the results.html page.""" |
40 raise NotImplemented | 42 raise NotImplemented |
41 | 43 |
42 def ShouldKillTestShell(self): | 44 def ShouldKillTestShell(self): |
43 """Returns True if we should kill the test shell before the next test.""" | 45 """Returns True if we should kill the test shell before the next test.""" |
44 return False | 46 return False |
45 | 47 |
| 48 def RelativeOutputFilename(self, filename, modifier): |
| 49 """Returns a relative filename inside the output dir that contains |
| 50 modifier. |
| 51 |
| 52 For example, if filename is fast\dom\foo.html and modifier is |
| 53 "-expected.txt", the return value is fast\dom\foo-expected.txt |
| 54 |
| 55 Args: |
| 56 filename: relative filename to test file |
| 57 modifier: a string to replace the extension of filename with |
| 58 |
| 59 Return: |
| 60 The relative windows path to the output filename |
| 61 """ |
| 62 return os.path.splitext(filename)[0] + modifier |
46 | 63 |
47 class FailureWithType(TestFailure): | 64 class FailureWithType(TestFailure): |
48 """Base class that produces standard HTML output based on the test type. | 65 """Base class that produces standard HTML output based on the test type. |
49 | 66 |
50 Subclasses may commonly choose to override the ResultHtmlOutput, but still | 67 Subclasses may commonly choose to override the ResultHtmlOutput, but still |
51 use the standard OutputLinks. | 68 use the standard OutputLinks. |
52 """ | 69 """ |
53 def __init__(self, test_type): | 70 def __init__(self, test_type): |
54 TestFailure.__init__(self) | 71 TestFailure.__init__(self) |
| 72 # TODO(ojan): This class no longer needs to know the test_type. |
55 self._test_type = test_type | 73 self._test_type = test_type |
56 | 74 |
57 # Filename suffixes used by ResultHtmlOutput. | 75 # Filename suffixes used by ResultHtmlOutput. |
58 OUT_FILENAMES = [] | 76 OUT_FILENAMES = [] |
59 | 77 |
60 def OutputLinks(self, filename, out_names): | 78 def OutputLinks(self, filename, out_names): |
61 """Returns a string holding all applicable output file links. | 79 """Returns a string holding all applicable output file links. |
62 | 80 |
63 Args: | 81 Args: |
64 filename: the test filename, used to construct the result file names | 82 filename: the test filename, used to construct the result file names |
65 out_names: list of filename suffixes for the files. If three or more | 83 out_names: list of filename suffixes for the files. If three or more |
66 suffixes are in the list, they should be [actual, expected, diff, | 84 suffixes are in the list, they should be [actual, expected, diff, |
67 wdiff]. | 85 wdiff]. |
68 Two suffixes should be [actual, expected], and a single item is the | 86 Two suffixes should be [actual, expected], and a single item is the |
69 [actual] filename suffix. If out_names is empty, returns the empty | 87 [actual] filename suffix. If out_names is empty, returns the empty |
70 string. | 88 string. |
71 """ | 89 """ |
72 links = [''] | 90 links = [''] |
73 uris = [self._test_type.RelativeOutputFilename(filename, fn) | 91 uris = [self.RelativeOutputFilename(filename, fn) for fn in out_names] |
74 for fn in out_names] | |
75 if len(uris) > 1: | 92 if len(uris) > 1: |
76 links.append("<a href='%s'>expected</a>" % uris[1]) | 93 links.append("<a href='%s'>expected</a>" % uris[1]) |
77 if len(uris) > 0: | 94 if len(uris) > 0: |
78 links.append("<a href='%s'>actual</a>" % uris[0]) | 95 links.append("<a href='%s'>actual</a>" % uris[0]) |
79 if len(uris) > 2: | 96 if len(uris) > 2: |
80 links.append("<a href='%s'>diff</a>" % uris[2]) | 97 links.append("<a href='%s'>diff</a>" % uris[2]) |
81 if len(uris) > 3: | 98 if len(uris) > 3: |
82 links.append("<a href='%s'>wdiff</a>" % uris[3]) | 99 links.append("<a href='%s'>wdiff</a>" % uris[3]) |
83 return ' '.join(links) | 100 return ' '.join(links) |
84 | 101 |
(...skipping 16 matching lines...) Expand all Loading... |
101 | 118 |
102 | 119 |
103 class FailureCrash(TestFailure): | 120 class FailureCrash(TestFailure): |
104 """Test shell crashed.""" | 121 """Test shell crashed.""" |
105 @staticmethod | 122 @staticmethod |
106 def Message(): | 123 def Message(): |
107 return "Test shell crashed" | 124 return "Test shell crashed" |
108 | 125 |
109 def ResultHtmlOutput(self, filename): | 126 def ResultHtmlOutput(self, filename): |
110 # TODO(tc): create a link to the minidump file | 127 # TODO(tc): create a link to the minidump file |
111 return "<strong>%s</strong>" % self.Message() | 128 stack = self.RelativeOutputFilename(filename, "-stack.txt") |
| 129 return "<strong>%s</strong> <a href=%s>stack</a>" % (self.Message(), stack) |
112 | 130 |
113 def ShouldKillTestShell(self): | 131 def ShouldKillTestShell(self): |
114 return True | 132 return True |
115 | 133 |
116 | 134 |
117 class FailureMissingResult(FailureWithType): | 135 class FailureMissingResult(FailureWithType): |
118 """Expected result was missing.""" | 136 """Expected result was missing.""" |
119 OUT_FILENAMES = ["-actual.txt"] | 137 OUT_FILENAMES = ["-actual.txt"] |
120 | 138 |
121 @staticmethod | 139 @staticmethod |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 # Chrome doesn't know to display a .checksum file as text, so don't bother | 212 # Chrome doesn't know to display a .checksum file as text, so don't bother |
195 # putting in a link to the actual result. | 213 # putting in a link to the actual result. |
196 OUT_FILENAMES = [] | 214 OUT_FILENAMES = [] |
197 | 215 |
198 @staticmethod | 216 @staticmethod |
199 def Message(): | 217 def Message(): |
200 return "Images match, expected image hash incorrect. " | 218 return "Images match, expected image hash incorrect. " |
201 | 219 |
202 def ResultHtmlOutput(self, filename): | 220 def ResultHtmlOutput(self, filename): |
203 return "<strong>%s</strong>" % self.Message() | 221 return "<strong>%s</strong>" % self.Message() |
OLD | NEW |