deploy_chrome: Add an arg to deploy test binaries.

Some tast tests expect to find test binaries built within chromium at
/usr/local/libexec/chrome-binary-tests on the device.

This adds an arg to deploy_chrome to replace those binaries with any
found in the local build dir. This will allow those tests to be executed
with their respective binaries built at ToT instead of with the ones
shipped with the device image.

BUG=chromium:1099963
TEST=unittest
TEST=ran this on a failing chrome patch:
    https://chrome-swarming.appspot.com/task?id=4d25f16fceedf210

Change-Id: Id08a73644ca9e03c693b09d388e3f13dd6c8edb9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2277078
Reviewed-by: Achuith Bhandarkar <achuith@chromium.org>
Commit-Queue: Ben Pastene <bpastene@chromium.org>
Tested-by: Ben Pastene <bpastene@chromium.org>
diff --git a/scripts/deploy_chrome_unittest.py b/scripts/deploy_chrome_unittest.py
index b8c784a..b63d0c4 100644
--- a/scripts/deploy_chrome_unittest.py
+++ b/scripts/deploy_chrome_unittest.py
@@ -372,3 +372,46 @@
     self.deploy._CheckDeployType()
     self.assertTrue(self.getCopyPath('chrome'))
     self.assertFalse(self.getCopyPath('app_shell'))
+
+
+class TestDeployTestBinaries(cros_test_lib.RunCommandTempDirTestCase):
+  """Tests _DeployTestBinaries()."""
+
+  def setUp(self):
+    options = _ParseCommandLine(list(_REGULAR_TO) + [
+        '--board', _TARGET_BOARD, '--force', '--mount',
+        '--build-dir', os.path.join(self.tempdir, 'build_dir'),
+        '--nostrip'])
+    self.deploy = deploy_chrome.DeployChrome(
+        options, self.tempdir, os.path.join(self.tempdir, 'staging'))
+
+  def testFindError(self):
+    """Ensure an error is thrown if we can't inspect the device."""
+    self.rc.AddCmdResult(
+        partial_mock.In(deploy_chrome._FIND_TEST_BIN_CMD), 1)
+    self.assertRaises(
+        deploy_chrome.DeployFailure, self.deploy._DeployTestBinaries)
+
+  def testSuccess(self):
+    """Ensure the staging dir contains the right binaries to copy over."""
+    test_binaries = [
+        'run_a_tests',
+        'run_b_tests',
+        'run_c_tests',
+    ]
+    # Simulate having the binaries both on the device and in our local build
+    # dir.
+    self.rc.AddCmdResult(
+        partial_mock.In(deploy_chrome._FIND_TEST_BIN_CMD),
+        stdout='\n'.join(test_binaries))
+    for binary in test_binaries:
+      osutils.Touch(os.path.join(self.deploy.options.build_dir, binary),
+                    makedirs=True, mode=0o700)
+
+    self.deploy._DeployTestBinaries()
+
+    # Ensure the binaries were placed in the staging dir used to copy them over.
+    staging_dir = os.path.join(
+        self.tempdir, os.path.basename(deploy_chrome._CHROME_TEST_BIN_DIR))
+    for binary in test_binaries:
+      self.assertIn(binary, os.listdir(staging_dir))