Home | History | Annotate | Download | only in net
      1 #!/usr/bin/env python
      2 # Copyright (C) 2010 Google Inc. 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
      6 # are met:
      7 #
      8 # 1.  Redistributions of source code must retain the above copyright
      9 #     notice, this list of conditions and the following disclaimer.
     10 # 2.  Redistributions in binary form must reproduce the above copyright
     11 #     notice, this list of conditions and the following disclaimer in the
     12 #     documentation and/or other materials provided with the distribution.
     13 #
     14 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     15 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     16 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     17 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     18 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     19 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     20 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     21 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     23 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24 
     25 import sys
     26 
     27 from webkitpy.common.system.zip_mock import MockZip
     28 import testoutputset
     29 import unittest
     30 
     31 
     32 class TestOutputSetTest(unittest.TestCase):
     33     def _outputset_with_zip(self, zip, **kwargs):
     34         return testoutputset.TestOutputSet('<fake-outputset>', '<fake-platform>', zip, **kwargs)
     35 
     36     def test_text_files_get_interpreted_as_text_outputs(self):
     37         zip = MockZip()
     38         zip.insert('fast/dom/some-test-actual.txt', 'actual outputs')
     39         b = self._outputset_with_zip(zip)
     40         self.assertEquals(1, len(b.outputs_for('fast/dom/some-test')))
     41         self.assertEquals('fast/dom/some-test', b.outputs_for('fast/dom/some-test.html')[0].name())
     42 
     43     def test_image_and_checksum_files_get_interpreted_as_a_single_image_output(self):
     44         zip = MockZip()
     45         zip.insert('fast/dom/some-test-actual.checksum', 'abc123')
     46         zip.insert('fast/dom/some-test-actual.png', '<image data>')
     47         b = self._outputset_with_zip(zip)
     48         outputs = b.outputs_for('fast/dom/some-test')
     49         self.assertEquals(1, len(outputs))
     50         output = outputs[0]
     51         self.assertEquals('image', output.type())
     52         self.assertEquals('abc123', output.checksum())
     53 
     54     def test_multiple_image_outputs_are_detected(self):
     55         zip = MockZip()
     56         zip.insert('platform/win/fast/dom/some-test-actual.checksum', 'checksum1')
     57         zip.insert('platform/win/fast/dom/some-test-actual.png', '<image data 1>')
     58         zip.insert('platform/mac/fast/dom/some-test-actual.checksum', 'checksum2')
     59         zip.insert('platform/mac/fast/dom/some-test-actual.png', '<image data 2>')
     60         b = self._outputset_with_zip(zip)
     61         outputs = b.outputs_for('fast/dom/some-test')
     62         self.assertEquals(2, len(outputs))
     63         self.assertFalse(outputs[0].same_content(outputs[1]))
     64 
     65     def test_aggregate_output_set_correctly_retrieves_tests_from_multiple_output_sets(self):
     66         outputset1_zip = MockZip()
     67         outputset1_zip.insert('fast/dom/test-actual.txt', 'linux text output')
     68         outputset1 = testoutputset.TestOutputSet('linux-outputset', 'linux', outputset1_zip)
     69         outputset2_zip = MockZip()
     70         outputset2_zip.insert('fast/dom/test-actual.txt', 'windows text output')
     71         outputset2 = testoutputset.TestOutputSet('win-outputset', 'win', outputset2_zip)
     72 
     73         b = testoutputset.AggregateTestOutputSet([outputset1, outputset2])
     74         self.assertEquals(2, len(b.outputs_for('fast/dom/test')))
     75 
     76     def test_can_infer_platform_from_path_if_none_provided(self):
     77         # FIXME: unclear what the right behavior on win32 is.
     78         # https://bugs.webkit.org/show_bug.cgi?id=54525.
     79         if sys.platform == 'win32':
     80             return
     81 
     82         zip = MockZip()
     83         zip.insert('platform/win/some-test-expected.png', '<image data>')
     84         zip.insert('platform/win/some-test-expected.checksum', 'abc123')
     85         b = testoutputset.TestOutputSet('local LayoutTests outputset', None, zip)
     86 
     87         outputs = b.outputs_for('some-test')
     88         self.assertEquals(1, len(outputs))
     89         self.assertEquals('win', outputs[0].platform())
     90 
     91     def test_test_extension_is_ignored(self):
     92         zip = MockZip()
     93         zip.insert('test/test-a-actual.txt', 'actual outputs')
     94         b = self._outputset_with_zip(zip)
     95         outputs = b.outputs_for('test/test-a.html')
     96         self.assertEquals(1, len(outputs))
     97         self.assertEquals('test/test-a', outputs[0].name())
     98 
     99     def test_existing_outputs_are_marked_as_such(self):
    100         zip = MockZip()
    101         zip.insert('test/test-a-expected.txt', 'expected outputs')
    102         b = self._outputset_with_zip(zip)
    103         outputs = b.outputs_for('test/test-a.html')
    104         self.assertEquals(1, len(outputs))
    105         self.assertFalse(outputs[0].is_actual())
    106 
    107     def test_only_returns_outputs_of_specified_type(self):
    108         zip = MockZip()
    109         zip.insert('test/test-a-expected.txt', 'expected outputs')
    110         zip.insert('test/test-a-expected.checksum', 'expected outputs')
    111         zip.insert('test/test-a-expected.png', 'expected outputs')
    112         b = self._outputset_with_zip(zip)
    113 
    114         outputs = b.outputs_for('test/test-a.html')
    115         text_outputs = b.outputs_for('test/test-a.html', target_type='text')
    116         image_outputs = b.outputs_for('test/test-a.html', target_type='image')
    117 
    118         self.assertEquals(2, len(outputs))
    119         self.assertEquals(1, len(text_outputs))
    120         self.assertEquals(1, len(image_outputs))
    121         self.assertEquals('text', text_outputs[0].type())
    122         self.assertEquals('image', image_outputs[0].type())
    123 
    124     def test_exclude_expected_outputs_works(self):
    125         zip = MockZip()
    126         zip.insert('test-expected.txt',  'expected outputs stored on server for some reason')
    127         b = self._outputset_with_zip(zip, include_expected=False)
    128         outputs = b.outputs_for('test', target_type=None)
    129         self.assertEquals(0, len(outputs))
    130 
    131 if __name__ == "__main__":
    132     unittest.main()
    133