firmware_TouchMTB: print metrics with missing values
[chromiumos/third_party/autotest.git] / client / site_tests / desktopui_UrlFetch / desktopui_UrlFetch.py
1 # Copyright (c) 2011 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
5 import logging
6
7 from autotest_lib.client.bin import utils
8 from autotest_lib.client.common_lib import error
9 from autotest_lib.client.cros import cros_ui_test, httpd
10
11
12 class desktopui_UrlFetch(cros_ui_test.UITest):
13     version = 1
14
15
16     def initialize(self, live=True):
17         self._live = live
18         super(desktopui_UrlFetch, self).initialize(creds='$default')
19         if self._live:
20             self._test_url = 'http://www.msn.com/'
21             self._expected_title = 'MSN.com'
22         else:
23             self._test_url = 'http://localhost:8000/hello.html'
24             self._expected_title = 'Hello World'
25             self._testServer = httpd.HTTPListener(8000, docroot=self.bindir)
26             self._testServer.run()
27
28
29     def cleanup(self):
30         if not self._live and hasattr(self, '_testServer'):
31             self._testServer.stop()
32         super(desktopui_UrlFetch, self).cleanup()
33
34
35     def start_authserver(self):
36         # Do nothing in live mode so that we do real login.
37         # In non-live mode, setup local authserver which handles login.
38         if not self._live:
39             super(desktopui_UrlFetch, self).start_authserver()
40
41
42     def run_once(self):
43         import pyauto
44
45         assert not self.pyauto.GetCookie(pyauto.GURL(self._test_url))
46
47         def _OpenUrl():
48             self.pyauto.NavigateToURL(self._test_url)
49             tab_title = self.pyauto.GetActiveTabTitle()
50             logging.info('Expected tab title: %s. Got: %s' % (
51                 self._expected_title, tab_title))
52             return tab_title == self._expected_title
53
54         # TODO(nirnimesh): This polling is a stop-gap fix and should not be
55         # necessary.  Looks like the http server takes a while to startup.
56         # Remove after http can guarantee its startup.
57         # crosbug.com/20034
58         utils.poll_for_condition(
59             _OpenUrl,
60             error.TestError('Timeout waiting to open %s' % self._test_url),
61             timeout=60,
62             sleep_interval=1)
63
64         cookie = self.pyauto.GetCookie(pyauto.GURL(self._test_url))
65         if not cookie:
66             raise error.TestError('Expected cookie for %s' % self._test_url)