Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Tools / Scripts / webkitpy / tool / commands / queries_unittest.py
1 # Copyright (C) 2009 Google Inc. All rights reserved.
2 # Copyright (C) 2012 Intel Corporation. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 #    * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 #    * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 #    * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 import unittest
31
32 from webkitpy.common.system.outputcapture import OutputCapture
33 from webkitpy.common.system.outputcapture import OutputCapture
34 from webkitpy.thirdparty.mock import Mock
35 from webkitpy.layout_tests.port.test import TestPort
36 from webkitpy.tool.commands.commandtest import CommandsTest
37 from webkitpy.tool.commands.queries import *
38 from webkitpy.tool.mocktool import MockTool, MockOptions
39
40
41 class PrintExpectationsTest(unittest.TestCase):
42     def run_test(self, tests, expected_stdout, platform='test-win-xp', **args):
43         options = MockOptions(all=False, csv=False, full=False, platform=platform,
44                               include_keyword=[], exclude_keyword=[], paths=False).update(**args)
45         tool = MockTool()
46         tool.port_factory.all_port_names = lambda: TestPort.ALL_BASELINE_VARIANTS
47         command = PrintExpectations()
48         command.bind_to_tool(tool)
49
50         oc = OutputCapture()
51         try:
52             oc.capture_output()
53             command.execute(options, tests, tool)
54         finally:
55             stdout, _, _ = oc.restore_output()
56         self.assertMultiLineEqual(stdout, expected_stdout)
57
58     def test_basic(self):
59         self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
60                       ('// For test-win-xp\n'
61                        'failures/expected/image.html [ ImageOnlyFailure ]\n'
62                        'failures/expected/text.html [ Failure ]\n'))
63
64     def test_multiple(self):
65         self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
66                       ('// For test-win-win7\n'
67                        'failures/expected/image.html [ ImageOnlyFailure ]\n'
68                        'failures/expected/text.html [ Failure ]\n'
69                        '\n'
70                        '// For test-win-xp\n'
71                        'failures/expected/image.html [ ImageOnlyFailure ]\n'
72                        'failures/expected/text.html [ Failure ]\n'),
73                        platform='test-win-*')
74
75     def test_full(self):
76         self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
77                       ('// For test-win-xp\n'
78                        'Bug(test) failures/expected/image.html [ ImageOnlyFailure ]\n'
79                        'Bug(test) failures/expected/text.html [ Failure ]\n'),
80                       full=True)
81
82     def test_exclude(self):
83         self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
84                       ('// For test-win-xp\n'
85                        'failures/expected/text.html [ Failure ]\n'),
86                       exclude_keyword=['image'])
87
88     def test_include(self):
89         self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
90                       ('// For test-win-xp\n'
91                        'failures/expected/image.html\n'),
92                       include_keyword=['image'])
93
94     def test_csv(self):
95         self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
96                       ('test-win-xp,failures/expected/image.html,Bug(test),,IMAGE\n'
97                        'test-win-xp,failures/expected/text.html,Bug(test),,FAIL\n'),
98                       csv=True)
99
100     def test_paths(self):
101         self.run_test([],
102                       ('/mock-checkout/LayoutTests/TestExpectations\n'
103                        'LayoutTests/platform/test/TestExpectations\n'
104                        'LayoutTests/platform/test-win-xp/TestExpectations\n'),
105                       paths=True)
106
107 class PrintBaselinesTest(unittest.TestCase):
108     def setUp(self):
109         self.oc = None
110         self.tool = MockTool()
111         self.test_port = self.tool.port_factory.get('test-win-xp')
112         self.tool.port_factory.get = lambda port_name=None: self.test_port
113         self.tool.port_factory.all_port_names = lambda: TestPort.ALL_BASELINE_VARIANTS
114
115     def tearDown(self):
116         if self.oc:
117             self.restore_output()
118
119     def capture_output(self):
120         self.oc = OutputCapture()
121         self.oc.capture_output()
122
123     def restore_output(self):
124         stdout, stderr, logs = self.oc.restore_output()
125         self.oc = None
126         return (stdout, stderr, logs)
127
128     def test_basic(self):
129         command = PrintBaselines()
130         command.bind_to_tool(self.tool)
131         self.capture_output()
132         command.execute(MockOptions(all=False, include_virtual_tests=False, csv=False, platform=None), ['passes/text.html'], self.tool)
133         stdout, _, _ = self.restore_output()
134         self.assertMultiLineEqual(stdout,
135                           ('// For test-win-xp\n'
136                            'passes/text-expected.png\n'
137                            'passes/text-expected.txt\n'))
138
139     def test_multiple(self):
140         command = PrintBaselines()
141         command.bind_to_tool(self.tool)
142         self.capture_output()
143         command.execute(MockOptions(all=False, include_virtual_tests=False, csv=False, platform='test-win-*'), ['passes/text.html'], self.tool)
144         stdout, _, _ = self.restore_output()
145         self.assertMultiLineEqual(stdout,
146                           ('// For test-win-win7\n'
147                            'passes/text-expected.png\n'
148                            'passes/text-expected.txt\n'
149                            '\n'
150                            '// For test-win-xp\n'
151                            'passes/text-expected.png\n'
152                            'passes/text-expected.txt\n'))
153
154     def test_csv(self):
155         command = PrintBaselines()
156         command.bind_to_tool(self.tool)
157         self.capture_output()
158         command.execute(MockOptions(all=False, platform='*xp', csv=True, include_virtual_tests=False), ['passes/text.html'], self.tool)
159         stdout, _, _ = self.restore_output()
160         self.assertMultiLineEqual(stdout,
161                           ('test-win-xp,passes/text.html,None,png,passes/text-expected.png,None\n'
162                            'test-win-xp,passes/text.html,None,txt,passes/text-expected.txt,None\n'))