OLD | NEW |
| (Empty) |
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 self._stdin_directory = None | |
40 | |
41 def start(self, pixel_tests, per_test_args, deadline): | |
42 """Same as Driver.start() however, it has an extra step. It waits for | |
43 a path to a file to be used for stdin to be printed by the browser test. | |
44 If a path is found by the deadline test test will open the file and | |
45 assign it to the stdin of the process that is owned by this driver's | |
46 server process. | |
47 """ | |
48 # FIXME(ivandavid): Need to handle case where the layout test doesn't | |
49 # get a file name. | |
50 new_cmd_line = self.cmd_line(pixel_tests, per_test_args) | |
51 if not self._server_process or new_cmd_line != self._current_cmd_line: | |
52 self._start(pixel_tests, per_test_args) | |
53 self._run_post_start_tasks() | |
54 self._open_stdin_path(deadline) | |
55 | |
56 # Gets the path of the directory that the file for stdin | |
57 # communication is in. Since the browser test cannot clean it | |
58 # up, the layout test framework will. Everything the browser test | |
59 # uses is stored in the same directory as the stdin file, so | |
60 # deleting that directory recursively will remove all the other | |
61 # temp data, like the printed pdf. | |
62 # Assumes that the correct file is sent, however if the path | |
63 # only contains one component, like '/foo' the the directory | |
64 # won't be deleted as it might be wrong. | |
65 def _open_stdin_path(self, deadline, test=False): | |
66 path, found = self._read_stdin_path(deadline) | |
67 if found: | |
68 if test == False: | |
69 self._server_process._proc.stdin = open(path, 'wb', 0) | |
70 path_split = path.split(self._port.TEST_PATH_SEPARATOR) | |
71 if len(path_split) > 2: | |
72 del path_split[-1] | |
73 self._stdin_directory = self._port.TEST_PATH_SEPARATOR.join(path
_split) | |
74 else: | |
75 self._stdin_directory = path | |
76 | |
77 def _read_stdin_path(self, deadline): | |
78 # return (stdin_path, bool) | |
79 block = self._read_block(deadline) | |
80 if block.stdin_path: | |
81 return (block.stdin_path, True) | |
82 return (None, False) | |
83 | |
84 def cmd_line(self, pixel_tests, per_test_args): | |
85 """Command line arguments to run the browser test.""" | |
86 cmd = self._command_wrapper(self._port.get_option('wrapper')) | |
87 cmd.append(self._port._path_to_driver()) | |
88 cmd.append('--gtest_filter=PrintPreviewPdfGeneratedBrowserTest.MANUAL_La
youtTestDriver') | |
89 cmd.append('--run-manual') | |
90 cmd.append('--single_process') | |
91 cmd.extend(per_test_args) | |
92 cmd.extend(self._port.get_option('additional_drt_flag', [])) | |
93 return cmd | |
94 | |
95 def __del__(self): | |
96 if self._stdin_directory: | |
97 shutil.rmtree(self._stdin_directory, ignore_errors=True) | |
OLD | NEW |