qt_unittest.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Copyright (C) 2010 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following disclaimer
  11. # in the documentation and/or other materials provided with the
  12. # distribution.
  13. # * Neither the name of Google Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. import unittest2 as unittest
  29. import os
  30. from copy import deepcopy
  31. from webkitpy.common.system.executive_mock import MockExecutive, MockExecutive2
  32. from webkitpy.common.system.outputcapture import OutputCapture
  33. from webkitpy.common.system.systemhost_mock import MockSystemHost
  34. from webkitpy.port import port_testcase
  35. from webkitpy.port.qt import QtPort
  36. from webkitpy.tool.mocktool import MockOptions
  37. class QtPortTest(port_testcase.PortTestCase):
  38. port_name = 'qt-mac'
  39. port_maker = QtPort
  40. search_paths_cases = [
  41. {'search_paths':['qt-5.0-mac-wk2', 'qt-5.0-wk2', 'qt-5.0', 'qt-mac', 'qt'], 'os_name':'mac', 'use_webkit2':True, 'qt_version':'5.0'},
  42. {'search_paths':['qt-5.0-wk2', 'qt-5.0', 'qt-win', 'qt'], 'os_name':'win', 'use_webkit2':True, 'qt_version':'5.0'},
  43. {'search_paths':['qt-5.0-wk2', 'qt-5.0', 'qt-linux', 'qt'], 'os_name':'linux', 'use_webkit2':True, 'qt_version':'5.0'},
  44. {'search_paths':['qt-5.0-wk1', 'qt-5.0', 'qt-mac', 'qt'], 'os_name':'mac', 'use_webkit2':False, 'qt_version':'5.0'},
  45. {'search_paths':['qt-5.0-wk1', 'qt-5.0', 'qt-win', 'qt'], 'os_name':'win', 'use_webkit2':False, 'qt_version':'5.0'},
  46. {'search_paths':['qt-5.0-wk1', 'qt-5.0', 'qt-linux', 'qt'], 'os_name':'linux', 'use_webkit2':False, 'qt_version':'5.0'},
  47. ]
  48. def _assert_search_path(self, search_paths, os_name, use_webkit2=False, qt_version='5.0'):
  49. # FIXME: Port constructors should not "parse" the port name, but
  50. # rather be passed components (directly or via setters). Once
  51. # we fix that, this method will need a re-write.
  52. host = MockSystemHost(os_name=os_name)
  53. host.executive = MockExecutive2(self._qt_version(qt_version))
  54. port_name = 'qt-' + os_name
  55. port = self.make_port(host=host, qt_version=qt_version, port_name=port_name,
  56. options=MockOptions(webkit_test_runner=use_webkit2, platform='qt'))
  57. absolute_search_paths = map(port._webkit_baseline_path, search_paths)
  58. self.assertEqual(port.baseline_search_path(), absolute_search_paths)
  59. def _assert_expectations_files(self, search_paths, os_name, use_webkit2=False, qt_version='5.0'):
  60. # FIXME: Port constructors should not "parse" the port name, but
  61. # rather be passed components (directly or via setters). Once
  62. # we fix that, this method will need a re-write.
  63. host = MockSystemHost(os_name=os_name)
  64. host.executive = MockExecutive2(self._qt_version(qt_version))
  65. port_name = 'qt-' + os_name
  66. port = self.make_port(host=host, qt_version=qt_version, port_name=port_name,
  67. options=MockOptions(webkit_test_runner=use_webkit2, platform='qt'))
  68. self.assertEqual(port.expectations_files(), search_paths)
  69. def _qt_version(self, qt_version):
  70. if qt_version in '5.0':
  71. return 'QMake version 2.01a\nUsing Qt version 5.0.0 in /usr/local/Trolltech/Qt-5.0.0/lib'
  72. def test_baseline_search_path(self):
  73. for case in self.search_paths_cases:
  74. self._assert_search_path(**case)
  75. def test_expectations_files(self):
  76. for case in self.search_paths_cases:
  77. expectations_case = deepcopy(case)
  78. if expectations_case['use_webkit2']:
  79. expectations_case['search_paths'].append("wk2")
  80. expectations_case['search_paths'].append('')
  81. expectations_case['search_paths'].reverse()
  82. expectations_case['search_paths'] = map(lambda path: '/mock-checkout/LayoutTests/TestExpectations' if not path else '/mock-checkout/LayoutTests/platform/%s/TestExpectations' % (path), expectations_case['search_paths'])
  83. self._assert_expectations_files(**expectations_case)
  84. def test_show_results_html_file(self):
  85. port = self.make_port()
  86. port._executive = MockExecutive(should_log=True)
  87. expected_logs = "MOCK run_command: ['Tools/Scripts/run-launcher', '--release', '--qt', 'file://test.html'], cwd=/mock-checkout\n"
  88. OutputCapture().assert_outputs(self, port.show_results_html_file, ["test.html"], expected_logs=expected_logs)
  89. def test_setup_environ_for_server(self):
  90. port = self.make_port()
  91. env = port.setup_environ_for_server(port.driver_name())
  92. self.assertEqual(env['QTWEBKIT_PLUGIN_PATH'], '/mock-build/lib/plugins')
  93. def test_operating_system(self):
  94. self.assertEqual('linux', self.make_port(port_name='qt-linux', os_name='linux').operating_system())
  95. self.assertEqual('mac', self.make_port(os_name='mac').operating_system())
  96. self.assertEqual('win', self.make_port(port_name='qt-win', os_name='win').operating_system())
  97. def test_check_sys_deps(self):
  98. port = self.make_port()
  99. # Success
  100. os.environ['WEBKIT_TESTFONTS'] = '/tmp/foo'
  101. port._executive = MockExecutive2(exit_code=0)
  102. self.assertTrue(port.check_sys_deps(needs_http=False))
  103. # Failure
  104. del os.environ['WEBKIT_TESTFONTS']
  105. port._executive = MockExecutive2(exit_code=1,
  106. output='testing output failure')
  107. self.assertFalse(port.check_sys_deps(needs_http=False))