• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Lint as: python2, python3
2# Copyright 2016 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import logging
7import time
8
9from autotest_lib.client.bin import test
10from autotest_lib.client.bin import utils
11from autotest_lib.client.common_lib import error
12from autotest_lib.client.common_lib.cros import chrome
13from autotest_lib.client.cros.input_playback import input_playback
14
15
16class logging_FeedbackReport(test.test):
17    """Tests if feedback report can be opened with no crashes in browser."""
18    version = 1
19    _FEEDBACK_STATE_TIMEOUT = 40
20    _WAIT = 2
21    _FEEDBACK_SENT_URL = 'support.google.com/chromebook/answer/3142217'
22
23    def warmup(self):
24        """Test setup."""
25        # Emulate keyboard to open feedback app.
26        # See input_playback. The keyboard is used to play back shortcuts.
27        self._player = input_playback.InputPlayback()
28        self._player.emulate(input_type='keyboard')
29        self._player.find_connected_inputs()
30
31    def _open_feedback(self):
32        """Use keyboard shortcut to emulate input to open feedback app."""
33        self._player.blocking_playback_of_default_file(
34            input_type='keyboard', filename='keyboard_alt+shift+i')
35
36    def _enter_feedback_text(self):
37        """Enter Feedback message in the Text field"""
38        time.sleep(self._WAIT)
39        self._player.blocking_playback_of_default_file(
40               input_type='keyboard', filename='keyboard_T+e+s+t')
41
42    def _press_enter(self):
43        """Use keyboard shortcut to press Enter."""
44        self._player.blocking_playback_of_default_file(
45            input_type='keyboard', filename='keyboard_enter')
46
47    def _press_shift_tab(self):
48        """Use keyboard shortcut to press Shift-Tab."""
49        self._player.blocking_playback_of_default_file(
50            input_type='keyboard', filename='keyboard_shift+tab')
51
52    def _submit_feedback(self):
53        """Click on Send button to submit Feedback Report using keyboard input"""
54        time.sleep(self._WAIT)
55        self._enter_feedback_text()
56        self._press_shift_tab()
57        self._press_enter()
58
59    def _is_feedback_sent(self, start_time, timeout):
60        """Checks feedback is sent within timeout
61
62        @param start_time: beginning timestamp
63        @param timeout: duration of URL checks
64
65        @returns: True if feedback sent page is present
66        """
67        while True:
68            time.sleep(self._WAIT)
69            for tab in self.cr.browser.tabs:
70                if self._FEEDBACK_SENT_URL in tab.url:
71                    return True
72            if time.time() - start_time >= timeout:
73                break;
74        return False
75
76    def run_once(self):
77        """Run the test."""
78        with chrome.Chrome(disable_default_apps=False) as self.cr:
79            # Open and confirm feedback app is working.
80            time.sleep(self._WAIT)
81            self._open_feedback()
82            self._submit_feedback()
83
84            start_time = time.time()
85            if not self._is_feedback_sent(start_time, self._WAIT * 30):
86                raise error.TestFail("Feedback NOT sent!")
87
88    def cleanup(self):
89        """Test cleanup."""
90