Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / prefs / incognito_mode_prefs_unittest.cc
blob67268cb75c27d648fd7e41f4d746de0eaefb8261
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
3 // found in the LICENSE file.
5 #include "chrome/browser/prefs/incognito_mode_prefs.h"
7 #include "chrome/common/pref_names.h"
8 #include "components/syncable_prefs/testing_pref_service_syncable.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 class IncognitoModePrefsTest : public testing::Test {
12 protected:
13 void SetUp() override {
14 IncognitoModePrefs::RegisterProfilePrefs(prefs_.registry());
17 syncable_prefs::TestingPrefServiceSyncable prefs_;
20 TEST_F(IncognitoModePrefsTest, IntToAvailability) {
21 ASSERT_EQ(0, IncognitoModePrefs::ENABLED);
22 ASSERT_EQ(1, IncognitoModePrefs::DISABLED);
23 ASSERT_EQ(2, IncognitoModePrefs::FORCED);
25 IncognitoModePrefs::Availability incognito;
26 EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(0, &incognito));
27 EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito);
28 EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(1, &incognito));
29 EXPECT_EQ(IncognitoModePrefs::DISABLED, incognito);
30 EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(2, &incognito));
31 EXPECT_EQ(IncognitoModePrefs::FORCED, incognito);
33 EXPECT_FALSE(IncognitoModePrefs::IntToAvailability(10, &incognito));
34 EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito);
35 EXPECT_FALSE(IncognitoModePrefs::IntToAvailability(-1, &incognito));
36 EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito);
39 TEST_F(IncognitoModePrefsTest, GetAvailability) {
40 prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
41 new base::FundamentalValue(IncognitoModePrefs::ENABLED));
42 EXPECT_EQ(IncognitoModePrefs::ENABLED,
43 IncognitoModePrefs::GetAvailability(&prefs_));
45 prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
46 new base::FundamentalValue(IncognitoModePrefs::DISABLED));
47 EXPECT_EQ(IncognitoModePrefs::DISABLED,
48 IncognitoModePrefs::GetAvailability(&prefs_));
50 prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
51 new base::FundamentalValue(IncognitoModePrefs::FORCED));
52 EXPECT_EQ(IncognitoModePrefs::FORCED,
53 IncognitoModePrefs::GetAvailability(&prefs_));
56 typedef IncognitoModePrefsTest IncognitoModePrefsDeathTest;
58 #if GTEST_HAS_DEATH_TEST
59 TEST_F(IncognitoModePrefsDeathTest, GetAvailabilityBadValue) {
60 prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
61 new base::FundamentalValue(-1));
62 #if defined(NDEBUG) && defined(DCHECK_ALWAYS_ON)
63 EXPECT_DEATH({
64 IncognitoModePrefs::Availability availability =
65 IncognitoModePrefs::GetAvailability(&prefs_);
66 EXPECT_EQ(IncognitoModePrefs::ENABLED, availability);
67 }, "");
68 #else
69 EXPECT_DEBUG_DEATH({
70 IncognitoModePrefs::Availability availability =
71 IncognitoModePrefs::GetAvailability(&prefs_);
72 EXPECT_EQ(IncognitoModePrefs::ENABLED, availability);
73 }, "");
74 #endif
76 #endif // GTEST_HAS_DEATH_TEST