OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import copy | 6 import copy |
7 import os | 7 import os |
8 | 8 |
9 import pyauto_functional # Must be imported before pyauto | 9 import pyauto_functional # Must be imported before pyauto |
10 import pyauto | 10 import pyauto |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 self.assertEqual(self.PAGES[0]['title'], | 172 self.assertEqual(self.PAGES[0]['title'], |
173 self.GetNTPThumbnails()[0]['title']) | 173 self.GetNTPThumbnails()[0]['title']) |
174 self.ExecuteJavascript('window.domAutomationController.send(' + | 174 self.ExecuteJavascript('window.domAutomationController.send(' + |
175 'document.title = "new title")') | 175 'document.title = "new title")') |
176 self.assertEqual('new title', self.GetNTPThumbnails()[0]['title']) | 176 self.assertEqual('new title', self.GetNTPThumbnails()[0]['title']) |
177 | 177 |
178 def testCloseOneTab(self): | 178 def testCloseOneTab(self): |
179 """Tests that closing a tab populates the recently closed list""" | 179 """Tests that closing a tab populates the recently closed list""" |
180 self.RemoveNTPDefaultThumbnails() | 180 self.RemoveNTPDefaultThumbnails() |
181 self.AppendTab(pyauto.GURL(self.PAGES[1]['url'])) | 181 self.AppendTab(pyauto.GURL(self.PAGES[1]['url'])) |
182 self.GetBrowserWindow(0).GetTab(1).Close(True) | 182 self.CloseTab(tab_index=1) |
183 self.assertEqual(self.PAGES[1]['url'], | 183 self.assertEqual(self.PAGES[1]['url'], |
184 self.GetNTPRecentlyClosed()[0]['url']) | 184 self.GetNTPRecentlyClosed()[0]['url']) |
185 self.assertEqual(self.PAGES[1]['title'], | 185 self.assertEqual(self.PAGES[1]['title'], |
186 self.GetNTPRecentlyClosed()[0]['title']) | 186 self.GetNTPRecentlyClosed()[0]['title']) |
187 | 187 |
188 def testCloseOneWindow(self): | 188 def testCloseOneWindow(self): |
189 """Tests that closing a window populates the recently closed list""" | 189 """Tests that closing a window populates the recently closed list""" |
190 self.RemoveNTPDefaultThumbnails() | 190 self.RemoveNTPDefaultThumbnails() |
191 self.OpenNewBrowserWindow(True) | 191 self.OpenNewBrowserWindow(True) |
192 self.NavigateToURL(self.PAGES[0]['url'], 1, 0) | 192 self.NavigateToURL(self.PAGES[0]['url'], 1, 0) |
193 self.AppendTab(pyauto.GURL(self.PAGES[1]['url']), 1) | 193 self.AppendTab(pyauto.GURL(self.PAGES[1]['url']), 1) |
194 self.CloseBrowserWindow(1) | 194 self.CloseBrowserWindow(1) |
195 expected = [{ u'type': u'window', | 195 expected = [{ u'type': u'window', |
196 u'tabs': [ | 196 u'tabs': [ |
197 { u'type': u'tab', | 197 { u'type': u'tab', |
198 u'url': self.PAGES[0]['url'], | 198 u'url': self.PAGES[0]['url'], |
199 u'direction': u'ltr' }, | 199 u'direction': u'ltr' }, |
200 { u'type': u'tab', | 200 { u'type': u'tab', |
201 u'url': self.PAGES[1]['url']}] | 201 u'url': self.PAGES[1]['url']}] |
202 }] | 202 }] |
203 self.assertEquals(expected, test_utils.StripUnmatchedKeys( | 203 self.assertEquals(expected, test_utils.StripUnmatchedKeys( |
204 self.GetNTPRecentlyClosed(), expected)) | 204 self.GetNTPRecentlyClosed(), expected)) |
205 | 205 |
206 def testCloseMultipleTabs(self): | 206 def testCloseMultipleTabs(self): |
207 """Tests closing multiple tabs populates the Recently Closed section in | 207 """Tests closing multiple tabs populates the Recently Closed section in |
208 order""" | 208 order""" |
209 self.RemoveNTPDefaultThumbnails() | 209 self.RemoveNTPDefaultThumbnails() |
210 self.AppendTab(pyauto.GURL(self.PAGES[0]['url'])) | 210 self.AppendTab(pyauto.GURL(self.PAGES[0]['url'])) |
211 self.AppendTab(pyauto.GURL(self.PAGES[1]['url'])) | 211 self.AppendTab(pyauto.GURL(self.PAGES[1]['url'])) |
212 self.GetBrowserWindow(0).GetTab(2).Close(True) | 212 self.CloseTab(tab_index=2) |
213 self.GetBrowserWindow(0).GetTab(1).Close(True) | 213 self.CloseTab(tab_index=1) |
214 expected = [{ u'type': u'tab', | 214 expected = [{ u'type': u'tab', |
215 u'url': self.PAGES[0]['url'] | 215 u'url': self.PAGES[0]['url'] |
216 }, | 216 }, |
217 { u'type': u'tab', | 217 { u'type': u'tab', |
218 u'url': self.PAGES[1]['url'] | 218 u'url': self.PAGES[1]['url'] |
219 }] | 219 }] |
220 self.assertEquals(expected, test_utils.StripUnmatchedKeys( | 220 self.assertEquals(expected, test_utils.StripUnmatchedKeys( |
221 self.GetNTPRecentlyClosed(), expected)) | 221 self.GetNTPRecentlyClosed(), expected)) |
222 | 222 |
223 def testCloseWindowWithOneTab(self): | 223 def testCloseWindowWithOneTab(self): |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 self.assertEquals(expected, test_utils.StripUnmatchedKeys( | 263 self.assertEquals(expected, test_utils.StripUnmatchedKeys( |
264 self.GetNTPRecentlyClosed(), expected)) | 264 self.GetNTPRecentlyClosed(), expected)) |
265 | 265 |
266 def testRecentlyClosedIncognito(self): | 266 def testRecentlyClosedIncognito(self): |
267 """Tests that we don't record closure of Incognito tabs or windows""" | 267 """Tests that we don't record closure of Incognito tabs or windows""" |
268 #self.RemoveNTPDefaultThumbnails() | 268 #self.RemoveNTPDefaultThumbnails() |
269 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | 269 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
270 self.NavigateToURL(self.PAGES[0]['url'], 1, 0) | 270 self.NavigateToURL(self.PAGES[0]['url'], 1, 0) |
271 self.AppendTab(pyauto.GURL(self.PAGES[0]['url']), 1) | 271 self.AppendTab(pyauto.GURL(self.PAGES[0]['url']), 1) |
272 self.AppendTab(pyauto.GURL(self.PAGES[1]['url']), 1) | 272 self.AppendTab(pyauto.GURL(self.PAGES[1]['url']), 1) |
273 self.GetBrowserWindow(1).GetTab(0).Close(True) | 273 self.CloseTab(windex=1) |
274 self.assertFalse(self.GetNTPRecentlyClosed()) | 274 self.assertFalse(self.GetNTPRecentlyClosed()) |
275 self.CloseBrowserWindow(1) | 275 self.CloseBrowserWindow(1) |
276 self.assertFalse(self.GetNTPRecentlyClosed()) | 276 self.assertFalse(self.GetNTPRecentlyClosed()) |
277 | 277 |
278 def _VerifyAppInfo(self, actual_info, expected_info): | 278 def _VerifyAppInfo(self, actual_info, expected_info): |
279 """Ensures that the actual app info contains the expected app info. | 279 """Ensures that the actual app info contains the expected app info. |
280 | 280 |
281 This method assumes that both the actual and expected information for each | 281 This method assumes that both the actual and expected information for each |
282 app contains at least the 'title' attribute. Both sets of info are | 282 app contains at least the 'title' attribute. Both sets of info are |
283 considered to match if the actual info contains at least the specified | 283 considered to match if the actual info contains at least the specified |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 info = self.GetBrowserInfo() | 464 info = self.GetBrowserInfo() |
465 self.assertTrue(len(info['windows']) == 2, | 465 self.assertTrue(len(info['windows']) == 2, |
466 msg='A second window does not exist.') | 466 msg='A second window does not exist.') |
467 actual_tab_url = info['windows'][1]['tabs'][0]['url'] | 467 actual_tab_url = info['windows'][1]['tabs'][0]['url'] |
468 expected_app_url_start = 'chrome-extension://' + installed_app_id | 468 expected_app_url_start = 'chrome-extension://' + installed_app_id |
469 self.assertTrue(actual_tab_url.startswith(expected_app_url_start), | 469 self.assertTrue(actual_tab_url.startswith(expected_app_url_start), |
470 msg='The app was not launched in the new window.') | 470 msg='The app was not launched in the new window.') |
471 | 471 |
472 if __name__ == '__main__': | 472 if __name__ == '__main__': |
473 pyauto_functional.Main() | 473 pyauto_functional.Main() |
OLD | NEW |