Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2013 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 | |
| 5 from telemetry.core.webdriver import webdriver_tab_backend | |
| 6 | |
| 7 class WebDriverTabListBackend(object): | |
| 8 def __init__(self, browser_backend): | |
| 9 self._browser_backend = browser_backend | |
| 10 # Stores the window handles. | |
| 11 self._tab_list = [] | |
| 12 | |
| 13 def Init(self): | |
| 14 self._UpdateTabList() | |
| 15 | |
| 16 def New(self, timeout=None): | |
| 17 raise NotImplementedError() | |
|
chrisgao (Use stgao instead)
2013/07/31 19:05:41
Add a comment with a reason of not-impl.
chrisgao (Use stgao instead)
2013/08/01 00:36:44
Done.
| |
| 18 | |
| 19 def __iter__(self): | |
| 20 self._UpdateTabList() | |
| 21 return self._tab_list.__iter__() | |
| 22 | |
| 23 def __len__(self): | |
| 24 self._UpdateTabList() | |
| 25 return len(self._tab_list) | |
| 26 | |
| 27 def __getitem__(self, index): | |
| 28 self._UpdateTabList() | |
| 29 if len(self._tab_list) <= index: | |
| 30 raise IndexError('list index out of range') | |
| 31 return self._tab_list[index] | |
| 32 | |
| 33 def _UpdateTabList(self): | |
| 34 window_handles = self._browser_backend.driver.window_handles | |
| 35 old_tab_list = self._tab_list | |
| 36 self._tab_list = [] | |
| 37 for window_handle in window_handles: | |
| 38 tab = None | |
| 39 for old_tab in old_tab_list: | |
| 40 if old_tab.window_handle == window_handle: | |
| 41 tab = old_tab | |
| 42 break | |
| 43 else: | |
| 44 tab = webdriver_tab_backend.WebDriverTabBackend( | |
| 45 self._browser_backend, window_handle) | |
| 46 self._tab_list.append(tab) | |
| OLD | NEW |