Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5278)

Unified Diff: chrome/test/functional/protector.py

Issue 10049005: Fix homepage migration for users who never changed their settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Value -> base::Value Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/functional/protector.py
diff --git a/chrome/test/functional/protector.py b/chrome/test/functional/protector.py
index c7f432d03b66f5b3f843a6905683699209a1d0af..9b62d8a5b81a8338d6baf14cf82b3743665bd324 100755
--- a/chrome/test/functional/protector.py
+++ b/chrome/test/functional/protector.py
@@ -151,21 +151,30 @@ class BaseProtectorTest(pyauto.PyUITest):
prefs['backup']['_signature'] = 'INVALID'
self._WritePreferences(prefs)
- def _ChangeSessionStartupPrefs(self, startup_type, startup_urls=None,
- homepage=None):
+ def _ChangeSessionStartupPrefs(self, startup_type=None, startup_urls=None,
+ homepage=None, delete_migrated_pref=False):
"""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.
+ delete_migrated_pref: Whether we should delete the preference which says
+ we've already migrated the startup_type preference.
"""
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:
prefs['homepage'] = homepage
+ if delete_migrated_pref:
+ del prefs['session']['restore_on_startup_migrated']
self._WritePreferences(prefs)
def _ChangePinnedTabsPrefs(self, pinned_tabs):
@@ -452,7 +461,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)
@@ -463,7 +472,8 @@ class ProtectorSessionStartupTest(BaseProtectorTest):
clear_profile=False,
pre_launch_hook=lambda: self._ChangeSessionStartupPrefs(
self._SESSION_STARTUP_HOMEPAGE,
- homepage=new_homepage))
+ homepage=new_homepage,
+ delete_migrated_pref=True))
# The change must be detected by Protector.
self.assertTrue(self.GetProtectorState()['showing_change'])
# Protector must restore old preference values.
@@ -481,6 +491,63 @@ 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, to simulate a
+ # user coming from m18 and having left it on the default value.
+ self.RestartBrowser(
+ clear_profile=False,
+ pre_launch_hook=lambda: self._ChangeSessionStartupPrefs(
+ startup_type=None,
+ delete_migrated_pref=True))
+ # 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))
+ 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.
+ """
+ # Initially, the default value is selected for kRestoreOnStartup.
+ self.assertEqual(self._SESSION_STARTUP_NTP,
+ self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup))
+ # Set the homepage, but leave kRestoreOnStartup unchanged.
+ 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))
+ # No longer showing the change.
+ self.assertFalse(self.GetProtectorState()['showing_change'])
+
def testDetectPinnedTabsChangeAndApply(self):
"""Test for detecting and applying a change to pinned tabs."""
pinned_urls = ['chrome://version/', 'chrome://credits/']
« chrome/browser/prefs/session_startup_pref_unittest.cc ('K') | « chrome/common/pref_names.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698