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

Side by Side Diff: chrome/test/functional/protector.py

Issue 10173007: Revert 133740 - Fix homepage migration for users who never changed their settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
« no previous file with comments | « chrome/common/pref_names.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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=None, startup_urls=None, 154 def _ChangeSessionStartupPrefs(self, startup_type, startup_urls=None,
155 homepage=None, delete_migrated_pref=False): 155 homepage=None):
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. If startup_type 159 startup_type: int with one of _SESSION_STARTUP_* values.
160 is None, then it deletes the preference.
161 startup_urls: list(str) with a list of URLs; if None, is left unchanged. 160 startup_urls: list(str) with a list of URLs; if None, is left unchanged.
162 homepage: unless None, the new value for homepage. 161 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.
165 """ 162 """
166 prefs = self._LoadPreferences() 163 prefs = self._LoadPreferences()
167 if startup_type is None: 164 prefs['session']['restore_on_startup'] = startup_type
168 del prefs['session']['restore_on_startup']
169 else:
170 prefs['session']['restore_on_startup'] = startup_type
171
172 if startup_urls is not None: 165 if startup_urls is not None:
173 prefs['session']['urls_to_restore_on_startup'] = startup_urls 166 prefs['session']['urls_to_restore_on_startup'] = startup_urls
174 if homepage is not None: 167 if homepage is not None:
175 prefs['homepage'] = homepage 168 prefs['homepage'] = homepage
176 if delete_migrated_pref:
177 del prefs['session']['restore_on_startup_migrated']
178 self._WritePreferences(prefs) 169 self._WritePreferences(prefs)
179 170
180 def _ChangePinnedTabsPrefs(self, pinned_tabs): 171 def _ChangePinnedTabsPrefs(self, pinned_tabs):
181 """Changes the list of pinned tabs. 172 """Changes the list of pinned tabs.
182 173
183 Args: 174 Args:
184 pinned_tabs: list(str) with a list of pinned tabs URLs. 175 pinned_tabs: list(str) with a list of pinned tabs URLs.
185 """ 176 """
186 prefs = self._LoadPreferences() 177 prefs = self._LoadPreferences()
187 prefs['pinned_tabs'] = [] 178 prefs['pinned_tabs'] = []
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 pre_launch_hook=lambda: self._ChangeSessionStartupPrefs( 445 pre_launch_hook=lambda: self._ChangeSessionStartupPrefs(
455 self._SESSION_STARTUP_URLS, 446 self._SESSION_STARTUP_URLS,
456 startup_urls=['http://www.google.com'])) 447 startup_urls=['http://www.google.com']))
457 # The change must be detected by Protector. 448 # The change must be detected by Protector.
458 self.assertTrue(self.GetProtectorState()['showing_change']) 449 self.assertTrue(self.GetProtectorState()['showing_change'])
459 # Change the setting manually. 450 # Change the setting manually.
460 self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_NTP) 451 self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_NTP)
461 # No longer showing the change. 452 # No longer showing the change.
462 self.assertFalse(self.GetProtectorState()['showing_change']) 453 self.assertFalse(self.GetProtectorState()['showing_change'])
463 454
464 def testSessionStartupPrefMigrationFromHomepage(self): 455 def testSessionStartupPrefMigration(self):
465 """Test migration from old session.restore_on_startup values (homepage).""" 456 """Test migration from old session.restore_on_startup values (homepage)."""
466 # Set startup prefs to restoring last open tabs. 457 # Set startup prefs to restoring last open tabs.
467 self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_LAST) 458 self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_LAST)
468 self.SetPrefs(pyauto.kURLsToRestoreOnStartup, []) 459 self.SetPrefs(pyauto.kURLsToRestoreOnStartup, [])
469 new_homepage = 'http://www.google.com/' 460 new_homepage = 'http://www.google.com/'
470 # Restart browser with startup prefs set to open homepage (google.com). 461 # Restart browser with startup prefs set to open homepage (google.com).
471 self.RestartBrowser( 462 self.RestartBrowser(
472 clear_profile=False, 463 clear_profile=False,
473 pre_launch_hook=lambda: self._ChangeSessionStartupPrefs( 464 pre_launch_hook=lambda: self._ChangeSessionStartupPrefs(
474 self._SESSION_STARTUP_HOMEPAGE, 465 self._SESSION_STARTUP_HOMEPAGE,
475 homepage=new_homepage, 466 homepage=new_homepage))
476 delete_migrated_pref=True))
477 # The change must be detected by Protector. 467 # The change must be detected by Protector.
478 self.assertTrue(self.GetProtectorState()['showing_change']) 468 self.assertTrue(self.GetProtectorState()['showing_change'])
479 # Protector must restore old preference values. 469 # Protector must restore old preference values.
480 self.assertEqual(self._SESSION_STARTUP_LAST, 470 self.assertEqual(self._SESSION_STARTUP_LAST,
481 self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup)) 471 self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup))
482 self.assertEqual([], 472 self.assertEqual([],
483 self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup)) 473 self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup))
484 self.ApplyProtectorChange() 474 self.ApplyProtectorChange()
485 # Now the new preference values are active. 475 # Now the new preference values are active.
486 self.assertEqual(self._SESSION_STARTUP_URLS, 476 self.assertEqual(self._SESSION_STARTUP_URLS,
487 self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup)) 477 self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup))
488 # Homepage migrated to the list of startup URLs. 478 # Homepage migrated to the list of startup URLs.
489 self.assertEqual([new_homepage], 479 self.assertEqual([new_homepage],
490 self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup)) 480 self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup))
491 # No longer showing the change. 481 # No longer showing the change.
492 self.assertFalse(self.GetProtectorState()['showing_change']) 482 self.assertFalse(self.GetProtectorState()['showing_change'])
493 483
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
551 def testDetectPinnedTabsChangeAndApply(self): 484 def testDetectPinnedTabsChangeAndApply(self):
552 """Test for detecting and applying a change to pinned tabs.""" 485 """Test for detecting and applying a change to pinned tabs."""
553 pinned_urls = ['chrome://version/', 'chrome://credits/'] 486 pinned_urls = ['chrome://version/', 'chrome://credits/']
554 self.RestartBrowser( 487 self.RestartBrowser(
555 clear_profile=False, 488 clear_profile=False,
556 pre_launch_hook=lambda: self._ChangePinnedTabsPrefs(pinned_urls)) 489 pre_launch_hook=lambda: self._ChangePinnedTabsPrefs(pinned_urls))
557 # The change must be detected by Protector. 490 # The change must be detected by Protector.
558 self.assertTrue(self.GetProtectorState()['showing_change']) 491 self.assertTrue(self.GetProtectorState()['showing_change'])
559 # Protector must restore old preference values. 492 # Protector must restore old preference values.
560 self.assertEqual([], 493 self.assertEqual([],
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 pre_launch_hook=lambda: self._ChangeHomepage(new_homepage, False, True)) 699 pre_launch_hook=lambda: self._ChangeHomepage(new_homepage, False, True))
767 # Not showing the change. 700 # Not showing the change.
768 self.assertFalse(self.GetProtectorState()['showing_change']) 701 self.assertFalse(self.GetProtectorState()['showing_change'])
769 # New values must be active. 702 # New values must be active.
770 self.assertEquals(new_homepage, self.GetPrefsInfo().Prefs(pyauto.kHomePage)) 703 self.assertEquals(new_homepage, self.GetPrefsInfo().Prefs(pyauto.kHomePage))
771 self.assertEquals(True, self.GetPrefsInfo().Prefs(pyauto.kShowHomeButton)) 704 self.assertEquals(True, self.GetPrefsInfo().Prefs(pyauto.kShowHomeButton))
772 705
773 706
774 if __name__ == '__main__': 707 if __name__ == '__main__':
775 pyauto_functional.Main() 708 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « chrome/common/pref_names.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698