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 | 4 |
5 """Worker thread base class. | 5 """Worker thread base class. |
6 | 6 |
7 Worker threads are used to run multiple PyUITests simultaneously. They | 7 Worker threads are used to run multiple PyUITests simultaneously. They |
8 synchronize calls to the browser.""" | 8 synchronize calls to the browser.""" |
9 | 9 |
10 import itertools | 10 import itertools |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 while True: | 98 while True: |
99 task = self.__tasks.get() | 99 task = self.__tasks.get() |
100 # Check for magic exit values. | 100 # Check for magic exit values. |
101 if task is None: | 101 if task is None: |
102 break | 102 break |
103 # Make the test URL unique so we can figure out our tab index later. | 103 # Make the test URL unique so we can figure out our tab index later. |
104 unique_url = '%s?%d' % (self.__url, WorkerThread._task_id.next()) | 104 unique_url = '%s?%d' % (self.__url, WorkerThread._task_id.next()) |
105 self.AppendTab(unique_url) | 105 self.AppendTab(unique_url) |
106 if not self.RunTask(unique_url, task): | 106 if not self.RunTask(unique_url, task): |
107 self.failures += 1 | 107 self.failures += 1 |
108 self.CloseTab(unique_url) | 108 self.CloseTabByURL(unique_url) |
109 self.__tasks.task_done() | 109 self.__tasks.task_done() |
110 | 110 |
111 def __FindTabLocked(self, url): | 111 def __FindTabLocked(self, url): |
112 """Returns the tab index for the tab belonging to this url. | 112 """Returns the tab index for the tab belonging to this url. |
113 | 113 |
114 __lock must be owned by caller. | 114 __lock must be owned by caller. |
115 """ | 115 """ |
116 if url is None: | 116 if url is None: |
117 return 0 | 117 return 0 |
118 for tab in self.__pyauto.GetBrowserInfo()['windows'][0]['tabs']: | 118 for tab in self.__pyauto.GetBrowserInfo()['windows'][0]['tabs']: |
(...skipping 12 matching lines...) Expand all Loading... |
131 @synchronized | 131 @synchronized |
132 def AppendTab(self, url): | 132 def AppendTab(self, url): |
133 self.__pyauto.AppendTab(pyauto.GURL(url)) | 133 self.__pyauto.AppendTab(pyauto.GURL(url)) |
134 | 134 |
135 @synchronized | 135 @synchronized |
136 def CallJavascriptFunc(self, fun_name, fun_args=[], url=None): | 136 def CallJavascriptFunc(self, fun_name, fun_args=[], url=None): |
137 return self.__pyauto.CallJavascriptFunc(fun_name, fun_args, | 137 return self.__pyauto.CallJavascriptFunc(fun_name, fun_args, |
138 tab_index=self.__FindTabLocked(url)) | 138 tab_index=self.__FindTabLocked(url)) |
139 | 139 |
140 @synchronized | 140 @synchronized |
141 def CloseTab(self, url): | 141 def CloseTabByURL(self, url): |
142 """Closes the tab with the given url.""" | 142 """Closes the tab with the given url.""" |
143 return self.__pyauto.GetBrowserWindow(0).GetTab( | 143 self.CloseTab(tab_index=self.__FindTabLocked(url)) |
144 self.__FindTabLocked(url)).Close(True) | |
145 | 144 |
146 @synchronized | 145 @synchronized |
147 def GetDOMValue(self, name, url=None): | 146 def GetDOMValue(self, name, url=None): |
148 return self.__pyauto.GetDOMValue(name, tab_index=self.__FindTabLocked(url)) | 147 return self.__pyauto.GetDOMValue(name, tab_index=self.__FindTabLocked(url)) |
149 | 148 |
150 def WaitUntil(self, *args, **kwargs): | 149 def WaitUntil(self, *args, **kwargs): |
151 """We do not need to lock WaitUntil since it does not call into Chrome. | 150 """We do not need to lock WaitUntil since it does not call into Chrome. |
152 | 151 |
153 Ensure that the function passed in the args is thread safe. | 152 Ensure that the function passed in the args is thread safe. |
154 """ | 153 """ |
155 return self.__pyauto.WaitUntil(*args, **kwargs) | 154 return self.__pyauto.WaitUntil(*args, **kwargs) |
OLD | NEW |