win_unittest.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 StringIO
  29. import unittest2 as unittest
  30. from webkitpy.common.system.executive import ScriptError
  31. from webkitpy.common.system.executive_mock import MockExecutive, MockExecutive2
  32. from webkitpy.common.system.filesystem_mock import MockFileSystem
  33. from webkitpy.common.system.outputcapture import OutputCapture
  34. from webkitpy.common.system.systemhost_mock import MockSystemHost
  35. from webkitpy.port import port_testcase
  36. from webkitpy.port.win import WinPort
  37. from webkitpy.tool.mocktool import MockOptions
  38. class WinPortTest(port_testcase.PortTestCase):
  39. os_name = 'win'
  40. os_version = 'xp'
  41. port_name = 'win-xp'
  42. port_maker = WinPort
  43. def test_show_results_html_file(self):
  44. port = self.make_port()
  45. port._executive = MockExecutive(should_log=True)
  46. capture = OutputCapture()
  47. capture.capture_output()
  48. port.show_results_html_file('test.html')
  49. _, _, logs = capture.restore_output()
  50. # We can't know for sure what path will be produced by cygpath, but we can assert about
  51. # everything else.
  52. self.assertTrue(logs.startswith("MOCK run_command: ['Tools/Scripts/run-safari', '--release', '"))
  53. self.assertTrue(logs.endswith("test.html'], cwd=/mock-checkout\n"))
  54. def _assert_search_path(self, expected_search_paths, version, use_webkit2=False):
  55. port = self.make_port(port_name='win', os_version=version, options=MockOptions(webkit_test_runner=use_webkit2))
  56. absolute_search_paths = map(port._webkit_baseline_path, expected_search_paths)
  57. self.assertEqual(port.baseline_search_path(), absolute_search_paths)
  58. def test_baseline_search_path(self):
  59. self._assert_search_path(['win-xp', 'win-vista', 'win-7sp0', 'win', 'mac-lion', 'mac'], 'xp')
  60. self._assert_search_path(['win-vista', 'win-7sp0', 'win', 'mac-lion', 'mac'], 'vista')
  61. self._assert_search_path(['win-7sp0', 'win', 'mac-lion', 'mac'], '7sp0')
  62. self._assert_search_path(['win-wk2', 'win-xp', 'win-vista', 'win-7sp0', 'win', 'mac-wk2', 'mac-lion', 'mac'], 'xp', use_webkit2=True)
  63. self._assert_search_path(['win-wk2', 'win-vista', 'win-7sp0', 'win', 'mac-wk2', 'mac-lion', 'mac'], 'vista', use_webkit2=True)
  64. self._assert_search_path(['win-wk2', 'win-7sp0', 'win', 'mac-wk2', 'mac-lion', 'mac'], '7sp0', use_webkit2=True)
  65. def _assert_version(self, port_name, expected_version):
  66. host = MockSystemHost(os_name='win', os_version=expected_version)
  67. port = WinPort(host, port_name=port_name)
  68. self.assertEqual(port.version(), expected_version)
  69. def test_versions(self):
  70. self._assert_version('win-xp', 'xp')
  71. self._assert_version('win-vista', 'vista')
  72. self._assert_version('win-7sp0', '7sp0')
  73. self.assertRaises(AssertionError, self._assert_version, 'win-me', 'xp')
  74. def test_compare_text(self):
  75. expected = "EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification\nfoo\nEDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n"
  76. port = self.make_port()
  77. self.assertFalse(port.do_text_results_differ(expected, "foo\n"))
  78. self.assertTrue(port.do_text_results_differ(expected, "foo"))
  79. self.assertTrue(port.do_text_results_differ(expected, "bar"))
  80. # This hack doesn't exist in WK2.
  81. port._options = MockOptions(webkit_test_runner=True)
  82. self.assertTrue(port.do_text_results_differ(expected, "foo\n"))
  83. def test_operating_system(self):
  84. self.assertEqual('win', self.make_port().operating_system())
  85. def test_runtime_feature_list(self):
  86. port = self.make_port()
  87. port._executive.run_command = lambda command, cwd=None, error_handler=None: "Nonsense"
  88. # runtime_features_list returns None when its results are meaningless (it couldn't run DRT or parse the output, etc.)
  89. self.assertEqual(port._runtime_feature_list(), None)
  90. port._executive.run_command = lambda command, cwd=None, error_handler=None: "SupportedFeatures:foo bar"
  91. self.assertEqual(port._runtime_feature_list(), ['foo', 'bar'])
  92. def test_expectations_files(self):
  93. self.assertEqual(len(self.make_port().expectations_files()), 3)
  94. self.assertEqual(len(self.make_port(options=MockOptions(webkit_test_runner=True, configuration='Release')).expectations_files()), 5)
  95. def test_get_crash_log(self):
  96. # Win crash logs are tested elsewhere, so here we just make sure we don't crash.
  97. def fake_time_cb():
  98. times = [0, 20, 40]
  99. return lambda: times.pop(0)
  100. port = self.make_port(port_name='win')
  101. port._get_crash_log('DumpRenderTree', 1234, '', '', 0,
  102. time_fn=fake_time_cb(), sleep_fn=lambda delay: None)