restore_on_startup_policy_handler_unittest.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file. 41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <string> 61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/compiler_specific.h" 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/prefs/pref_value_map.h" 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/strings/string_number_conversions.h" 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/values.h" 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/prefs/session_startup_pref.h" 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/sessions/restore_on_startup_policy_handler.h" 151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/common/pref_names.h" 16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/browser/configuration_policy_handler.h" 17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/browser/policy_error_map.h" 18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/policy_map.h" 19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "grit/component_strings.h" 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "policy/policy_constants.h" 211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h" 231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace policy { 251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class RestoreOnStartupPolicyHandlerTest : public testing::Test { 271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) protected: 281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void SetPolicyValue(const std::string& policy, base::Value* value) { 291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) policies_.Set( 301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, value, NULL); 311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool CheckPolicySettings() { 331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return handler_.CheckPolicySettings(policies_, &errors_); 341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void ApplyPolicySettings() { 361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) handler_.ApplyPolicySettings(policies_, &prefs_); 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PolicyErrorMap& errors() { return errors_; } 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PrefValueMap& prefs() { return prefs_; } 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private: 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PolicyMap policies_; 431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PolicyErrorMap errors_; 441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PrefValueMap prefs_; 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) RestoreOnStartupPolicyHandler handler_; 461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}; 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, CheckPolicySettings_FailsTypeCheck) { 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Handler expects an int; pass it a bool. 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue(key::kRestoreOnStartup, new base::FundamentalValue(false)); 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Checking should fail and add an error to the error map. 521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_FALSE(CheckPolicySettings()); 531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(1U, errors().size()); 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(l10n_util::GetStringFUTF16( 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) IDS_POLICY_TYPE_ERROR, 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASCIIToUTF16(ConfigurationPolicyHandler::ValueTypeToString( 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Value::TYPE_INTEGER))), 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) errors().begin()->second); 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, CheckPolicySettings_Unspecified) { 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Don't specify a value for the policy. 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Checking should succeed with no errors. 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckPolicySettings()); 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(0U, errors().size()); 661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, CheckPolicySettings_UnknownValue) { 691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify an unknown value for the policy. 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int impossible_value = SessionStartupPref::kPrefValueHomePage + 711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SessionStartupPref::kPrefValueLast + 721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SessionStartupPref::kPrefValueURLs + 731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SessionStartupPref::kPrefValueNewTab; 741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue(key::kRestoreOnStartup, 751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(impossible_value)); 761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Checking should succeed but add an error to the error map. 771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckPolicySettings()); 781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(1U, errors().size()); 791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(l10n_util::GetStringFUTF16( 801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) IDS_POLICY_OUT_OF_RANGE_ERROR, 811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASCIIToUTF16(base::IntToString(impossible_value))), 821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) errors().begin()->second); 831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, CheckPolicySettings_HomePage) { 861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify the HomePage value. 871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kRestoreOnStartup, 891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage)); 901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Checking should succeed but add an error to the error map. 911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckPolicySettings()); 921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(1U, errors().size()); 931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(l10n_util::GetStringUTF16(IDS_POLICY_VALUE_DEPRECATED), 941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) errors().begin()->second); 951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, 981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckPolicySettings_RestoreLastSession_SessionCookies) { 991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify the Last value and the Session-Only Cookies value. 1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 1011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kRestoreOnStartup, 1021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(SessionStartupPref::kPrefValueLast)); 1031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<base::ListValue> urls(new base::ListValue); 1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) urls->AppendString("http://foo.com"); 1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue(key::kCookiesSessionOnlyForUrls, urls.release()); 1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Checking should succeed but add an error to the error map. 1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckPolicySettings()); 1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(1U, errors().size()); 1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(key::kCookiesSessionOnlyForUrls == errors().begin()->first); 1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_POLICY_OVERRIDDEN, 1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASCIIToUTF16(key::kRestoreOnStartup)), 1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) errors().begin()->second); 1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, 1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckPolicySettings_RestoreLastSession_ClearDataOnExit) { 1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify the Last value and the Clear-Data-On-Exit value. 1181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kRestoreOnStartup, 1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(SessionStartupPref::kPrefValueLast)); 1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue(key::kClearSiteDataOnExit, new base::FundamentalValue(true)); 1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Checking should succeed but add an error to the error map. 1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckPolicySettings()); 1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(1U, errors().size()); 1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(key::kClearSiteDataOnExit == errors().begin()->first); 1261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_POLICY_OVERRIDDEN, 1271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASCIIToUTF16(key::kRestoreOnStartup)), 1281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) errors().begin()->second); 1291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, 1321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckPolicySettings_RestoreLastSession) { 1331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify the Last value without the conflicts. 1341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 1351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kRestoreOnStartup, 1361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(SessionStartupPref::kPrefValueLast)); 1371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Checking should succeed with no errors. 1381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckPolicySettings()); 1391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(0U, errors().size()); 1401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, CheckPolicySettings_URLs) { 1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify the URLs value. 1441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kRestoreOnStartup, 1461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(SessionStartupPref::kPrefValueURLs)); 1471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Checking should succeed with no errors. 1481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckPolicySettings()); 1491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(0U, errors().size()); 1501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, CheckPolicySettings_NewTab) { 1531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify the NewTab value. 1541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 1551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kRestoreOnStartup, 1561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(SessionStartupPref::kPrefValueNewTab)); 1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Checking should succeed with no errors. 1581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(CheckPolicySettings()); 1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(0U, errors().size()); 1601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, ApplyPolicySettings_NoValue) { 1631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Don't specify a value for the policy. 1641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings(); 1651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The resulting prefs should be empty. 1661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs().begin() == prefs().end()); 1671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, ApplyPolicySettings_WrongType) { 1701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Handler expects an int; pass it a bool. 1711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue(key::kRestoreOnStartup, new base::FundamentalValue(false)); 1721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The resulting prefs should be empty. 1731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs().begin() == prefs().end()); 1741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, ApplyPolicySettings_NotHomePage) { 1771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify anything except the HomePage value. 1781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int not_home_page = SessionStartupPref::kPrefValueHomePage + 1; 1791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue(key::kRestoreOnStartup, 1801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(not_home_page)); 1811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings(); 1821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The resulting prefs should have the value we specified. 1831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int result; 1841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs().GetInteger(prefs::kRestoreOnStartup, &result)); 1851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(not_home_page, result); 1861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, 1891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings_HomePage_NoHomePageValue) { 1901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify the HomePage value but no HomePageIsNewTabPage value. 1911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 1921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kRestoreOnStartup, 1931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage)); 1941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings(); 1951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The resulting prefs should be empty. 1961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs().begin() == prefs().end()); 1971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, 2001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings_HomePage_HomePageValueIsWrongType) { 2011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify the HomePage value and an integer for the home page value. 2021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 2031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kRestoreOnStartup, 2041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage)); 2051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 2061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kHomepageIsNewTabPage, 2071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(314159)); 2081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings(); 2091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The resulting prefs should be empty. 2101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs().begin() == prefs().end()); 2111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, 2141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings_HomePage_HomePageIsNewTabPage) { 2151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify the HomePage value and the home page as the new tab page. 2161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 2171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kRestoreOnStartup, 2181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage)); 2191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 2201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kHomepageIsNewTabPage, 2211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(true)); 2221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings(); 2231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The resulting prefs should have the restore value as NTP. 2241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int result; 2251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs().GetInteger(prefs::kRestoreOnStartup, &result)); 2261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int expected = SessionStartupPref::kPrefValueNewTab; 2271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(expected, result); 2281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, 2311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings_HomePage_HomePageIsNotNewTabPage_NotDefined) { 2321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify the HomePage value but don't specify the home page to use. 2331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 2341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kRestoreOnStartup, 2351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage)); 2361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 2371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kHomepageIsNewTabPage, 2381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(false)); 2391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings(); 2401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The resulting prefs should be empty. 2411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs().begin() == prefs().end()); 2421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, 2451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings_HomePage_HomePageIsNotNewTabPage_WrongType) { 2461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Specify the HomePage value but specify a boolean as the home page. 2471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 2481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kRestoreOnStartup, 2491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage)); 2501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 2511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kHomepageIsNewTabPage, 2521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(false)); 2531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 2541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kHomepageLocation, 2551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(false)); 2561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings(); 2571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The resulting prefs should be empty. 2581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs().begin() == prefs().end()); 2591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RestoreOnStartupPolicyHandlerTest, 2621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings_HomePage_HomePageIsNotNewTabPage) { 2631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue( 2641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) key::kRestoreOnStartup, 2651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::FundamentalValue(SessionStartupPref::kPrefValueHomePage)); 2661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue(key::kHomepageIsNewTabPage, new base::FundamentalValue(false)); 2671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetPolicyValue(key::kHomepageLocation, 2681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new base::StringValue("http://foo.com")); 2691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ApplyPolicySettings(); 2701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The resulting prefs should have have URLs specified for startup. 2721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int result; 2731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs().GetInteger(prefs::kRestoreOnStartup, &result)); 2741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int expected = SessionStartupPref::kPrefValueURLs; 2751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(expected, result); 2761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The resulting prefs should have the URL we specified as the home page. 2781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::Value* url_result; 2791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs().GetValue(prefs::kURLsToRestoreOnStartup, &url_result)); 2801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::ListValue* url_list_result; 2811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(url_result->GetAsList(&url_list_result)); 2821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(1U, url_list_result->GetSize()); 2831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string expected_url; 2841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(url_list_result->GetString(0, &expected_url)); 2851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(std::string("http://foo.com"), expected_url); 2861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} // namespace policy 289