1bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# Copyright (C) 2010 Google Inc. All rights reserved.
2bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#
3bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# Redistribution and use in source and binary forms, with or without
4bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# modification, are permitted provided that the following conditions are
5bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# met:
6bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#
7bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#    * Redistributions of source code must retain the above copyright
8bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# notice, this list of conditions and the following disclaimer.
9bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#    * Redistributions in binary form must reproduce the above
10bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# copyright notice, this list of conditions and the following disclaimer
11bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# in the documentation and/or other materials provided with the
12bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# distribution.
13bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#    * Neither the name of Google Inc. nor the names of its
14bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# contributors may be used to endorse or promote products derived from
15bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# this software without specific prior written permission.
16bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#
17bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen
292fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockimport sys
30bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenimport unittest
31bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen
322fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockfrom webkitpy.layout_tests.port import test
33bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenimport test_files
34bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen
35bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenclass TestFilesTest(unittest.TestCase):
36bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    def test_find_no_paths_specified(self):
372fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        port = test.TestPort()
38bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen        layout_tests_dir = port.layout_tests_dir()
39bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen        tests = test_files.find(port, [])
402fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        self.assertNotEqual(len(tests), 0)
41bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen
42bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    def test_find_one_test(self):
432fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        port = test.TestPort()
442fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        tests = test_files.find(port, ['failures/expected/image.html'])
45bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen        self.assertEqual(len(tests), 1)
46bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen
47bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    def test_find_glob(self):
482fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        port = test.TestPort()
492fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        tests = test_files.find(port, ['failures/expected/im*'])
502fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        self.assertEqual(len(tests), 2)
51bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen
52bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    def test_find_with_skipped_directories(self):
532fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        port = test.TestPort()
54bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen        tests = port.tests('userscripts')
552fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        self.assertTrue('userscripts/resources/iframe.html' not in tests)
56bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen
57bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    def test_find_with_skipped_directories_2(self):
582fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        port = test.TestPort()
59bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen        tests = test_files.find(port, ['userscripts/resources'])
60bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen        self.assertEqual(tests, set([]))
61bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen
624576aa36e9a9671459299c7963ac95aa94beaea9Shimeng (Simon) Wang    def test_is_test_file(self):
632fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        port = test.TestPort()
64ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch        fs = port._filesystem
65ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch        self.assertTrue(test_files._is_test_file(fs, '', 'foo.html'))
66ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch        self.assertTrue(test_files._is_test_file(fs, '', 'foo.shtml'))
67ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch        self.assertFalse(test_files._is_test_file(fs, '', 'foo.png'))
68ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch        self.assertFalse(test_files._is_test_file(fs, '', 'foo-expected.html'))
69ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch        self.assertFalse(test_files._is_test_file(fs, '', 'foo-expected-mismatch.html'))
704576aa36e9a9671459299c7963ac95aa94beaea9Shimeng (Simon) Wang
71bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen
722fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockclass MockWinFileSystem(object):
732fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    def join(self, *paths):
742fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        return '\\'.join(paths)
752fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
762fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    def normpath(self, path):
772fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        return path.replace('/', '\\')
782fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
792fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
802fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockclass TestWinNormalize(unittest.TestCase):
812fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    def assert_filesystem_normalizes(self, filesystem):
822fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        self.assertEquals(test_files.normalize(filesystem, "c:\\foo",
832fc2651226baac27029e38c9d6ef883fa32084dbSteve Block            ['fast/html', 'fast/canvas/*', 'compositing/foo.html']),
842fc2651226baac27029e38c9d6ef883fa32084dbSteve Block            ['c:\\foo\\fast\html', 'c:\\foo\\fast\canvas\*', 'c:\\foo\compositing\\foo.html'])
852fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
862fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    def test_mocked_win(self):
872fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        # This tests test_files.normalize, using portable behavior emulating
882fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        # what we think Windows is supposed to do. This test will run on all
892fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        # platforms.
902fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        self.assert_filesystem_normalizes(MockWinFileSystem())
912fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
922fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    def test_win(self):
932fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        # This tests the actual windows platform, to ensure we get the same
942fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        # results that we get in test_mocked_win().
952fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        if sys.platform != 'win':
962fc2651226baac27029e38c9d6ef883fa32084dbSteve Block            return
972fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        self.assert_filesystem_normalizes(FileSystem())
982fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
992fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
100bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsenif __name__ == '__main__':
101bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    unittest.main()
102