1 # Copyright (C) 2013 Google Inc. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
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
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.
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.
32 from webkitpy.common.host_mock import MockHost
33 from webkitpy.common.checkout.scm.scm_mock import MockSCM
34 from webkitpy.common.system.filesystem_mock import MockFileSystem
35 from webkitpy.layout_tests.layout_tests_mover import LayoutTestsMover
36 from webkitpy.layout_tests.port import base
39 class MockPort(base.Port):
41 def __init__(self, **kwargs):
42 # This sets up a mock FileSystem and SCM using that FileSystem.
44 super(MockPort, self).__init__(host, host.port_factory.all_port_names()[0], **kwargs)
46 host.filesystem.maybe_make_directory(self._absolute_path('platform'))
47 host.filesystem.maybe_make_directory(self._absolute_path('existing_directory'))
48 host.filesystem.write_text_file(self._absolute_path('existing_file.txt'), '')
49 host.filesystem.write_text_file(self._absolute_path('TestExpectations'), """
50 crbug.com/42 [ Debug ] origin/path/test.html [ Pass Timeout Failure ]
51 crbug.com/42 [ Win ] origin/path [ Slow ]
52 crbug.com/42 [ Release ] origin [ Crash ]
54 host.filesystem.write_text_file(self._absolute_path('existing_directory_with_contents', 'test.html'), '')
55 host.filesystem.write_text_file(self._absolute_path('origin', 'path', 'test.html'), """
56 <script src="local_script.js">
57 <script src="../../unmoved/remote_script.js">
58 <script src='../../unmoved/remote_script_single_quotes.js'>
59 <script href="../../unmoved/remote_script.js">
60 <script href='../../unmoved/remote_script_single_quotes.js'>
63 host.filesystem.write_text_file(self._absolute_path('origin', 'path', 'test.css'), """
64 url('../../unmoved/url_function.js')
65 url("../../unmoved/url_function_double_quotes.js")
66 url(../../unmoved/url_function_no_quotes.js)
70 host.filesystem.write_text_file(self._absolute_path('origin', 'path', 'test.js'), """
71 importScripts('../../unmoved/import_scripts_function.js')
72 importScripts("../../unmoved/import_scripts_function_double_quotes.js")
75 host.filesystem.write_text_file(self._absolute_path('unmoved', 'test.html'), """
76 <script src="local_script.js">
77 <script src="../origin/path/remote_script.js">
80 def _absolute_path(self, *paths):
81 return self.host.scm().absolute_path('LayoutTests', *paths)
83 def layout_tests_dir(self):
84 return self._absolute_path()
87 class LayoutTestsMoverTest(unittest.TestCase):
92 self._filesystem = self._port.host.filesystem
93 self._mover = LayoutTestsMover(port=self._port)
95 def test_non_existent_origin_raises(self):
96 self.assertRaises(Exception, self._mover.move, 'non_existent', 'destination')
98 def test_origin_outside_layout_tests_directory_raises(self):
99 self.assertRaises(Exception, self._mover.move, '../outside', 'destination')
101 def test_file_destination_raises(self):
102 self.assertRaises(Exception, self._mover.move, 'origin/path', 'existing_file.txt')
104 def test_destination_outside_layout_tests_directory_raises(self):
105 self.assertRaises(Exception, self._mover.move, 'origin/path', '../outside')
107 def test_basic_operation(self):
108 self._mover.move('origin/path', 'destination')
109 self.assertFalse(self._filesystem.exists(self._port._absolute_path('origin/path')))
110 self.assertTrue(self._filesystem.isfile(self._port._absolute_path('destination/test.html')))
112 def test_move_to_existing_directory(self):
113 self._mover.move('origin/path', 'existing_directory')
114 self.assertFalse(self._filesystem.exists(self._port._absolute_path('origin', 'path')))
115 self.assertTrue(self._filesystem.isfile(self._port._absolute_path('existing_directory', 'test.html')))
117 def test_collision_in_existing_directory_raises(self):
118 self.assertRaises(Exception, self._mover.move, 'origin/path', 'existing_directory_with_contents')
120 def test_move_to_layout_tests_root(self):
121 self._mover.move('origin/path', '')
122 self.assertFalse(self._filesystem.exists(self._port._absolute_path('origin', 'path')))
123 self.assertTrue(self._filesystem.isfile(self._port._absolute_path('test.html')))
125 def test_moved_reference_in_moved_file_not_updated(self):
126 self._mover.move('origin/path', 'destination')
127 self.assertTrue('src="local_script.js"' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))
129 def test_unmoved_reference_in_unmoved_file_not_updated(self):
130 self._mover.move('origin/path', 'destination')
131 self.assertTrue('src="local_script.js"' in self._filesystem.read_text_file(self._port._absolute_path('unmoved', 'test.html')))
133 def test_moved_reference_in_unmoved_file_is_updated(self):
134 self._mover.move('origin/path', 'destination')
135 self.assertTrue('src="../destination/remote_script.js"' in self._filesystem.read_text_file(self._port._absolute_path('unmoved', 'test.html')))
137 def test_unmoved_reference_in_moved_file_is_updated(self):
138 self._mover.move('origin/path', 'destination')
139 self.assertTrue('src="../unmoved/remote_script.js"' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))
141 def test_references_in_html_file_are_updated(self):
142 self._mover.move('origin/path', 'destination')
143 self.assertTrue('src="../unmoved/remote_script.js"' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))
144 self.assertTrue('src=\'../unmoved/remote_script_single_quotes.js\'' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))
145 self.assertTrue('href="../unmoved/remote_script.js"' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))
146 self.assertTrue('href=\'../unmoved/remote_script_single_quotes.js\'' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))
147 self.assertTrue('href=""' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))
149 def test_references_in_css_file_are_updated(self):
150 self._mover.move('origin/path', 'destination')
151 self.assertTrue('url(\'../unmoved/url_function.js\')' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.css')))
152 self.assertTrue('url("../unmoved/url_function_double_quotes.js")' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.css')))
153 self.assertTrue('url(../unmoved/url_function_no_quotes.js)' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.css')))
154 self.assertTrue('url(\'\')' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.css')))
155 self.assertTrue('url()' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.css')))
157 def test_references_in_javascript_file_are_updated(self):
158 self._mover.move('origin/path', 'destination')
159 self.assertTrue('importScripts(\'../unmoved/import_scripts_function.js\')' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.js')))
160 self.assertTrue('importScripts("../unmoved/import_scripts_function_double_quotes.js")' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.js')))
161 self.assertTrue('importScripts(\'\')' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.js')))
163 def test_expectation_is_updated(self):
164 self._mover.move('origin/path', 'destination')
165 self.assertFalse('origin/path/test.html' in self._filesystem.read_text_file(self._port._absolute_path('TestExpectations')))
166 self.assertTrue('crbug.com/42 [ Debug ] destination/test.html [ Pass Timeout Failure ]'
167 in self._filesystem.read_text_file(self._port._absolute_path('TestExpectations')))
169 def test_directory_expectation_is_updated(self):
170 self._mover.move('origin/path', 'destination')
171 self.assertFalse('origin/path' in self._filesystem.read_text_file(self._port._absolute_path('TestExpectations')))
172 self.assertTrue('crbug.com/42 [ Win ] destination [ Slow ]' in self._filesystem.read_text_file(self._port._absolute_path('TestExpectations')))
174 def test_expectation_is_added_when_subdirectory_moved(self):
175 self._mover.move('origin/path', 'destination')
176 self.assertTrue('crbug.com/42 [ Release ] origin [ Crash ]' in self._filesystem.read_text_file(self._port._absolute_path('TestExpectations')))
177 self.assertTrue('crbug.com/42 [ Release ] destination [ Crash ]' in self._filesystem.read_text_file(self._port._absolute_path('TestExpectations')))