Index: chrome/test/functional/tracing/tab_tracker.py |
diff --git a/chrome/test/functional/tracing/tab_tracker.py b/chrome/test/functional/tracing/tab_tracker.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..db4da4a5fd33005504129ff7897a90768a836a1c |
--- /dev/null |
+++ b/chrome/test/functional/tracing/tab_tracker.py |
@@ -0,0 +1,41 @@ |
+# Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import uuid |
+ |
+# The TabTracker class allows the creation of tabs whose indices can be |
Nirnimesh
2012/07/30 18:57:19
This sounds like a docstring. Move inside the clas
|
+# determined even after lower indexed tabs have been closed, therefore changing |
+# that tab's index. |
+class TabTracker: |
+ def __init__(self, browser, visible = False): |
Nirnimesh
2012/07/30 18:57:19
remove parents around =
Nirnimesh
2012/07/30 18:58:03
err.. parents -> space
|
+ # A binary search tree would be faster, but this is easier to write. |
+ # If this needs to become faster, understand that the important operations |
+ # here are append, arbitrary deletion and searching. |
+ self._uuids = [None] |
+ self._window_idx = browser.GetBrowserWindowCount() |
+ self._browser = browser |
+ browser.OpenNewBrowserWindow(visible) |
+ # We leave the 0'th tab empty to have something to close on __del__ |
+ |
+ def __del__(self): |
+ self._browser.CloseBrowserWindow(self._window_idx) |
+ |
+ def createTab(self, url="about:blank"): |
Nirnimesh
2012/07/30 18:57:19
createTab -> CreateTab
Please repeat for all meth
Nirnimesh
2012/07/30 18:57:19
use single quote char ' instead of " for consisten
Nirnimesh
2012/07/30 18:57:19
Add docstring, with an Args: section.
|
+ self._browser.AppendTab(url, self._window_idx) |
+ # We use uuids here rather than a monotonic integer to prevent confusion |
+ # with the tab index. |
+ tab_uuid = uuid.uuid4() |
+ self._uuids.append(tab_uuid) |
+ return tab_uuid |
+ |
+ def releaseTab(self, tab_uuid): |
+ idx = self.getTabIndex(tab_uuid) |
+ self._browser.GetBrowserWindow(self._window_idx).GetTab(idx).Close() |
+ del self._uuids[idx] |
+ |
+ def getTabIndex(self, tab_uuid): |
+ return self._uuids.index(tab_uuid) |
+ |
+ def getWindowIndex(self): |
+ return self._window_idx |