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

Side by Side Diff: chrome/browser/sessions/restore_on_startup_policy_handler_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: Change comment for kRestoreOnStartup 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/prefs/pref_value_map.h" 9 #include "base/prefs/pref_value_map.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/prefs/session_startup_pref.h" 13 #include "chrome/browser/prefs/session_startup_pref.h"
14 #include "chrome/browser/sessions/restore_on_startup_policy_handler.h" 14 #include "chrome/browser/sessions/restore_on_startup_policy_handler.h"
15 #include "chrome/common/pref_names.h"
16 #include "components/policy/core/browser/configuration_policy_handler.h" 15 #include "components/policy/core/browser/configuration_policy_handler.h"
17 #include "components/policy/core/browser/policy_error_map.h" 16 #include "components/policy/core/browser/policy_error_map.h"
18 #include "components/policy/core/common/policy_map.h" 17 #include "components/policy/core/common/policy_map.h"
19 #include "components/policy/core/common/policy_types.h" 18 #include "components/policy/core/common/policy_types.h"
20 #include "grit/components_strings.h" 19 #include "grit/components_strings.h"
21 #include "policy/policy_constants.h" 20 #include "policy/policy_constants.h"
22 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
24 23
25 namespace policy { 24 namespace policy {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 62
64 TEST_F(RestoreOnStartupPolicyHandlerTest, CheckPolicySettings_Unspecified) { 63 TEST_F(RestoreOnStartupPolicyHandlerTest, CheckPolicySettings_Unspecified) {
65 // Don't specify a value for the policy. 64 // Don't specify a value for the policy.
66 // Checking should succeed with no errors. 65 // Checking should succeed with no errors.
67 EXPECT_TRUE(CheckPolicySettings()); 66 EXPECT_TRUE(CheckPolicySettings());
68 EXPECT_EQ(0U, errors().size()); 67 EXPECT_EQ(0U, errors().size());
69 } 68 }
70 69
71 TEST_F(RestoreOnStartupPolicyHandlerTest, CheckPolicySettings_UnknownValue) { 70 TEST_F(RestoreOnStartupPolicyHandlerTest, CheckPolicySettings_UnknownValue) {
72 // Specify an unknown value for the policy. 71 // Specify an unknown value for the policy.
73 int impossible_value = SessionStartupPref::kPrefValueHomePage + 72 int impossible_value = SessionStartupPref::kPrefValueLast +
74 SessionStartupPref::kPrefValueLast +
75 SessionStartupPref::kPrefValueURLs + 73 SessionStartupPref::kPrefValueURLs +
76 SessionStartupPref::kPrefValueNewTab; 74 SessionStartupPref::kPrefValueNewTab;
77 SetPolicyValue(key::kRestoreOnStartup, 75 SetPolicyValue(key::kRestoreOnStartup,
78 new base::FundamentalValue(impossible_value)); 76 new base::FundamentalValue(impossible_value));
79 // Checking should succeed but add an error to the error map. 77 // Checking should succeed but add an error to the error map.
80 EXPECT_TRUE(CheckPolicySettings()); 78 EXPECT_TRUE(CheckPolicySettings());
81 EXPECT_EQ(1U, errors().size()); 79 EXPECT_EQ(1U, errors().size());
82 EXPECT_EQ(l10n_util::GetStringFUTF16( 80 EXPECT_EQ(l10n_util::GetStringFUTF16(
83 IDS_POLICY_OUT_OF_RANGE_ERROR, 81 IDS_POLICY_OUT_OF_RANGE_ERROR,
84 base::ASCIIToUTF16(base::IntToString(impossible_value))), 82 base::ASCIIToUTF16(base::IntToString(impossible_value))),
85 errors().begin()->second); 83 errors().begin()->second);
86 } 84 }
87 85
88 TEST_F(RestoreOnStartupPolicyHandlerTest, CheckPolicySettings_HomePage) {
89 // Specify the HomePage value.
90 SetPolicyValue(
91 key::kRestoreOnStartup,
92 new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage));
Andrew T Wilson (Slow) 2015/12/08 18:09:34 Let's restore this test.
sdefresne 2015/12/09 18:41:06 Done.
93 // Checking should succeed but add an error to the error map.
94 EXPECT_TRUE(CheckPolicySettings());
95 EXPECT_EQ(1U, errors().size());
96 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_POLICY_VALUE_DEPRECATED),
97 errors().begin()->second);
98 }
99
100 TEST_F(RestoreOnStartupPolicyHandlerTest, 86 TEST_F(RestoreOnStartupPolicyHandlerTest,
101 CheckPolicySettings_RestoreLastSession_SessionCookies) { 87 CheckPolicySettings_RestoreLastSession_SessionCookies) {
102 // Specify the Last value and the Session-Only Cookies value. 88 // Specify the Last value and the Session-Only Cookies value.
103 SetPolicyValue( 89 SetPolicyValue(
104 key::kRestoreOnStartup, 90 key::kRestoreOnStartup,
105 new base::FundamentalValue(SessionStartupPref::kPrefValueLast)); 91 new base::FundamentalValue(SessionStartupPref::kPrefValueLast));
106 scoped_ptr<base::ListValue> urls(new base::ListValue); 92 scoped_ptr<base::ListValue> urls(new base::ListValue);
107 urls->AppendString("http://foo.com"); 93 urls->AppendString("http://foo.com");
108 SetPolicyValue(key::kCookiesSessionOnlyForUrls, urls.release()); 94 SetPolicyValue(key::kCookiesSessionOnlyForUrls, urls.release());
109 // Checking should succeed but add an error to the error map. 95 // Checking should succeed but add an error to the error map.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 EXPECT_TRUE(prefs().begin() == prefs().end()); 157 EXPECT_TRUE(prefs().begin() == prefs().end());
172 } 158 }
173 159
174 TEST_F(RestoreOnStartupPolicyHandlerTest, ApplyPolicySettings_WrongType) { 160 TEST_F(RestoreOnStartupPolicyHandlerTest, ApplyPolicySettings_WrongType) {
175 // Handler expects an int; pass it a bool. 161 // Handler expects an int; pass it a bool.
176 SetPolicyValue(key::kRestoreOnStartup, new base::FundamentalValue(false)); 162 SetPolicyValue(key::kRestoreOnStartup, new base::FundamentalValue(false));
177 // The resulting prefs should be empty. 163 // The resulting prefs should be empty.
178 EXPECT_TRUE(prefs().begin() == prefs().end()); 164 EXPECT_TRUE(prefs().begin() == prefs().end());
179 } 165 }
180 166
181 TEST_F(RestoreOnStartupPolicyHandlerTest, ApplyPolicySettings_NotHomePage) {
182 // Specify anything except the HomePage value.
183 int not_home_page = SessionStartupPref::kPrefValueHomePage + 1;
Andrew T Wilson (Slow) 2015/12/08 18:09:34 I think we should restore this test also as it's m
sdefresne 2015/12/09 18:41:05 Done.
184 SetPolicyValue(key::kRestoreOnStartup,
185 new base::FundamentalValue(not_home_page));
186 ApplyPolicySettings();
187 // The resulting prefs should have the value we specified.
188 int result;
189 EXPECT_TRUE(prefs().GetInteger(prefs::kRestoreOnStartup, &result));
190 EXPECT_EQ(not_home_page, result);
191 }
192
193 TEST_F(RestoreOnStartupPolicyHandlerTest,
194 ApplyPolicySettings_HomePage_NoHomePageValue) {
195 // Specify the HomePage value but no HomePageIsNewTabPage value.
196 SetPolicyValue(
197 key::kRestoreOnStartup,
198 new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage));
199 ApplyPolicySettings();
200 // The resulting prefs should be empty.
201 EXPECT_TRUE(prefs().begin() == prefs().end());
202 }
203
204 TEST_F(RestoreOnStartupPolicyHandlerTest,
205 ApplyPolicySettings_HomePage_HomePageValueIsWrongType) {
206 // Specify the HomePage value and an integer for the home page value.
207 SetPolicyValue(
208 key::kRestoreOnStartup,
209 new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage));
210 SetPolicyValue(
211 key::kHomepageIsNewTabPage,
212 new base::FundamentalValue(314159));
213 ApplyPolicySettings();
214 // The resulting prefs should be empty.
215 EXPECT_TRUE(prefs().begin() == prefs().end());
216 }
217
218 TEST_F(RestoreOnStartupPolicyHandlerTest,
219 ApplyPolicySettings_HomePage_HomePageIsNewTabPage) {
220 // Specify the HomePage value and the home page as the new tab page.
221 SetPolicyValue(
222 key::kRestoreOnStartup,
223 new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage));
224 SetPolicyValue(
225 key::kHomepageIsNewTabPage,
226 new base::FundamentalValue(true));
227 ApplyPolicySettings();
228 // The resulting prefs should have the restore value as NTP.
229 int result;
230 EXPECT_TRUE(prefs().GetInteger(prefs::kRestoreOnStartup, &result));
231 int expected = SessionStartupPref::kPrefValueNewTab;
232 EXPECT_EQ(expected, result);
233 }
234
235 TEST_F(RestoreOnStartupPolicyHandlerTest,
236 ApplyPolicySettings_HomePage_HomePageIsNotNewTabPage_NotDefined) {
237 // Specify the HomePage value but don't specify the home page to use.
238 SetPolicyValue(
239 key::kRestoreOnStartup,
240 new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage));
241 SetPolicyValue(
242 key::kHomepageIsNewTabPage,
243 new base::FundamentalValue(false));
244 ApplyPolicySettings();
245 // The resulting prefs should be empty.
246 EXPECT_TRUE(prefs().begin() == prefs().end());
247 }
248
249 TEST_F(RestoreOnStartupPolicyHandlerTest,
250 ApplyPolicySettings_HomePage_HomePageIsNotNewTabPage_WrongType) {
251 // Specify the HomePage value but specify a boolean as the home page.
252 SetPolicyValue(
253 key::kRestoreOnStartup,
254 new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage));
255 SetPolicyValue(
256 key::kHomepageIsNewTabPage,
257 new base::FundamentalValue(false));
258 SetPolicyValue(
259 key::kHomepageLocation,
260 new base::FundamentalValue(false));
261 ApplyPolicySettings();
262 // The resulting prefs should be empty.
263 EXPECT_TRUE(prefs().begin() == prefs().end());
264 }
265
266 TEST_F(RestoreOnStartupPolicyHandlerTest,
267 ApplyPolicySettings_HomePage_HomePageIsNotNewTabPage) {
268 SetPolicyValue(
269 key::kRestoreOnStartup,
270 new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage));
271 SetPolicyValue(key::kHomepageIsNewTabPage, new base::FundamentalValue(false));
272 SetPolicyValue(key::kHomepageLocation,
273 new base::StringValue("http://foo.com"));
274 ApplyPolicySettings();
275
276 // The resulting prefs should have have URLs specified for startup.
277 int result;
278 EXPECT_TRUE(prefs().GetInteger(prefs::kRestoreOnStartup, &result));
279 int expected = SessionStartupPref::kPrefValueURLs;
280 EXPECT_EQ(expected, result);
281
282 // The resulting prefs should have the URL we specified as the home page.
283 base::Value* url_result;
284 EXPECT_TRUE(prefs().GetValue(prefs::kURLsToRestoreOnStartup, &url_result));
285 base::ListValue* url_list_result;
286 EXPECT_TRUE(url_result->GetAsList(&url_list_result));
287 EXPECT_EQ(1U, url_list_result->GetSize());
288 std::string expected_url;
289 EXPECT_TRUE(url_list_result->GetString(0, &expected_url));
290 EXPECT_EQ(std::string("http://foo.com"), expected_url);
291 }
292
293 } // namespace policy 167 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698