Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(639)

Side by Side Diff: chrome/browser/managed_mode/supervised_user_pref_store_unittest.cc

Issue 104493005: Update some uses of Value in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/prefs/testing_pref_store.h" 9 #include "base/prefs/testing_pref_store.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/managed_mode/managed_user_constants.h" 11 #include "chrome/browser/managed_mode/managed_user_constants.h"
12 #include "chrome/browser/managed_mode/managed_user_settings_service.h" 12 #include "chrome/browser/managed_mode/managed_user_settings_service.h"
13 #include "chrome/browser/managed_mode/supervised_user_pref_store.h" 13 #include "chrome/browser/managed_mode/supervised_user_pref_store.h"
14 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using base::DictionaryValue; 17 using base::DictionaryValue;
18 using base::Value; 18 using base::Value;
19 19
20 namespace { 20 namespace {
21 21
22 class SupervisedUserPrefStoreFixture : public PrefStore::Observer { 22 class SupervisedUserPrefStoreFixture : public PrefStore::Observer {
23 public: 23 public:
24 explicit SupervisedUserPrefStoreFixture( 24 explicit SupervisedUserPrefStoreFixture(
25 ManagedUserSettingsService* settings_service); 25 ManagedUserSettingsService* settings_service);
26 virtual ~SupervisedUserPrefStoreFixture(); 26 virtual ~SupervisedUserPrefStoreFixture();
27 27
28 DictionaryValue* changed_prefs() { 28 base::DictionaryValue* changed_prefs() {
29 return &changed_prefs_; 29 return &changed_prefs_;
30 } 30 }
31 31
32 bool initialization_completed() const { 32 bool initialization_completed() const {
33 return initialization_completed_; 33 return initialization_completed_;
34 } 34 }
35 35
36 // PrefStore::Observer implementation: 36 // PrefStore::Observer implementation:
37 virtual void OnPrefValueChanged(const std::string& key) OVERRIDE; 37 virtual void OnPrefValueChanged(const std::string& key) OVERRIDE;
38 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE; 38 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE;
39 39
40 private: 40 private:
41 scoped_refptr<SupervisedUserPrefStore> pref_store_; 41 scoped_refptr<SupervisedUserPrefStore> pref_store_;
42 DictionaryValue changed_prefs_; 42 base::DictionaryValue changed_prefs_;
43 bool initialization_completed_; 43 bool initialization_completed_;
44 }; 44 };
45 45
46 SupervisedUserPrefStoreFixture::SupervisedUserPrefStoreFixture( 46 SupervisedUserPrefStoreFixture::SupervisedUserPrefStoreFixture(
47 ManagedUserSettingsService* settings_service) 47 ManagedUserSettingsService* settings_service)
48 : pref_store_(new SupervisedUserPrefStore(settings_service)), 48 : pref_store_(new SupervisedUserPrefStore(settings_service)),
49 initialization_completed_(pref_store_->IsInitializationComplete()) { 49 initialization_completed_(pref_store_->IsInitializationComplete()) {
50 pref_store_->AddObserver(this); 50 pref_store_->AddObserver(this);
51 } 51 }
52 52
53 SupervisedUserPrefStoreFixture::~SupervisedUserPrefStoreFixture() { 53 SupervisedUserPrefStoreFixture::~SupervisedUserPrefStoreFixture() {
54 pref_store_->RemoveObserver(this); 54 pref_store_->RemoveObserver(this);
55 } 55 }
56 56
57 void SupervisedUserPrefStoreFixture::OnPrefValueChanged( 57 void SupervisedUserPrefStoreFixture::OnPrefValueChanged(
58 const std::string& key) { 58 const std::string& key) {
59 const Value* value = NULL; 59 const base::Value* value = NULL;
60 ASSERT_TRUE(pref_store_->GetValue(key, &value)); 60 ASSERT_TRUE(pref_store_->GetValue(key, &value));
61 changed_prefs_.Set(key, value->DeepCopy()); 61 changed_prefs_.Set(key, value->DeepCopy());
62 } 62 }
63 63
64 void SupervisedUserPrefStoreFixture::OnInitializationCompleted(bool succeeded) { 64 void SupervisedUserPrefStoreFixture::OnInitializationCompleted(bool succeeded) {
65 EXPECT_FALSE(initialization_completed_); 65 EXPECT_FALSE(initialization_completed_);
66 EXPECT_TRUE(succeeded); 66 EXPECT_TRUE(succeeded);
67 EXPECT_TRUE(pref_store_->IsInitializationComplete()); 67 EXPECT_TRUE(pref_store_->IsInitializationComplete());
68 initialization_completed_ = true; 68 initialization_completed_ = true;
69 } 69 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 service_.Activate(); 102 service_.Activate();
103 103
104 // kAllowDeletingBrowserHistory is hardcoded to false for managed users. 104 // kAllowDeletingBrowserHistory is hardcoded to false for managed users.
105 bool allow_deleting_browser_history = true; 105 bool allow_deleting_browser_history = true;
106 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean( 106 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(
107 prefs::kAllowDeletingBrowserHistory, &allow_deleting_browser_history)); 107 prefs::kAllowDeletingBrowserHistory, &allow_deleting_browser_history));
108 EXPECT_FALSE(allow_deleting_browser_history); 108 EXPECT_FALSE(allow_deleting_browser_history);
109 109
110 // kManagedModeManualHosts does not have a hardcoded value. 110 // kManagedModeManualHosts does not have a hardcoded value.
111 DictionaryValue* manual_hosts = NULL; 111 base::DictionaryValue* manual_hosts = NULL;
112 EXPECT_FALSE(fixture.changed_prefs()->GetDictionary( 112 EXPECT_FALSE(fixture.changed_prefs()->GetDictionary(
113 prefs::kManagedModeManualHosts, &manual_hosts)); 113 prefs::kManagedModeManualHosts, &manual_hosts));
114 114
115 // kForceSafeSearch defaults to true for managed users. 115 // kForceSafeSearch defaults to true for managed users.
116 bool force_safesearch = false; 116 bool force_safesearch = false;
117 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceSafeSearch, 117 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceSafeSearch,
118 &force_safesearch)); 118 &force_safesearch));
119 EXPECT_TRUE(force_safesearch); 119 EXPECT_TRUE(force_safesearch);
120 120
121 // Activating the service again should not change anything. 121 // Activating the service again should not change anything.
122 fixture.changed_prefs()->Clear(); 122 fixture.changed_prefs()->Clear();
123 service_.Activate(); 123 service_.Activate();
124 EXPECT_EQ(0u, fixture.changed_prefs()->size()); 124 EXPECT_EQ(0u, fixture.changed_prefs()->size());
125 125
126 // kManagedModeManualHosts can be configured by the custodian. 126 // kManagedModeManualHosts can be configured by the custodian.
127 scoped_ptr<DictionaryValue> dict(new DictionaryValue); 127 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
128 dict->SetBoolean("example.com", true); 128 dict->SetBoolean("example.com", true);
129 dict->SetBoolean("moose.org", false); 129 dict->SetBoolean("moose.org", false);
130 service_.SetLocalSettingForTesting( 130 service_.SetLocalSettingForTesting(
131 managed_users::kContentPackManualBehaviorHosts, 131 managed_users::kContentPackManualBehaviorHosts,
132 scoped_ptr<Value>(dict->DeepCopy())); 132 scoped_ptr<base::Value>(dict->DeepCopy()));
133 EXPECT_EQ(1u, fixture.changed_prefs()->size()); 133 EXPECT_EQ(1u, fixture.changed_prefs()->size());
134 ASSERT_TRUE(fixture.changed_prefs()->GetDictionary( 134 ASSERT_TRUE(fixture.changed_prefs()->GetDictionary(
135 prefs::kManagedModeManualHosts, &manual_hosts)); 135 prefs::kManagedModeManualHosts, &manual_hosts));
136 EXPECT_TRUE(manual_hosts->Equals(dict.get())); 136 EXPECT_TRUE(manual_hosts->Equals(dict.get()));
137 137
138 // kForceSafeSearch can be configured by the custodian, overriding the 138 // kForceSafeSearch can be configured by the custodian, overriding the
139 // hardcoded default. 139 // hardcoded default.
140 fixture.changed_prefs()->Clear(); 140 fixture.changed_prefs()->Clear();
141 service_.SetLocalSettingForTesting( 141 service_.SetLocalSettingForTesting(
142 managed_users::kForceSafeSearch, 142 managed_users::kForceSafeSearch,
143 scoped_ptr<Value>(new base::FundamentalValue(false))); 143 scoped_ptr<base::Value>(new base::FundamentalValue(false)));
144 EXPECT_EQ(1u, fixture.changed_prefs()->size()); 144 EXPECT_EQ(1u, fixture.changed_prefs()->size());
145 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceSafeSearch, 145 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceSafeSearch,
146 &force_safesearch)); 146 &force_safesearch));
147 EXPECT_FALSE(force_safesearch); 147 EXPECT_FALSE(force_safesearch);
148 } 148 }
149 149
150 TEST_F(SupervisedUserPrefStoreTest, ActivateSettingsBeforeInitialization) { 150 TEST_F(SupervisedUserPrefStoreTest, ActivateSettingsBeforeInitialization) {
151 SupervisedUserPrefStoreFixture fixture(&service_); 151 SupervisedUserPrefStoreFixture fixture(&service_);
152 EXPECT_FALSE(fixture.initialization_completed()); 152 EXPECT_FALSE(fixture.initialization_completed());
153 153
154 service_.Activate(); 154 service_.Activate();
155 EXPECT_FALSE(fixture.initialization_completed()); 155 EXPECT_FALSE(fixture.initialization_completed());
156 EXPECT_EQ(0u, fixture.changed_prefs()->size()); 156 EXPECT_EQ(0u, fixture.changed_prefs()->size());
157 157
158 pref_store_->SetInitializationCompleted(); 158 pref_store_->SetInitializationCompleted();
159 EXPECT_TRUE(fixture.initialization_completed()); 159 EXPECT_TRUE(fixture.initialization_completed());
160 EXPECT_EQ(0u, fixture.changed_prefs()->size()); 160 EXPECT_EQ(0u, fixture.changed_prefs()->size());
161 } 161 }
162 162
163 TEST_F(SupervisedUserPrefStoreTest, CreatePrefStoreAfterInitialization) { 163 TEST_F(SupervisedUserPrefStoreTest, CreatePrefStoreAfterInitialization) {
164 pref_store_->SetInitializationCompleted(); 164 pref_store_->SetInitializationCompleted();
165 service_.Activate(); 165 service_.Activate();
166 166
167 SupervisedUserPrefStoreFixture fixture(&service_); 167 SupervisedUserPrefStoreFixture fixture(&service_);
168 EXPECT_TRUE(fixture.initialization_completed()); 168 EXPECT_TRUE(fixture.initialization_completed());
169 EXPECT_EQ(0u, fixture.changed_prefs()->size()); 169 EXPECT_EQ(0u, fixture.changed_prefs()->size());
170 } 170 }
171 171
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698