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

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: simpler approach (+ rebase) 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 5fca89f35d07d183b4d0d3a6e054bff61ae928cb..8edabf04f35dd2e39f6b3aa8fd0f81b25ac46175 100644
--- 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):
@@ -438,7 +447,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)
@@ -449,7 +458,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.
@@ -467,6 +477,61 @@ 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
Ivan Korotkov 2012/04/17 09:27:51 Please align pydoc as in the rest of the file, i.e
Tyler Breisacher (Chromium) 2012/04/17 19:54:33 Done.
+ 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.
Ivan Korotkov 2012/04/17 09:27:51 Please add assert that protector isn't showing a b
Tyler Breisacher (Chromium) 2012/04/17 19:54:33 Done.
+ 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/']
« chrome/browser/prefs/session_startup_pref.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