Simplified ChromeBinaryTest without pyauto dependency.

BUG=chromium:345153
TEST=build and run the test on daisy

Change-Id: Ic6f13c4aef1f214ff21ff111199b06cd4272ae06
Reviewed-on: https://chromium-review.googlesource.com/188167
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: Yuli Huang <yuli@chromium.org>
Tested-by: Yuli Huang <yuli@chromium.org>
Reviewed-by: Achuith Bhandarkar <achuith@chromium.org>
Commit-Queue: Yuli Huang <yuli@chromium.org>
diff --git a/client/cros/chrome_binary_test.py b/client/cros/chrome_binary_test.py
new file mode 100755
index 0000000..da478f7
--- /dev/null
+++ b/client/cros/chrome_binary_test.py
@@ -0,0 +1,65 @@
+# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os, shutil, tempfile
+
+import cros_ui
+from autotest_lib.client.bin import test
+from autotest_lib.client.common_lib import error
+
+
+class ChromeBinaryTest(test.test):
+    """
+    Base class for tests to run chrome test binaries without signing in and
+    running Chrome.
+    """
+
+    CHROME_TEST_DEP = 'chrome_test'
+    CHROME_SANDBOX = '/opt/google/chrome/chrome-sandbox'
+    home_dir = None
+
+    def setup(self):
+        self.job.setup_dep([self.CHROME_TEST_DEP])
+
+
+    def initialize(self):
+        test_dep_dir = os.path.join(self.autodir, 'deps',
+                                    self.CHROME_TEST_DEP)
+        self.job.install_pkg(self.CHROME_TEST_DEP, 'dep', test_dep_dir)
+
+        self.cr_source_dir = '%s/test_src' % test_dep_dir
+        self.test_binary_dir = '%s/out/Release' % self.cr_source_dir
+        self.home_dir = tempfile.mkdtemp()
+
+
+    def cleanup(self):
+        if self.home_dir:
+            shutil.rmtree(self.home_dir, ignore_errors=True)
+
+
+    def run_chrome_test_binary(self, binary_to_run, extra_params='', prefix='',
+                               as_chronos=True):
+        """
+        Run chrome test binary.
+
+        @param binary_to_run: The name of the browser test binary.
+        @param extra_params: Arguments for the browser test binary.
+        @param prefix: Prefix to the command that invokes the test binary.
+        @param as_chronos: Boolean indicating if the tests should run in a
+            chronos shell.
+
+        @raises: error.TestFail if there is error running the command.
+        """
+        cmd = '%s/%s %s' % (self.test_binary_dir, binary_to_run, extra_params)
+        env_vars = 'HOME=%s CR_SOURCE_ROOT=%s CHROME_DEVEL_SANDBOX=%s' % (
+                self.home_dir, self.cr_source_dir, self.CHROME_SANDBOX)
+        cmd = '%s %s' % (env_vars, prefix + cmd)
+
+        try:
+            if as_chronos:
+                cros_ui.xsystem_as(cmd, user='chronos')
+            else:
+                cros_ui.xsystem(cmd)
+        except error.CmdError as e:
+            raise error.TestFail('%s failed! %s' % (binary_to_run, e))