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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 pyauto_functional # Must be imported first 6 import pyauto_functional # Must be imported first
7 import pyauto 7 import pyauto
8 import test_utils 8 import test_utils
9 9
10 import json 10 import json
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 """ 144 """
145 with open(os.path.join(self._profile_path, 'Preferences'), 'w') as f: 145 with open(os.path.join(self._profile_path, 'Preferences'), 'w') as f:
146 json.dump(prefs, f) 146 json.dump(prefs, f)
147 147
148 def _InvalidatePreferencesBackup(self): 148 def _InvalidatePreferencesBackup(self):
149 """Makes the Preferences backup invalid by clearing the signature.""" 149 """Makes the Preferences backup invalid by clearing the signature."""
150 prefs = self._LoadPreferences() 150 prefs = self._LoadPreferences()
151 prefs['backup']['_signature'] = 'INVALID' 151 prefs['backup']['_signature'] = 'INVALID'
152 self._WritePreferences(prefs) 152 self._WritePreferences(prefs)
153 153
154 def _ChangeSessionStartupPrefs(self, startup_type, startup_urls=None, 154 def _ChangeSessionStartupPrefs(self, startup_type=None, startup_urls=None,
155 homepage=None): 155 homepage=None, delete_migrated_pref=False):
156 """Changes the session startup type and the list of URLs to load on startup. 156 """Changes the session startup type and the list of URLs to load on startup.
157 157
158 Args: 158 Args:
159 startup_type: int with one of _SESSION_STARTUP_* values. 159 startup_type: int with one of _SESSION_STARTUP_* values. If startup_type
160 is None, then it deletes the preference.
160 startup_urls: list(str) with a list of URLs; if None, is left unchanged. 161 startup_urls: list(str) with a list of URLs; if None, is left unchanged.
161 homepage: unless None, the new value for homepage. 162 homepage: unless None, the new value for homepage.
163 delete_migrated_pref: Whether we should delete the preference which says
164 we've already migrated the startup_type preference.
162 """ 165 """
163 prefs = self._LoadPreferences() 166 prefs = self._LoadPreferences()
164 prefs['session']['restore_on_startup'] = startup_type 167 if startup_type is None:
168 del prefs['session']['restore_on_startup']
169 else:
170 prefs['session']['restore_on_startup'] = startup_type
171
165 if startup_urls is not None: 172 if startup_urls is not None:
166 prefs['session']['urls_to_restore_on_startup'] = startup_urls 173 prefs['session']['urls_to_restore_on_startup'] = startup_urls
167 if homepage is not None: 174 if homepage is not None:
168 prefs['homepage'] = homepage 175 prefs['homepage'] = homepage
176 if delete_migrated_pref:
177 del prefs['session']['restore_on_startup_migrated']
169 self._WritePreferences(prefs) 178 self._WritePreferences(prefs)
170 179
171 def _ChangePinnedTabsPrefs(self, pinned_tabs): 180 def _ChangePinnedTabsPrefs(self, pinned_tabs):
172 """Changes the list of pinned tabs. 181 """Changes the list of pinned tabs.
173 182
174 Args: 183 Args:
175 pinned_tabs: list(str) with a list of pinned tabs URLs. 184 pinned_tabs: list(str) with a list of pinned tabs URLs.
176 """ 185 """
177 prefs = self._LoadPreferences() 186 prefs = self._LoadPreferences()
178 prefs['pinned_tabs'] = [] 187 prefs['pinned_tabs'] = []
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 pre_launch_hook=lambda: self._ChangeSessionStartupPrefs( 454 pre_launch_hook=lambda: self._ChangeSessionStartupPrefs(
446 self._SESSION_STARTUP_URLS, 455 self._SESSION_STARTUP_URLS,
447 startup_urls=['http://www.google.com'])) 456 startup_urls=['http://www.google.com']))
448 # The change must be detected by Protector. 457 # The change must be detected by Protector.
449 self.assertTrue(self.GetProtectorState()['showing_change']) 458 self.assertTrue(self.GetProtectorState()['showing_change'])
450 # Change the setting manually. 459 # Change the setting manually.
451 self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_NTP) 460 self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_NTP)
452 # No longer showing the change. 461 # No longer showing the change.
453 self.assertFalse(self.GetProtectorState()['showing_change']) 462 self.assertFalse(self.GetProtectorState()['showing_change'])
454 463
455 def testSessionStartupPrefMigration(self): 464 def testSessionStartupPrefMigrationFromHomepage(self):
456 """Test migration from old session.restore_on_startup values (homepage).""" 465 """Test migration from old session.restore_on_startup values (homepage)."""
457 # Set startup prefs to restoring last open tabs. 466 # Set startup prefs to restoring last open tabs.
458 self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_LAST) 467 self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_LAST)
459 self.SetPrefs(pyauto.kURLsToRestoreOnStartup, []) 468 self.SetPrefs(pyauto.kURLsToRestoreOnStartup, [])
460 new_homepage = 'http://www.google.com/' 469 new_homepage = 'http://www.google.com/'
461 # Restart browser with startup prefs set to open homepage (google.com). 470 # Restart browser with startup prefs set to open homepage (google.com).
462 self.RestartBrowser( 471 self.RestartBrowser(
463 clear_profile=False, 472 clear_profile=False,
464 pre_launch_hook=lambda: self._ChangeSessionStartupPrefs( 473 pre_launch_hook=lambda: self._ChangeSessionStartupPrefs(
465 self._SESSION_STARTUP_HOMEPAGE, 474 self._SESSION_STARTUP_HOMEPAGE,
466 homepage=new_homepage)) 475 homepage=new_homepage,
476 delete_migrated_pref=True))
467 # The change must be detected by Protector. 477 # The change must be detected by Protector.
468 self.assertTrue(self.GetProtectorState()['showing_change']) 478 self.assertTrue(self.GetProtectorState()['showing_change'])
469 # Protector must restore old preference values. 479 # Protector must restore old preference values.
470 self.assertEqual(self._SESSION_STARTUP_LAST, 480 self.assertEqual(self._SESSION_STARTUP_LAST,
471 self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup)) 481 self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup))
472 self.assertEqual([], 482 self.assertEqual([],
473 self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup)) 483 self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup))
474 self.ApplyProtectorChange() 484 self.ApplyProtectorChange()
475 # Now the new preference values are active. 485 # Now the new preference values are active.
476 self.assertEqual(self._SESSION_STARTUP_URLS, 486 self.assertEqual(self._SESSION_STARTUP_URLS,
477 self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup)) 487 self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup))
478 # Homepage migrated to the list of startup URLs. 488 # Homepage migrated to the list of startup URLs.
479 self.assertEqual([new_homepage], 489 self.assertEqual([new_homepage],
480 self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup)) 490 self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup))
481 # No longer showing the change. 491 # No longer showing the change.
482 self.assertFalse(self.GetProtectorState()['showing_change']) 492 self.assertFalse(self.GetProtectorState()['showing_change'])
483 493
494 def testSessionStartupPrefMigrationFromBlank(self):
495 """Test migration from session.restore_on_startup being blank, as it would
496 be for a user who had m18 or lower, and never changed that preference.
497 """
498 # Set startup prefs to restoring last open tabs.
499 self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_LAST)
500 self.SetPrefs(pyauto.kURLsToRestoreOnStartup, [])
501 # Set the homepage.
502 new_homepage = 'http://www.google.com/'
503 self.SetPrefs(pyauto.kHomePageIsNewTabPage, False)
504 self.SetPrefs(pyauto.kHomePage, new_homepage)
505 # Restart browser, clearing the 'restore on startup' pref, to simulate a
506 # user coming from m18 and having left it on the default value.
507 self.RestartBrowser(
508 clear_profile=False,
509 pre_launch_hook=lambda: self._ChangeSessionStartupPrefs(
510 startup_type=None,
511 delete_migrated_pref=True))
512 # The change must be detected by Protector.
513 self.assertTrue(self.GetProtectorState()['showing_change'])
514 # Protector must restore old preference values.
515 self.assertEqual(self._SESSION_STARTUP_LAST,
516 self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup))
517 self.assertEqual([],
518 self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup))
519 self.ApplyProtectorChange()
520 # Now the new preference values are active.
521 self.assertEqual(self._SESSION_STARTUP_URLS,
522 self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup))
523 # Homepage migrated to the list of startup URLs.
524 self.assertEqual([new_homepage],
525 self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup))
526 # No longer showing the change.
527 self.assertFalse(self.GetProtectorState()['showing_change'])
528
529 def testSessionStartupPrefNoMigrationOnHomepageChange(self):
530 """Test that when the user modifies their homepage in m19+, we don't do the
531 preference migration.
532 """
533 # Initially, the default value is selected for kRestoreOnStartup.
534 self.assertEqual(self._SESSION_STARTUP_NTP,
535 self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup))
536 # Set the homepage, but leave kRestoreOnStartup unchanged.
537 new_homepage = 'http://www.google.com/'
538 self.SetPrefs(pyauto.kHomePageIsNewTabPage, False)
539 self.SetPrefs(pyauto.kHomePage, new_homepage)
540 # Restart browser.
541 self.RestartBrowser(clear_profile=False)
542 # Now the new preference values are active.
543 self.assertEqual(self._SESSION_STARTUP_NTP,
544 self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup))
545 # kURLsToRestoreOnStartup pref is unchanged.
546 self.assertEqual([],
547 self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup))
548 # No longer showing the change.
549 self.assertFalse(self.GetProtectorState()['showing_change'])
550
484 def testDetectPinnedTabsChangeAndApply(self): 551 def testDetectPinnedTabsChangeAndApply(self):
485 """Test for detecting and applying a change to pinned tabs.""" 552 """Test for detecting and applying a change to pinned tabs."""
486 pinned_urls = ['chrome://version/', 'chrome://credits/'] 553 pinned_urls = ['chrome://version/', 'chrome://credits/']
487 self.RestartBrowser( 554 self.RestartBrowser(
488 clear_profile=False, 555 clear_profile=False,
489 pre_launch_hook=lambda: self._ChangePinnedTabsPrefs(pinned_urls)) 556 pre_launch_hook=lambda: self._ChangePinnedTabsPrefs(pinned_urls))
490 # The change must be detected by Protector. 557 # The change must be detected by Protector.
491 self.assertTrue(self.GetProtectorState()['showing_change']) 558 self.assertTrue(self.GetProtectorState()['showing_change'])
492 # Protector must restore old preference values. 559 # Protector must restore old preference values.
493 self.assertEqual([], 560 self.assertEqual([],
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 pre_launch_hook=lambda: self._ChangeHomepage(new_homepage, False, True)) 766 pre_launch_hook=lambda: self._ChangeHomepage(new_homepage, False, True))
700 # Not showing the change. 767 # Not showing the change.
701 self.assertFalse(self.GetProtectorState()['showing_change']) 768 self.assertFalse(self.GetProtectorState()['showing_change'])
702 # New values must be active. 769 # New values must be active.
703 self.assertEquals(new_homepage, self.GetPrefsInfo().Prefs(pyauto.kHomePage)) 770 self.assertEquals(new_homepage, self.GetPrefsInfo().Prefs(pyauto.kHomePage))
704 self.assertEquals(True, self.GetPrefsInfo().Prefs(pyauto.kShowHomeButton)) 771 self.assertEquals(True, self.GetPrefsInfo().Prefs(pyauto.kShowHomeButton))
705 772
706 773
707 if __name__ == '__main__': 774 if __name__ == '__main__':
708 pyauto_functional.Main() 775 pyauto_functional.Main()
OLDNEW
« 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