OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 import httplib | 4 import httplib |
5 import json | 5 import json |
6 import socket | 6 import socket |
7 import urllib2 | 7 import urllib2 |
8 import weakref | 8 import weakref |
9 | 9 |
10 from telemetry import browser_gone_exception | 10 from telemetry import browser_gone_exception |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 tab_id = debugger_url.split('/')[-1] | 55 tab_id = debugger_url.split('/')[-1] |
56 try: | 56 try: |
57 response = self._browser_backend.Request('close/%s' % tab_id, | 57 response = self._browser_backend.Request('close/%s' % tab_id, |
58 timeout=timeout) | 58 timeout=timeout) |
59 except urllib2.HTTPError: | 59 except urllib2.HTTPError: |
60 raise Exception('Unable to close tab, tab id not found: %s' % tab_id) | 60 raise Exception('Unable to close tab, tab id not found: %s' % tab_id) |
61 assert response == 'Target is closing' | 61 assert response == 'Target is closing' |
62 | 62 |
63 util.WaitFor(lambda: not self._FindTabInfo(debugger_url), timeout=5) | 63 util.WaitFor(lambda: not self._FindTabInfo(debugger_url), timeout=5) |
| 64 |
| 65 if debugger_url in self._tab_dict: |
| 66 del self._tab_dict[debugger_url] |
64 self._UpdateTabList() | 67 self._UpdateTabList() |
65 | 68 |
66 def ActivateTab(self, debugger_url, timeout=None): | 69 def ActivateTab(self, debugger_url, timeout=None): |
67 assert self._browser_backend.supports_tab_control | 70 assert self._browser_backend.supports_tab_control |
68 | 71 |
69 assert debugger_url in self._tab_dict | 72 assert debugger_url in self._tab_dict |
70 tab_id = debugger_url.split('/')[-1] | 73 tab_id = debugger_url.split('/')[-1] |
71 try: | 74 try: |
72 response = self._browser_backend.Request('activate/%s' % tab_id, | 75 response = self._browser_backend.Request('activate/%s' % tab_id, |
73 timeout=timeout) | 76 timeout=timeout) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 except (socket.error, httplib.BadStatusLine, urllib2.URLError): | 129 except (socket.error, httplib.BadStatusLine, urllib2.URLError): |
127 if not self._browser_backend.IsBrowserRunning(): | 130 if not self._browser_backend.IsBrowserRunning(): |
128 raise browser_gone_exception.BrowserGoneException() | 131 raise browser_gone_exception.BrowserGoneException() |
129 raise BrowserConnectionGoneException() | 132 raise BrowserConnectionGoneException() |
130 | 133 |
131 def _UpdateTabList(self): | 134 def _UpdateTabList(self): |
132 def GetDebuggerUrl(tab_info): | 135 def GetDebuggerUrl(tab_info): |
133 if 'webSocketDebuggerUrl' not in tab_info: | 136 if 'webSocketDebuggerUrl' not in tab_info: |
134 return None | 137 return None |
135 return tab_info['webSocketDebuggerUrl'] | 138 return tab_info['webSocketDebuggerUrl'] |
136 newtab_list = map(GetDebuggerUrl, self._ListTabs()) | 139 new_tab_list = map(GetDebuggerUrl, self._ListTabs()) |
137 self._tab_list = [t for t in self._tab_list if t in newtab_list] | 140 self._tab_list = [t for t in self._tab_list |
138 self._tab_list += [t for t in newtab_list if t not in self._tab_list] | 141 if t in self._tab_dict or t in new_tab_list] |
| 142 self._tab_list += [t for t in new_tab_list |
| 143 if t is not None and t not in self._tab_list] |
139 | 144 |
140 def _FindTabInfo(self, debugger_url): | 145 def _FindTabInfo(self, debugger_url): |
141 for tab_info in self._ListTabs(): | 146 for tab_info in self._ListTabs(): |
142 if tab_info.get('webSocketDebuggerUrl') == debugger_url: | 147 if tab_info.get('webSocketDebuggerUrl') == debugger_url: |
143 return tab_info | 148 return tab_info |
144 return None | 149 return None |
OLD | NEW |