OLD | NEW |
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 """Utility script to launch browser-tests on the Chromoting bot.""" | 6 """Utility script to launch browser-tests on the Chromoting bot.""" |
7 import argparse | 7 import argparse |
8 import glob | 8 import glob |
9 import hashlib | 9 import hashlib |
10 import os | 10 import os |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop') | 73 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop') |
74 | 74 |
75 # Cleanup any host logs. | 75 # Cleanup any host logs. |
76 RunCommandInSubProcess('rm /tmp/chrome_remote_desktop_*') | 76 RunCommandInSubProcess('rm /tmp/chrome_remote_desktop_*') |
77 | 77 |
78 # Remove the user-profile dir | 78 # Remove the user-profile dir |
79 if os.path.exists(user_profile_dir): | 79 if os.path.exists(user_profile_dir): |
80 shutil.rmtree(user_profile_dir) | 80 shutil.rmtree(user_profile_dir) |
81 | 81 |
82 | 82 |
83 def InitialiseTestMachineForLinux(cfg_file, manifest_file, user_profile_dir): | 83 def InitialiseTestMachineForLinux(cfg_file): |
84 """Sets up a Linux machine for connect-to-host browser-tests. | 84 """Sets up a Linux machine for connect-to-host browser-tests. |
85 | 85 |
86 Copy over me2me host-config and manifest files to expected locations. | 86 Copy over me2me host-config to expected locations. |
87 By default, the Linux me2me host expects the host-config file to be under | 87 By default, the Linux me2me host expects the host-config file to be under |
88 $HOME/.config/chrome-remote-desktop | 88 $HOME/.config/chrome-remote-desktop |
89 Its name is expected to have a hash that is specific to a machine. | 89 Its name is expected to have a hash that is specific to a machine. |
90 | 90 |
91 When a user launches the remoting web-app, the native-message host process is | |
92 started. For this to work, the manifest file for me2me host is expected to be | |
93 in a specific folder under the user-profile dir. | |
94 | |
95 This function performs both the above tasks. | |
96 | |
97 TODO(anandc): | 91 TODO(anandc): |
98 Once we have Linux machines in the swarming lab already installed with the | 92 Once we have Linux machines in the swarming lab already installed with the |
99 me2me host, this function should also perform the step of starting the host. | 93 me2me host, this function should also perform the step of starting the host. |
100 That is gated on this CL: https://chromereviews.googleplex.com/123957013/, and | 94 That is gated on this CL: https://chromereviews.googleplex.com/123957013/, and |
101 then having base images in the chrome-labs be updated with it. | 95 then having base images in the chrome-labs be updated with it. |
102 | 96 |
103 Args: | 97 Args: |
104 cfg_file: location of test account's host-config file. | 98 cfg_file: location of test account's host-config file. |
105 manifest_file: location of me2me host manifest file. | |
106 user_profile_dir: user-profile-dir to be used by the connect-to-host tests. | |
107 """ | 99 """ |
108 | 100 |
109 # First get home directory on current machine. | 101 # First get home directory on current machine. |
110 home_dir = expanduser('~') | 102 home_dir = expanduser('~') |
111 default_config_file_location = os.path.join(home_dir, '.config', CRD_ID) | 103 default_config_file_location = os.path.join(home_dir, '.config', CRD_ID) |
112 if os.path.exists(default_config_file_location): | 104 if os.path.exists(default_config_file_location): |
113 shutil.rmtree(default_config_file_location) | 105 shutil.rmtree(default_config_file_location) |
114 os.makedirs(default_config_file_location) | 106 os.makedirs(default_config_file_location) |
115 | 107 |
116 # Copy over test host-config to expected location, with expected file-name. | 108 # Copy over test host-config to expected location, with expected file-name. |
117 # The file-name should contain a hash-value that is machine-specific. | 109 # The file-name should contain a hash-value that is machine-specific. |
118 default_config_file_name = 'host#%s.json' % HOST_HASH_VALUE | 110 default_config_file_name = 'host#%s.json' % HOST_HASH_VALUE |
119 config_file_src = os.path.join(os.getcwd(), cfg_file) | 111 config_file_src = os.path.join(os.getcwd(), cfg_file) |
120 shutil.copyfile( | 112 shutil.copyfile( |
121 config_file_src, | 113 config_file_src, |
122 os.path.join(default_config_file_location, default_config_file_name)) | 114 os.path.join(default_config_file_location, default_config_file_name)) |
123 | 115 |
124 # Next, create a user-profile dir, and place the me2me manifest.json file in | 116 # Finally, start chromoting host. |
125 # the expected location for native-messating-host to work properly. | 117 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start') |
| 118 |
| 119 |
| 120 def SetupUserProfileDir(me2me_manifest_file, it2me_manifest_file, |
| 121 user_profile_dir): |
| 122 """Sets up the Google Chrome user profile directory |
| 123 |
| 124 Delete the previous user profile directory if exists and create a new one. |
| 125 This invalidates any state changes by the previous test so each test can start |
| 126 with the same environment. |
| 127 |
| 128 When a user launches the remoting web-app, the native messaging host process |
| 129 is started. For this to work, this function places the me2me and it2me native |
| 130 messaging host manifest files in a specific folder under the user-profile dir. |
| 131 |
| 132 Args: |
| 133 me2me_manifest_file: location of me2me native messaging host manifest file. |
| 134 it2me_manifest_file: location of it2me native messaging host manifest file. |
| 135 user_profile_dir: Chrome user-profile-directory. |
| 136 """ |
126 native_messaging_folder = os.path.join(user_profile_dir, NATIVE_MESSAGING_DIR) | 137 native_messaging_folder = os.path.join(user_profile_dir, NATIVE_MESSAGING_DIR) |
127 | 138 |
128 if os.path.exists(user_profile_dir): | 139 if os.path.exists(user_profile_dir): |
129 shutil.rmtree(user_profile_dir) | 140 shutil.rmtree(user_profile_dir) |
130 os.makedirs(native_messaging_folder) | 141 os.makedirs(native_messaging_folder) |
131 | 142 |
132 manifest_file_src = os.path.join(os.getcwd(), manifest_file) | 143 manifest_files = [me2me_manifest_file, it2me_manifest_file] |
133 manifest_file_dest = ( | 144 for manifest_file in manifest_files: |
134 os.path.join(native_messaging_folder, os.path.basename(manifest_file))) | 145 manifest_file_src = os.path.join(os.getcwd(), manifest_file) |
135 shutil.copyfile(manifest_file_src, manifest_file_dest) | 146 manifest_file_dest = ( |
136 | 147 os.path.join(native_messaging_folder, os.path.basename(manifest_file))) |
137 # Finally, start chromoting host. | 148 shutil.copyfile(manifest_file_src, manifest_file_dest) |
138 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start') | |
139 | 149 |
140 | 150 |
141 def main(): | 151 def main(): |
142 parser = argparse.ArgumentParser() | 152 parser = argparse.ArgumentParser() |
143 parser.add_argument('-f', '--commands_file', | 153 parser.add_argument('-f', '--commands_file', |
144 help='path to file listing commands to be launched.') | 154 help='path to file listing commands to be launched.') |
145 parser.add_argument('-p', '--prod_dir', | 155 parser.add_argument('-p', '--prod_dir', |
146 help='path to folder having product and test binaries.') | 156 help='path to folder having product and test binaries.') |
147 parser.add_argument('-c', '--cfg_file', | 157 parser.add_argument('-c', '--cfg_file', |
148 help='path to test host config file.') | 158 help='path to test host config file.') |
149 parser.add_argument('-m', '--manifest_file', | 159 parser.add_argument('--me2me_manifest_file', |
150 help='path to me2me host manifest file.') | 160 help='path to me2me host manifest file.') |
| 161 parser.add_argument('--it2me_manifest_file', |
| 162 help='path to it2me host manifest file.') |
151 parser.add_argument( | 163 parser.add_argument( |
152 '-u', '--user_profile_dir', | 164 '-u', '--user_profile_dir', |
153 help='path to user-profile-dir, used by connect-to-host tests.') | 165 help='path to user-profile-dir, used by connect-to-host tests.') |
154 | 166 |
155 args = parser.parse_args() | 167 args = parser.parse_args() |
156 | 168 |
157 InitialiseTestMachineForLinux(args.cfg_file, args.manifest_file, | 169 InitialiseTestMachineForLinux(args.cfg_file) |
158 args.user_profile_dir) | |
159 | 170 |
160 with open(args.commands_file) as f: | 171 with open(args.commands_file) as f: |
161 for line in f: | 172 for line in f: |
| 173 # Reset the user profile directory to start each test with a clean slate. |
| 174 SetupUserProfileDir(args.me2me_manifest_file, args.it2me_manifest_file, |
| 175 args.user_profile_dir) |
| 176 |
162 # Replace the PROD_DIR value in the command-line with | 177 # Replace the PROD_DIR value in the command-line with |
163 # the passed in value. | 178 # the passed in value. |
164 line = line.replace(PROD_DIR_ID, args.prod_dir) | 179 line = line.replace(PROD_DIR_ID, args.prod_dir) |
165 LaunchBTCommand(line) | 180 LaunchBTCommand(line) |
166 | 181 |
167 # Now, stop host, and cleanup user-profile-dir | 182 # Now, stop host, and cleanup user-profile-dir |
168 TestCleanUp(args.user_profile_dir) | 183 TestCleanUp(args.user_profile_dir) |
169 | 184 |
170 if __name__ == '__main__': | 185 if __name__ == '__main__': |
171 main() | 186 main() |
OLD | NEW |