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.
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
12 class desktopui_UrlFetch(cros_ui_test.UITest):
16 def initialize(self, live=True):
18 super(desktopui_UrlFetch, self).initialize(creds='$default')
20 self._test_url = 'http://www.msn.com/'
21 self._expected_title = 'MSN.com'
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()
30 if not self._live and hasattr(self, '_testServer'):
31 self._testServer.stop()
32 super(desktopui_UrlFetch, self).cleanup()
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.
39 super(desktopui_UrlFetch, self).start_authserver()
45 assert not self.pyauto.GetCookie(pyauto.GURL(self._test_url))
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
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.
58 utils.poll_for_condition(
60 error.TestError('Timeout waiting to open %s' % self._test_url),
64 cookie = self.pyauto.GetCookie(pyauto.GURL(self._test_url))
66 raise error.TestError('Expected cookie for %s' % self._test_url)