[autotest] Adds chromecast deps, server, client test for sonic.
Adds an autotest dependency that installs the freshest
version of the chromecast extension as an autotest dep.
Also adds a server and client test for sonic that installs the
extension and performs a tab cast, and starts the youtube/netflix apps.
The tests will only work when the DUT and the sonic device are on
the same subnet.
TEST=emerge-lumpy autotest-deps, ran a test that uses it.
Ran the tests, visually verified results.
BUG=chromium:321177, chromium:321179, chromium:292640
Change-Id: I48a6149a11d3bb8167a1c766873e672b3523d769
Reviewed-on: https://chromium-review.googlesource.com/179407
Commit-Queue: Prashanth B <beeps@chromium.org>
Tested-by: Prashanth B <beeps@chromium.org>
Reviewed-by: Dan Shi <dshi@chromium.org>
diff --git a/client/common_lib/cros/chromedriver.py b/client/common_lib/cros/chromedriver.py
index a118433..65bd0a0 100644
--- a/client/common_lib/cros/chromedriver.py
+++ b/client/common_lib/cros/chromedriver.py
@@ -41,8 +41,10 @@
assert os.geteuid() == 0, 'Need superuser privileges'
# Log in with telemetry
- self._browser = chrome.Chrome(extension_paths=extension_paths,
- is_component=is_component).browser
+ self._chrome = chrome.Chrome(extension_paths=extension_paths,
+ is_component=is_component,
+ extra_browser_args=extra_chrome_flags)
+ self._browser = self._chrome.browser
# Start ChromeDriver server
self._server = chromedriver_server(CHROMEDRIVER_EXE_PATH)
@@ -81,6 +83,16 @@
del self._browser
+ def get_extension(self, extension_path):
+ """Gets an extension by proxying to the browser.
+
+ @param extension_path: Path to the extension loaded in the browser.
+
+ @return: A telemetry extension object representing the extension.
+ """
+ return self._chrome.get_extension(extension_path)
+
+
class chromedriver_server(object):
"""A running ChromeDriver server.
diff --git a/client/common_lib/site_utils.py b/client/common_lib/site_utils.py
index 69f769c..1a116c7 100644
--- a/client/common_lib/site_utils.py
+++ b/client/common_lib/site_utils.py
@@ -2,11 +2,13 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import glob
import logging
import os
import re
import signal
import socket
+import sys
import time
import urllib2
@@ -272,3 +274,32 @@
ver = match.group(0) if match else version_string
milestone = match.group(1) if match else ''
return ver, milestone
+
+
+def take_screenshot(dest_dir, fname_prefix, format='png'):
+ """Take screenshot and save to a new file in the dest_dir.
+
+ @param dest_dir: The destination directory to save the screenshot.
+ @param fname_prefix: Prefix for the output fname
+ @param format: String indicating file format ('png', 'jpg', etc)
+
+ @return: The path of the saved screenshot file
+ """
+ next_index = len(glob.glob(
+ os.path.join(dest_dir, '%s-*.%s' % (fname_prefix, format))))
+ screenshot_file = os.path.join(
+ dest_dir, '%s-%d.%s' % (fname_prefix, next_index, format))
+ logging.info('Saving screenshot to %s.', screenshot_file)
+
+ old_exc_type = sys.exc_info()[0]
+ try:
+ base_utils.system('DISPLAY=:0.0 XAUTHORITY=/home/chronos/.Xauthority '
+ '/usr/local/bin/import -window root -depth 8 %s' %
+ screenshot_file)
+ except Exception as err:
+ # Do not raise an exception if the screenshot fails while processing
+ # another exception.
+ if old_exc_type is None:
+ raise
+ logging.error(err)
+ return screenshot_file