Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / prefs / incognito_mode_prefs_unittest.cc
blobea15b9529ff3edd9844fe903c6de207fc3d40eaf
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 "chrome/test/base/testing_pref_service_syncable.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 class IncognitoModePrefsTest : public testing::Test {
12 protected:
13 virtual void SetUp() {
14 IncognitoModePrefs::RegisterProfilePrefs(prefs_.registry());
17 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 base::Value::CreateIntegerValue(
42 IncognitoModePrefs::ENABLED));
43 EXPECT_EQ(IncognitoModePrefs::ENABLED,
44 IncognitoModePrefs::GetAvailability(&prefs_));
46 prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
47 base::Value::CreateIntegerValue(
48 IncognitoModePrefs::DISABLED));
49 EXPECT_EQ(IncognitoModePrefs::DISABLED,
50 IncognitoModePrefs::GetAvailability(&prefs_));
52 prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
53 base::Value::CreateIntegerValue(
54 IncognitoModePrefs::FORCED));
55 EXPECT_EQ(IncognitoModePrefs::FORCED,
56 IncognitoModePrefs::GetAvailability(&prefs_));
59 typedef IncognitoModePrefsTest IncognitoModePrefsDeathTest;
61 // Takes too long to execute on Mac. http://crbug.com/101109
62 #if defined(OS_MACOSX)
63 #define MAYBE_GetAvailabilityBadValue DISABLED_GetAvailabilityBadValue
64 #else
65 #define MAYBE_GetAvailabilityBadValue GetAvailabilityBadValue
66 #endif
68 #if GTEST_HAS_DEATH_TEST
69 TEST_F(IncognitoModePrefsDeathTest, MAYBE_GetAvailabilityBadValue) {
70 prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
71 base::Value::CreateIntegerValue(-1));
72 #if defined(NDEBUG) && defined(DCHECK_ALWAYS_ON)
73 EXPECT_DEATH({
74 IncognitoModePrefs::Availability availability =
75 IncognitoModePrefs::GetAvailability(&prefs_);
76 EXPECT_EQ(IncognitoModePrefs::ENABLED, availability);
77 }, "");
78 #else
79 EXPECT_DEBUG_DEATH({
80 IncognitoModePrefs::Availability availability =
81 IncognitoModePrefs::GetAvailability(&prefs_);
82 EXPECT_EQ(IncognitoModePrefs::ENABLED, availability);
83 }, "");
84 #endif
86 #endif // GTEST_HAS_DEATH_TEST