• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import os
6
7from autotest_lib.client.bin import test, utils
8from autotest_lib.client.common_lib import error
9from autotest_lib.client.common_lib.cros import chrome
10
11
12class desktopui_CameraApp(test.test):
13    """Tests if the Camera App works correctly."""
14    version = 1
15    preserve_srcdir = True
16
17
18    def setup(self):
19        """Fetches and builds the ToT Camera App."""
20        os.chdir(self.srcdir)
21        utils.make('clean')
22        utils.make('all')
23
24
25    def run_once(self):
26        """Runs the integration test."""
27        # Create the browser instance.
28        camera_path = os.path.join(os.path.dirname(__file__),
29                                   'src/camera/build/camera')
30        browser = chrome.Chrome(extension_paths=[camera_path])
31
32        # Start the Camera app.
33        extension = browser.get_extension(camera_path)
34        extension.ExecuteJavaScript('camera.bg.createForTesting();')
35
36        # Wait until the Camera app acquires the stream.
37        js_is_capturing = (
38                'camera.bg.appWindow && '
39                'camera.bg.appWindow.contentWindow.camera && '
40                'camera.bg.appWindow.contentWindow.camera.Camera && '
41                'camera.bg.appWindow.contentWindow.camera.Camera.getInstance().'
42                'cameraView.capturing')
43
44        # Verify if the camera initializes correctly in up to 30 seconds.
45        utils.poll_for_condition(
46                condition=lambda: extension.EvaluateJavaScript(js_is_capturing),
47                exception=error.TestError('Camera initialization timed out.'),
48                sleep_interval=1,
49                timeout=30)
50
51