| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import shutil | 8 import shutil |
| 9 import sys | 9 import sys |
| 10 | 10 |
| 11 import pyauto_functional # Must be imported before pyauto | 11 import pyauto_functional # Must be imported before pyauto |
| 12 import pyauto | 12 import pyauto |
| 13 import test_utils |
| 13 | 14 |
| 14 | 15 |
| 15 class PrefsTest(pyauto.PyUITest): | 16 class PrefsTest(pyauto.PyUITest): |
| 16 """TestCase for Preferences.""" | 17 """TestCase for Preferences.""" |
| 17 | 18 |
| 18 def Debug(self): | 19 def Debug(self): |
| 19 """Test method for experimentation. | 20 """Test method for experimentation. |
| 20 | 21 |
| 21 This method will not run automatically. | 22 This method will not run automatically. |
| 22 """ | 23 """ |
| 23 while True: | 24 while True: |
| 24 raw_input('Interact with the browser and hit <enter> to dump prefs... ') | 25 raw_input('Interact with the browser and hit <enter> to dump prefs... ') |
| 25 self.pprint(self.GetPrefsInfo().Prefs()) | 26 self.pprint(self.GetPrefsInfo().Prefs()) |
| 26 | 27 |
| 27 def testSessionRestore(self): | 28 def testSessionRestore(self): |
| 28 """Test session restore preference.""" | 29 """Test session restore preference.""" |
| 30 |
| 31 pref_url = 'chrome://settings/browser' |
| 29 url1 = 'http://www.google.com/' | 32 url1 = 'http://www.google.com/' |
| 30 url2 = 'http://news.google.com/' | 33 url2 = 'http://news.google.com/' |
| 34 |
| 35 self.NavigateToURL(pref_url) |
| 36 # Set pref to restore session on startup. |
| 37 driver = self.NewWebDriver() |
| 38 restore_elem = driver.find_element_by_xpath( |
| 39 '//input[@metric="Options_Startup_LastSession"]') |
| 40 restore_elem.click() |
| 41 self.assertTrue(restore_elem.is_selected()) |
| 42 self.RestartBrowser(clear_profile=False) |
| 31 self.NavigateToURL(url1) | 43 self.NavigateToURL(url1) |
| 32 self.AppendTab(pyauto.GURL(url2)) | 44 self.AppendTab(pyauto.GURL(url2)) |
| 33 num_tabs = self.GetTabCount() | 45 num_tabs = self.GetTabCount() |
| 34 # Set pref to restore session on startup | |
| 35 self.SetPrefs(pyauto.kRestoreOnStartup, 1) | |
| 36 logging.debug('Setting %s to 1' % pyauto.kRestoreOnStartup) | |
| 37 self.RestartBrowser(clear_profile=False) | 46 self.RestartBrowser(clear_profile=False) |
| 38 # Verify | 47 # Verify tabs are properly restored. |
| 39 self.assertEqual(self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup), 1) | 48 self.assertEqual(self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup), 1) |
| 40 self.assertEqual(num_tabs, self.GetTabCount()) | 49 self.assertEqual(num_tabs, self.GetTabCount()) |
| 41 self.ActivateTab(0) | 50 self.ActivateTab(0) |
| 42 self.assertEqual(url1, self.GetActiveTabURL().spec()) | 51 self.assertEqual(url1, self.GetActiveTabURL().spec()) |
| 43 self.ActivateTab(1) | 52 self.ActivateTab(1) |
| 44 self.assertEqual(url2, self.GetActiveTabURL().spec()) | 53 self.assertEqual(url2, self.GetActiveTabURL().spec()) |
| 54 # Verify session restore option is still selected. |
| 55 self.NavigateToURL(pref_url, 0, 0) |
| 56 driver = self.NewWebDriver() |
| 57 self.assertTrue(driver.find_element_by_xpath( |
| 58 '//input[@metric="Options_Startup_LastSession"]').is_selected()) |
| 45 | 59 |
| 46 def testNavigationStateOnSessionRestore(self): | 60 def testNavigationStateOnSessionRestore(self): |
| 47 """Verify navigation state is preserved on session restore.""" | 61 """Verify navigation state is preserved on session restore.""" |
| 48 urls = ('http://www.google.com/', | 62 urls = ('http://www.google.com/', |
| 49 'http://news.google.com/', | 63 'http://news.google.com/', |
| 50 'http://dev.chromium.org/',) | 64 'http://dev.chromium.org/',) |
| 51 for url in urls: | 65 for url in urls: |
| 52 self.NavigateToURL(url) | 66 self.NavigateToURL(url) |
| 53 tab = self.GetBrowserWindow(0).GetTab(0) | 67 tab = self.GetBrowserWindow(0).GetTab(0) |
| 54 tab.GoBack() | 68 tab.GoBack() |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 self.assertEqual(title, self.GetActiveTabTitle()) | 203 self.assertEqual(title, self.GetActiveTabTitle()) |
| 190 | 204 |
| 191 def testHaveLocalStatePrefs(self): | 205 def testHaveLocalStatePrefs(self): |
| 192 """Verify that we have some Local State prefs.""" | 206 """Verify that we have some Local State prefs.""" |
| 193 self.assertTrue(self.GetLocalStatePrefsInfo()) | 207 self.assertTrue(self.GetLocalStatePrefsInfo()) |
| 194 | 208 |
| 195 | 209 |
| 196 if __name__ == '__main__': | 210 if __name__ == '__main__': |
| 197 pyauto_functional.Main() | 211 pyauto_functional.Main() |
| 198 | 212 |
| OLD | NEW |