1 # Copyright 2012 The Chromium 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.
8 from telemetry.core import browser_finder
9 from telemetry.core import util
10 from telemetry.unittest import options_for_unittests
13 class TabTestCase(unittest.TestCase):
14 def __init__(self, *args):
15 self._extra_browser_args = []
16 self.test_file_path = None
18 super(TabTestCase, self).__init__(*args)
23 options = options_for_unittests.GetCopy()
25 self.CustomizeBrowserOptions(options.browser_options)
27 if self._extra_browser_args:
28 options.AppendExtraBrowserArgs(self._extra_browser_args)
30 browser_to_create = browser_finder.FindBrowser(options)
31 if not browser_to_create:
32 raise Exception('No browser found, cannot continue test.')
34 self._browser = browser_to_create.Create()
36 self._tab = self._browser.tabs[0]
37 self._tab.Navigate('about:blank')
38 self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
48 def CustomizeBrowserOptions(self, options):
49 """Override to add test-specific options to the BrowserOptions object"""
52 def Navigate(self, filename, script_to_evaluate_on_commit=None):
53 """Navigates |tab| to |filename| in the unittest data directory.
55 Also sets up http server to point to the unittest data directory.
57 self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
58 self.test_file_path = os.path.join(util.GetUnittestDataDir(), filename)
59 self.test_url = self._browser.http_server.UrlOf(self.test_file_path)
60 self._tab.Navigate(self.test_url, script_to_evaluate_on_commit)
61 self._tab.WaitForDocumentReadyStateToBeComplete()