gtk_unittest.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # Copyright (C) 2011 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 sys
  30. import os
  31. from webkitpy.common.system.executive_mock import MockExecutive
  32. from webkitpy.common.system.filesystem_mock import MockFileSystem
  33. from webkitpy.common.system.outputcapture import OutputCapture
  34. from webkitpy.port.gtk import GtkPort
  35. from webkitpy.port.pulseaudio_sanitizer_mock import PulseAudioSanitizerMock
  36. from webkitpy.port import port_testcase
  37. from webkitpy.thirdparty.mock import Mock
  38. from webkitpy.tool.mocktool import MockOptions
  39. class GtkPortTest(port_testcase.PortTestCase):
  40. port_name = 'gtk'
  41. port_maker = GtkPort
  42. # Additionally mocks out the PulseAudioSanitizer methods.
  43. def make_port(self, host=None, port_name=None, options=None, os_name=None, os_version=None, **kwargs):
  44. port = super(GtkPortTest, self).make_port(host, port_name, options, os_name, os_version, **kwargs)
  45. port._pulseaudio_sanitizer = PulseAudioSanitizerMock()
  46. return port
  47. def test_default_baseline_search_path(self):
  48. port = self.make_port()
  49. self.assertEqual(port.default_baseline_search_path(), ['/mock-checkout/LayoutTests/platform/gtk-wk1',
  50. '/mock-checkout/LayoutTests/platform/gtk'])
  51. port = self.make_port(options=MockOptions(webkit_test_runner=True))
  52. self.assertEqual(port.default_baseline_search_path(), ['/mock-checkout/LayoutTests/platform/gtk-wk2',
  53. '/mock-checkout/LayoutTests/platform/wk2', '/mock-checkout/LayoutTests/platform/gtk'])
  54. def test_port_specific_expectations_files(self):
  55. port = self.make_port()
  56. self.assertEqual(port.expectations_files(), ['/mock-checkout/LayoutTests/TestExpectations',
  57. '/mock-checkout/LayoutTests/platform/gtk/TestExpectations',
  58. '/mock-checkout/LayoutTests/platform/gtk-wk1/TestExpectations'])
  59. port = self.make_port(options=MockOptions(webkit_test_runner=True))
  60. self.assertEqual(port.expectations_files(), ['/mock-checkout/LayoutTests/TestExpectations',
  61. '/mock-checkout/LayoutTests/platform/gtk/TestExpectations',
  62. '/mock-checkout/LayoutTests/platform/wk2/TestExpectations',
  63. '/mock-checkout/LayoutTests/platform/gtk-wk2/TestExpectations'])
  64. def test_show_results_html_file(self):
  65. port = self.make_port()
  66. port._executive = MockExecutive(should_log=True)
  67. expected_logs = "MOCK run_command: ['Tools/Scripts/run-launcher', '--release', '--gtk', 'file://test.html'], cwd=/mock-checkout\n"
  68. OutputCapture().assert_outputs(self, port.show_results_html_file, ["test.html"], expected_logs=expected_logs)
  69. def test_default_timeout_ms(self):
  70. self.assertEqual(self.make_port(options=MockOptions(configuration='Release')).default_timeout_ms(), 6000)
  71. self.assertEqual(self.make_port(options=MockOptions(configuration='Debug')).default_timeout_ms(), 12000)
  72. def test_get_crash_log(self):
  73. core_directory = os.environ.get('WEBKIT_CORE_DUMPS_DIRECTORY', '/path/to/coredumps')
  74. core_pattern = os.path.join(core_directory, "core-pid_%p-_-process_%e")
  75. mock_empty_crash_log = """\
  76. Crash log for DumpRenderTree (pid 28529):
  77. Coredump core-pid_28529-_-process_DumpRenderTree not found. To enable crash logs:
  78. - run this command as super-user: echo "%(core_pattern)s" > /proc/sys/kernel/core_pattern
  79. - enable core dumps: ulimit -c unlimited
  80. - set the WEBKIT_CORE_DUMPS_DIRECTORY environment variable: export WEBKIT_CORE_DUMPS_DIRECTORY=%(core_directory)s
  81. STDERR: <empty>""" % locals()
  82. def _mock_gdb_output(coredump_path):
  83. return (mock_empty_crash_log, [])
  84. port = self.make_port()
  85. port._get_gdb_output = mock_empty_crash_log
  86. stderr, log = port._get_crash_log("DumpRenderTree", 28529, "", "", newer_than=None)
  87. self.assertEqual(stderr, "")
  88. self.assertMultiLineEqual(log, mock_empty_crash_log)
  89. stderr, log = port._get_crash_log("DumpRenderTree", 28529, "", "", newer_than=0.0)
  90. self.assertEqual(stderr, "")
  91. self.assertMultiLineEqual(log, mock_empty_crash_log)