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. 4 5from telemetry.core import exceptions 6from telemetry.testing import browser_test_case 7 8 9class TabTestCase(browser_test_case.BrowserTestCase): 10 def __init__(self, *args): 11 super(TabTestCase, self).__init__(*args) 12 self._tab = None 13 14 def setUp(self): 15 super(TabTestCase, self).setUp() 16 17 if self._browser.supports_tab_control: 18 try: 19 while len(self._browser.tabs) < 1: 20 self._browser.tabs.New() 21 while len(self._browser.tabs) > 1: 22 self._browser.tabs[0].Close() 23 self._tab = self._browser.tabs[0] 24 except exceptions.TimeoutException: 25 self._RestartBrowser() 26 else: 27 self._RestartBrowser() 28 self._tab.Navigate('about:blank') 29 self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() 30 31 def Navigate(self, filename, script_to_evaluate_on_commit=None): 32 """Navigates |tab| to |filename| in the unittest data directory. 33 34 Also sets up http server to point to the unittest data directory. 35 """ 36 url = self.UrlOfUnittestFile(filename) 37 self._tab.Navigate(url, script_to_evaluate_on_commit) 38 self._tab.WaitForDocumentReadyStateToBeComplete() 39 40 def _RestartBrowser(self): 41 if not self._browser.tabs: 42 self.tearDownClass() 43 self.setUpClass() 44 self._tab = self._browser.tabs[0] 45 46 @property 47 def tabs(self): 48 return self._browser.tabs 49