1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "testing/gtest/include/gtest/gtest.h"
class IncognitoModePrefsTest : public testing::Test {
protected:
virtual void SetUp() {
IncognitoModePrefs::RegisterProfilePrefs(prefs_.registry());
}
TestingPrefServiceSyncable prefs_;
};
TEST_F(IncognitoModePrefsTest, IntToAvailability) {
ASSERT_EQ(0, IncognitoModePrefs::ENABLED);
ASSERT_EQ(1, IncognitoModePrefs::DISABLED);
ASSERT_EQ(2, IncognitoModePrefs::FORCED);
IncognitoModePrefs::Availability incognito;
EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(0, &incognito));
EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito);
EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(1, &incognito));
EXPECT_EQ(IncognitoModePrefs::DISABLED, incognito);
EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(2, &incognito));
EXPECT_EQ(IncognitoModePrefs::FORCED, incognito);
EXPECT_FALSE(IncognitoModePrefs::IntToAvailability(10, &incognito));
EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito);
EXPECT_FALSE(IncognitoModePrefs::IntToAvailability(-1, &incognito));
EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito);
}
TEST_F(IncognitoModePrefsTest, GetAvailability) {
prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
Value::CreateIntegerValue(IncognitoModePrefs::ENABLED));
EXPECT_EQ(IncognitoModePrefs::ENABLED,
IncognitoModePrefs::GetAvailability(&prefs_));
prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
Value::CreateIntegerValue(IncognitoModePrefs::DISABLED));
EXPECT_EQ(IncognitoModePrefs::DISABLED,
IncognitoModePrefs::GetAvailability(&prefs_));
prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
Value::CreateIntegerValue(IncognitoModePrefs::FORCED));
EXPECT_EQ(IncognitoModePrefs::FORCED,
IncognitoModePrefs::GetAvailability(&prefs_));
}
typedef IncognitoModePrefsTest IncognitoModePrefsDeathTest;
// Takes too long to execute on Mac. http://crbug.com/101109
#if defined(OS_MACOSX)
#define MAYBE_GetAvailabilityBadValue DISABLED_GetAvailabilityBadValue
#else
#define MAYBE_GetAvailabilityBadValue GetAvailabilityBadValue
#endif
#if GTEST_HAS_DEATH_TEST
TEST_F(IncognitoModePrefsDeathTest, MAYBE_GetAvailabilityBadValue) {
prefs_.SetUserPref(prefs::kIncognitoModeAvailability,
Value::CreateIntegerValue(-1));
#if defined(NDEBUG) && defined(DCHECK_ALWAYS_ON)
EXPECT_DEATH({
IncognitoModePrefs::Availability availability =
IncognitoModePrefs::GetAvailability(&prefs_);
EXPECT_EQ(IncognitoModePrefs::ENABLED, availability);
}, "");
#else
EXPECT_DEBUG_DEATH({
IncognitoModePrefs::Availability availability =
IncognitoModePrefs::GetAvailability(&prefs_);
EXPECT_EQ(IncognitoModePrefs::ENABLED, availability);
}, "");
#endif
}
#endif // GTEST_HAS_DEATH_TEST
|