Index: chrome/test/functional/protector.py |
diff --git a/chrome/test/functional/protector.py b/chrome/test/functional/protector.py |
index 5fca89f35d07d183b4d0d3a6e054bff61ae928cb..7e726a4781175c717e74be39f44aba482fcab953 100644 |
--- a/chrome/test/functional/protector.py |
+++ b/chrome/test/functional/protector.py |
@@ -151,17 +151,22 @@ class BaseProtectorTest(pyauto.PyUITest): |
prefs['backup']['_signature'] = 'INVALID' |
self._WritePreferences(prefs) |
- def _ChangeSessionStartupPrefs(self, startup_type, startup_urls=None, |
+ def _ChangeSessionStartupPrefs(self, startup_type=None, startup_urls=None, |
homepage=None): |
"""Changes the session startup type and the list of URLs to load on startup. |
Args: |
- startup_type: int with one of _SESSION_STARTUP_* values. |
+ startup_type: int with one of _SESSION_STARTUP_* values. If startup_type |
+ is None, then it deletes the preference. |
startup_urls: list(str) with a list of URLs; if None, is left unchanged. |
homepage: unless None, the new value for homepage. |
""" |
prefs = self._LoadPreferences() |
- prefs['session']['restore_on_startup'] = startup_type |
+ if startup_type is None: |
+ del prefs['session']['restore_on_startup'] |
+ else: |
+ prefs['session']['restore_on_startup'] = startup_type |
+ |
if startup_urls is not None: |
prefs['session']['urls_to_restore_on_startup'] = startup_urls |
if homepage is not None: |
@@ -438,7 +443,7 @@ class ProtectorSessionStartupTest(BaseProtectorTest): |
# No longer showing the change. |
self.assertFalse(self.GetProtectorState()['showing_change']) |
- def testSessionStartupPrefMigration(self): |
+ def testSessionStartupPrefMigrationFromHomepage(self): |
"""Test migration from old session.restore_on_startup values (homepage).""" |
# Set startup prefs to restoring last open tabs. |
self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_LAST) |
@@ -467,6 +472,57 @@ class ProtectorSessionStartupTest(BaseProtectorTest): |
# No longer showing the change. |
self.assertFalse(self.GetProtectorState()['showing_change']) |
+ def testSessionStartupPrefMigrationFromBlank(self): |
+ """Test migration from session.restore_on_startup being blank, as it would |
+ be for a user who had m18 or lower, and never changed that preference. |
+ """ |
+ # Set startup prefs to restoring last open tabs. |
+ self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_LAST) |
+ self.SetPrefs(pyauto.kURLsToRestoreOnStartup, []) |
+ # Set the homepage. |
+ new_homepage = 'http://www.google.com/' |
+ self.SetPrefs(pyauto.kHomePageIsNewTabPage, False) |
+ self.SetPrefs(pyauto.kHomePage, new_homepage) |
+ # Restart browser, clearing the 'restore on startup' pref. |
+ self.RestartBrowser( |
+ clear_profile=False, |
+ pre_launch_hook=lambda: self._ChangeSessionStartupPrefs( |
+ startup_type=None)) |
+ # The change must be detected by Protector. |
+ self.assertTrue(self.GetProtectorState()['showing_change']) |
+ # Protector must restore old preference values. |
+ self.assertEqual(self._SESSION_STARTUP_LAST, |
+ self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup)) |
+ self.assertEqual([], |
+ self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup)) |
Nirnimesh
2012/04/14 08:09:55
use assertFalse instead
|
+ self.ApplyProtectorChange() |
+ # Now the new preference values are active. |
+ self.assertEqual(self._SESSION_STARTUP_URLS, |
+ self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup)) |
+ # Homepage migrated to the list of startup URLs. |
+ self.assertEqual([new_homepage], |
+ self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup)) |
+ # No longer showing the change. |
+ self.assertFalse(self.GetProtectorState()['showing_change']) |
+ |
+ def testSessionStartupPrefNoMigrationOnHomepageChange(self): |
+ """Test that when the user modifies their homepage in m19+, we don't do the |
+ preference migration. |
+ """ |
+ # Leave the kRestoreOnStartup preference unset so that the default value |
+ # applies (for m18, that's "open the homepage"), and set the homepage. |
+ new_homepage = 'http://www.google.com/' |
+ self.SetPrefs(pyauto.kHomePageIsNewTabPage, False) |
+ self.SetPrefs(pyauto.kHomePage, new_homepage) |
+ # Restart browser. |
+ self.RestartBrowser(clear_profile=False) |
+ # Now the new preference values are active. |
+ self.assertEqual(self._SESSION_STARTUP_NTP, |
+ self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup)) |
+ # kURLsToRestoreOnStartup pref is unchanged. |
+ self.assertEqual([], |
+ self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup)) |
+ |
def testDetectPinnedTabsChangeAndApply(self): |
"""Test for detecting and applying a change to pinned tabs.""" |
pinned_urls = ['chrome://version/', 'chrome://credits/'] |