Home | History | Annotate | Download | only in port
      1 # Copyright (C) 2014 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 Google name 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 
     29 from webkitpy.layout_tests.port import driver
     30 import time
     31 import shutil
     32 
     33 
     34 class BrowserTestDriver(driver.Driver):
     35     """Object for running print preview test(s) using browser_tests."""
     36     def __init__(self, port, worker_number, pixel_tests, no_timeout=False):
     37         """Invokes the constructor of driver.Driver."""
     38         super(BrowserTestDriver, self).__init__(port, worker_number, pixel_tests, no_timeout)
     39 
     40     def start(self, pixel_tests, per_test_args, deadline):
     41         """Same as Driver.start() however, it has an extra step. It waits for
     42         a path to a file to be used for stdin to be printed by the browser test.
     43         If a path is found by the deadline test test will open the file and
     44         assign it to the stdin of the process that is owned by this driver's
     45         server process.
     46         """
     47         # FIXME(ivandavid): Need to handle case where the layout test doesn't
     48         # get a file name.
     49         new_cmd_line = self.cmd_line(pixel_tests, per_test_args)
     50         if not self._server_process or new_cmd_line != self._current_cmd_line:
     51             self._start(pixel_tests, per_test_args)
     52             self._run_post_start_tasks()
     53             self._open_stdin_path(deadline)
     54 
     55     # Gets the path of the directory that the file for stdin communication is
     56     # in. Since the browser test cannot clean it up, the layout test framework
     57     # will. Everything the browser test uses is stored in the same directory as
     58     # the stdin file, so deleting that directory recursively will remove all the
     59     # other temp data, like the printed pdf. This function assumes the correct
     60     # file path is sent. It won't delete files with only one component to avoid
     61     # accidentally deleting files like /tmp.
     62     def _open_stdin_path(self, deadline, test=False):
     63         # FIXME(ivandavid): Come up with a way to test & see what happens when
     64         # the file can't be opened.
     65         path, found = self._read_stdin_path(deadline)
     66         if found:
     67             if test == False:
     68                 self._server_process._proc.stdin = open(path, 'wb', 0)
     69 
     70     def _read_stdin_path(self, deadline):
     71         # return (stdin_path, bool)
     72         block = self._read_block(deadline)
     73         if block.stdin_path:
     74             return (block.stdin_path, True)
     75         return (None, False)
     76 
     77     def cmd_line(self, pixel_tests, per_test_args):
     78         """Command line arguments to run the browser test."""
     79         cmd = self._command_wrapper(self._port.get_option('wrapper'))
     80         cmd.append(self._port._path_to_driver())
     81         cmd.append('--gtest_filter=PrintPreviewPdfGeneratedBrowserTest.MANUAL_LayoutTestDriver')
     82         cmd.append('--run-manual')
     83         cmd.append('--single_process')
     84         cmd.extend(per_test_args)
     85         cmd.extend(self._port.get_option('additional_drt_flag', []))
     86         return cmd
     87 
     88     def stop(self):
     89         if self._server_process:
     90             self._server_process.write('QUIT')
     91         super(BrowserTestDriver, self).stop(self._port.driver_stop_timeout())
     92