コード例 #1
0
 def setUp(self):
     port = MockPort()
     self._port = port
     self._filesystem = self._port.host.filesystem
     self._mover = LayoutTestsMover(port=self._port)
コード例 #2
0
class LayoutTestsMoverTest(unittest.TestCase):

    def setUp(self):
        port = MockPort()
        self._port = port
        self._filesystem = self._port.host.filesystem
        self._mover = LayoutTestsMover(port=self._port)

    def test_non_existent_origin_raises(self):
        self.assertRaises(Exception, self._mover.move, 'non_existent', 'destination')

    def test_origin_outside_layout_tests_directory_raises(self):
        self.assertRaises(Exception, self._mover.move, '../outside', 'destination')

    def test_file_destination_raises(self):
        self.assertRaises(Exception, self._mover.move, 'origin/path', 'existing_file.txt')

    def test_destination_outside_layout_tests_directory_raises(self):
        self.assertRaises(Exception, self._mover.move, 'origin/path', '../outside')

    def test_basic_operation(self):
        self._mover.move('origin/path', 'destination')
        self.assertFalse(self._filesystem.exists(self._port._absolute_path('origin/path')))
        self.assertTrue(self._filesystem.isfile(self._port._absolute_path('destination/test.html')))

    def test_move_to_existing_directory(self):
        self._mover.move('origin/path', 'existing_directory')
        self.assertFalse(self._filesystem.exists(self._port._absolute_path('origin', 'path')))
        self.assertTrue(self._filesystem.isfile(self._port._absolute_path('existing_directory', 'test.html')))

    def test_collision_in_existing_directory_raises(self):
        self.assertRaises(Exception, self._mover.move, 'origin/path', 'existing_directory_with_contents')

    def test_move_to_layout_tests_root(self):
        self._mover.move('origin/path', '')
        self.assertFalse(self._filesystem.exists(self._port._absolute_path('origin', 'path')))
        self.assertTrue(self._filesystem.isfile(self._port._absolute_path('test.html')))

    def test_moved_reference_in_moved_file_not_updated(self):
        self._mover.move('origin/path', 'destination')
        self.assertTrue('src="local_script.js"' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))

    def test_unmoved_reference_in_unmoved_file_not_updated(self):
        self._mover.move('origin/path', 'destination')
        self.assertTrue('src="local_script.js"' in self._filesystem.read_text_file(self._port._absolute_path('unmoved', 'test.html')))

    def test_moved_reference_in_unmoved_file_is_updated(self):
        self._mover.move('origin/path', 'destination')
        self.assertTrue('src="../destination/remote_script.js"' in self._filesystem.read_text_file(self._port._absolute_path('unmoved', 'test.html')))

    def test_unmoved_reference_in_moved_file_is_updated(self):
        self._mover.move('origin/path', 'destination')
        self.assertTrue('src="../unmoved/remote_script.js"' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))

    def test_references_in_html_file_are_updated(self):
        self._mover.move('origin/path', 'destination')
        self.assertTrue('src="../unmoved/remote_script.js"' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))
        self.assertTrue('src=\'../unmoved/remote_script_single_quotes.js\'' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))
        self.assertTrue('href="../unmoved/remote_script.js"' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))
        self.assertTrue('href=\'../unmoved/remote_script_single_quotes.js\'' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))
        self.assertTrue('href=""' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.html')))

    def test_references_in_css_file_are_updated(self):
        self._mover.move('origin/path', 'destination')
        self.assertTrue('url(\'../unmoved/url_function.js\')' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.css')))
        self.assertTrue('url("../unmoved/url_function_double_quotes.js")' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.css')))
        self.assertTrue('url(../unmoved/url_function_no_quotes.js)' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.css')))
        self.assertTrue('url(\'\')' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.css')))
        self.assertTrue('url()' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.css')))

    def test_references_in_javascript_file_are_updated(self):
        self._mover.move('origin/path', 'destination')
        self.assertTrue('importScripts(\'../unmoved/import_scripts_function.js\')' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.js')))
        self.assertTrue('importScripts("../unmoved/import_scripts_function_double_quotes.js")' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.js')))
        self.assertTrue('importScripts(\'\')' in self._filesystem.read_text_file(self._port._absolute_path('destination', 'test.js')))

    def test_expectation_is_updated(self):
        self._mover.move('origin/path', 'destination')
        self.assertFalse('origin/path/test.html' in self._filesystem.read_text_file(self._port._absolute_path('TestExpectations')))
        self.assertTrue('crbug.com/42 [ Debug ] destination/test.html [ Pass Timeout Failure ]'
                        in self._filesystem.read_text_file(self._port._absolute_path('TestExpectations')))

    def test_directory_expectation_is_updated(self):
        self._mover.move('origin/path', 'destination')
        self.assertFalse('origin/path' in self._filesystem.read_text_file(self._port._absolute_path('TestExpectations')))
        self.assertTrue('crbug.com/42 [ Win ] destination [ Slow ]' in self._filesystem.read_text_file(self._port._absolute_path('TestExpectations')))

    def test_expectation_is_added_when_subdirectory_moved(self):
        self._mover.move('origin/path', 'destination')
        self.assertTrue('crbug.com/42 [ Release ] origin [ Crash ]' in self._filesystem.read_text_file(self._port._absolute_path('TestExpectations')))
        self.assertTrue('crbug.com/42 [ Release ] destination [ Crash ]' in self._filesystem.read_text_file(self._port._absolute_path('TestExpectations')))