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

Side by Side Diff: chrome/browser/prefs/session_startup_pref_unittest.cc

Issue 1312693005: Remove migration of obsolete value for "session.restore_on_startup". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@url-to-restore-on-startup
Patch Set: Re-enable the two tests Created 5 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/prefs/session_startup_pref.h" 5 #include "chrome/browser/prefs/session_startup_pref.h"
6 #include "chrome/common/pref_names.h" 6 #include "chrome/common/pref_names.h"
7 #include "components/pref_registry/pref_registry_syncable.h" 7 #include "components/pref_registry/pref_registry_syncable.h"
8 #include "components/syncable_prefs/testing_pref_service_syncable.h" 8 #include "components/syncable_prefs/testing_pref_service_syncable.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 // Unit tests for SessionStartupPref. 12 // Unit tests for SessionStartupPref.
13 class SessionStartupPrefTest : public testing::Test { 13 class SessionStartupPrefTest : public testing::Test {
14 public: 14 public:
15 void SetUp() override { 15 void SetUp() override {
16 pref_service_.reset(new syncable_prefs::TestingPrefServiceSyncable); 16 pref_service_.reset(new syncable_prefs::TestingPrefServiceSyncable);
17 SessionStartupPref::RegisterProfilePrefs(registry()); 17 SessionStartupPref::RegisterProfilePrefs(registry());
18 registry()->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, true); 18 registry()->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, true);
19 } 19 }
20 20
21 bool IsUseLastOpenDefault() {
22 // On ChromeOS, the default SessionStartupPref is LAST.
23 #if defined(OS_CHROMEOS)
24 return true;
25 #else
26 return false;
27 #endif
28 }
29
30 user_prefs::PrefRegistrySyncable* registry() { 21 user_prefs::PrefRegistrySyncable* registry() {
31 return pref_service_->registry(); 22 return pref_service_->registry();
32 } 23 }
33 24
34 scoped_ptr<syncable_prefs::TestingPrefServiceSyncable> pref_service_; 25 scoped_ptr<syncable_prefs::TestingPrefServiceSyncable> pref_service_;
35 }; 26 };
36 27
37 TEST_F(SessionStartupPrefTest, URLListIsFixedUp) { 28 TEST_F(SessionStartupPrefTest, URLListIsFixedUp) {
38 base::ListValue* url_pref_list = new base::ListValue; 29 base::ListValue* url_pref_list = new base::ListValue;
39 url_pref_list->Set(0, new base::StringValue("google.com")); 30 url_pref_list->Set(0, new base::StringValue("google.com"));
(...skipping 24 matching lines...) Expand all
64 EXPECT_EQ(3u, result.urls.size()); 55 EXPECT_EQ(3u, result.urls.size());
65 56
66 SessionStartupPref override_test = 57 SessionStartupPref override_test =
67 SessionStartupPref(SessionStartupPref::URLS); 58 SessionStartupPref(SessionStartupPref::URLS);
68 override_test.urls.push_back(GURL("dev.chromium.org")); 59 override_test.urls.push_back(GURL("dev.chromium.org"));
69 SessionStartupPref::SetStartupPref(pref_service_.get(), override_test); 60 SessionStartupPref::SetStartupPref(pref_service_.get(), override_test);
70 61
71 result = SessionStartupPref::GetStartupPref(pref_service_.get()); 62 result = SessionStartupPref::GetStartupPref(pref_service_.get());
72 EXPECT_EQ(3u, result.urls.size()); 63 EXPECT_EQ(3u, result.urls.size());
73 } 64 }
74
75 // Checks to make sure that if the user had previously not selected anything
76 // (so that, in effect, the default value "Open the homepage" was selected),
77 // their preferences are migrated on upgrade to m19.
78 TEST_F(SessionStartupPrefTest, DefaultMigration) {
79 registry()->RegisterStringPref(prefs::kHomePage, "http://google.com/");
80 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/");
81 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, false);
82
83 EXPECT_FALSE(pref_service_->HasPrefPath(prefs::kRestoreOnStartup));
84
85 SessionStartupPref pref = SessionStartupPref::GetStartupPref(
86 pref_service_.get());
87
88 if (IsUseLastOpenDefault()) {
89 EXPECT_EQ(SessionStartupPref::LAST, pref.type);
90 EXPECT_EQ(0U, pref.urls.size());
91 } else {
92 EXPECT_EQ(SessionStartupPref::URLS, pref.type);
93 EXPECT_EQ(1U, pref.urls.size());
94 EXPECT_EQ(GURL("http://chromium.org/"), pref.urls[0]);
95 }
96 }
97
98 // Checks to make sure that if the user had previously not selected anything
99 // (so that, in effect, the default value "Open the homepage" was selected),
100 // and the NTP is being used for the homepage, their preferences are migrated
101 // to "Open the New Tab Page" on upgrade to M19.
102 TEST_F(SessionStartupPrefTest, DefaultMigrationHomepageIsNTP) {
103 registry()->RegisterStringPref(prefs::kHomePage, "http://google.com/");
104 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/");
105 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, true);
106
107 EXPECT_FALSE(pref_service_->HasPrefPath(prefs::kRestoreOnStartup));
108
109 SessionStartupPref pref = SessionStartupPref::GetStartupPref(
110 pref_service_.get());
111
112 if (IsUseLastOpenDefault())
113 EXPECT_EQ(SessionStartupPref::LAST, pref.type);
114 else
115 EXPECT_EQ(SessionStartupPref::DEFAULT, pref.type);
116
117 // The "URLs to restore on startup" shouldn't get migrated.
118 EXPECT_EQ(0U, pref.urls.size());
119 }
120
121 // Checks to make sure that if the user had previously selected "Open the
122 // "homepage", their preferences are migrated on upgrade to M19.
123 TEST_F(SessionStartupPrefTest, HomePageMigration) {
124 registry()->RegisterStringPref(prefs::kHomePage, "http://google.com/");
125
126 // By design, it's impossible to set the 'restore on startup' pref to 0
127 // ("open the homepage") using SessionStartupPref::SetStartupPref(), so set it
128 // using the pref service directly.
129 pref_service_->SetInteger(prefs::kRestoreOnStartup, /*kPrefValueHomePage*/ 0);
130 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/");
131 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, false);
132
133 SessionStartupPref pref = SessionStartupPref::GetStartupPref(
134 pref_service_.get());
135
136 EXPECT_EQ(SessionStartupPref::URLS, pref.type);
137 EXPECT_EQ(1U, pref.urls.size());
138 EXPECT_EQ(GURL("http://chromium.org/"), pref.urls[0]);
139 }
140
141 // Checks to make sure that if the user had previously selected "Open the
142 // "homepage", and the NTP is being used for the homepage, their preferences
143 // are migrated on upgrade to M19.
144 TEST_F(SessionStartupPrefTest, HomePageMigrationHomepageIsNTP) {
145 registry()->RegisterStringPref(prefs::kHomePage, "http://google.com/");
146
147 // By design, it's impossible to set the 'restore on startup' pref to 0
148 // ("open the homepage") using SessionStartupPref::SetStartupPref(), so set it
149 // using the pref service directly.
150 pref_service_->SetInteger(prefs::kRestoreOnStartup, /*kPrefValueHomePage*/ 0);
151 pref_service_->SetString(prefs::kHomePage, "http://chromium.org/");
152 pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, true);
153
154 SessionStartupPref pref = SessionStartupPref::GetStartupPref(
155 pref_service_.get());
156
157 EXPECT_EQ(SessionStartupPref::DEFAULT, pref.type);
158 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/session_startup_pref.cc ('k') | chrome/browser/profile_resetter/profile_resetter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698