OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/prefs/incognito_mode_prefs.h" | 5 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
7 #include "base/test/gtest_util.h" | 8 #include "base/test/gtest_util.h" |
8 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
9 #include "components/sync_preferences/testing_pref_service_syncable.h" | 10 #include "components/sync_preferences/testing_pref_service_syncable.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 class IncognitoModePrefsTest : public testing::Test { | 13 class IncognitoModePrefsTest : public testing::Test { |
13 protected: | 14 protected: |
14 void SetUp() override { | 15 void SetUp() override { |
15 IncognitoModePrefs::RegisterProfilePrefs(prefs_.registry()); | 16 IncognitoModePrefs::RegisterProfilePrefs(prefs_.registry()); |
16 } | 17 } |
(...skipping 14 matching lines...) Expand all Loading... |
31 EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(2, &incognito)); | 32 EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(2, &incognito)); |
32 EXPECT_EQ(IncognitoModePrefs::FORCED, incognito); | 33 EXPECT_EQ(IncognitoModePrefs::FORCED, incognito); |
33 | 34 |
34 EXPECT_FALSE(IncognitoModePrefs::IntToAvailability(10, &incognito)); | 35 EXPECT_FALSE(IncognitoModePrefs::IntToAvailability(10, &incognito)); |
35 EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito); | 36 EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito); |
36 EXPECT_FALSE(IncognitoModePrefs::IntToAvailability(-1, &incognito)); | 37 EXPECT_FALSE(IncognitoModePrefs::IntToAvailability(-1, &incognito)); |
37 EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito); | 38 EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito); |
38 } | 39 } |
39 | 40 |
40 TEST_F(IncognitoModePrefsTest, GetAvailability) { | 41 TEST_F(IncognitoModePrefsTest, GetAvailability) { |
41 prefs_.SetUserPref(prefs::kIncognitoModeAvailability, | 42 prefs_.SetUserPref( |
42 new base::Value(IncognitoModePrefs::ENABLED)); | 43 prefs::kIncognitoModeAvailability, |
| 44 base::MakeUnique<base::Value>(IncognitoModePrefs::ENABLED)); |
43 EXPECT_EQ(IncognitoModePrefs::ENABLED, | 45 EXPECT_EQ(IncognitoModePrefs::ENABLED, |
44 IncognitoModePrefs::GetAvailability(&prefs_)); | 46 IncognitoModePrefs::GetAvailability(&prefs_)); |
45 | 47 |
46 prefs_.SetUserPref(prefs::kIncognitoModeAvailability, | 48 prefs_.SetUserPref( |
47 new base::Value(IncognitoModePrefs::DISABLED)); | 49 prefs::kIncognitoModeAvailability, |
| 50 base::MakeUnique<base::Value>(IncognitoModePrefs::DISABLED)); |
48 EXPECT_EQ(IncognitoModePrefs::DISABLED, | 51 EXPECT_EQ(IncognitoModePrefs::DISABLED, |
49 IncognitoModePrefs::GetAvailability(&prefs_)); | 52 IncognitoModePrefs::GetAvailability(&prefs_)); |
50 | 53 |
51 prefs_.SetUserPref(prefs::kIncognitoModeAvailability, | 54 prefs_.SetUserPref(prefs::kIncognitoModeAvailability, |
52 new base::Value(IncognitoModePrefs::FORCED)); | 55 base::MakeUnique<base::Value>(IncognitoModePrefs::FORCED)); |
53 EXPECT_EQ(IncognitoModePrefs::FORCED, | 56 EXPECT_EQ(IncognitoModePrefs::FORCED, |
54 IncognitoModePrefs::GetAvailability(&prefs_)); | 57 IncognitoModePrefs::GetAvailability(&prefs_)); |
55 } | 58 } |
56 | 59 |
57 typedef IncognitoModePrefsTest IncognitoModePrefsDeathTest; | 60 typedef IncognitoModePrefsTest IncognitoModePrefsDeathTest; |
58 | 61 |
59 TEST_F(IncognitoModePrefsDeathTest, GetAvailabilityBadValue) { | 62 TEST_F(IncognitoModePrefsDeathTest, GetAvailabilityBadValue) { |
60 prefs_.SetUserPref(prefs::kIncognitoModeAvailability, new base::Value(-1)); | 63 prefs_.SetUserPref(prefs::kIncognitoModeAvailability, |
| 64 base::MakeUnique<base::Value>(-1)); |
61 EXPECT_DCHECK_DEATH({ | 65 EXPECT_DCHECK_DEATH({ |
62 IncognitoModePrefs::Availability availability = | 66 IncognitoModePrefs::Availability availability = |
63 IncognitoModePrefs::GetAvailability(&prefs_); | 67 IncognitoModePrefs::GetAvailability(&prefs_); |
64 EXPECT_EQ(IncognitoModePrefs::ENABLED, availability); | 68 EXPECT_EQ(IncognitoModePrefs::ENABLED, availability); |
65 }); | 69 }); |
66 } | 70 } |
OLD | NEW |