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

Side by Side Diff: chrome/browser/chromeos/ownership/owner_settings_service_chromeos_unittest.cc

Issue 985093002: Fix up Owner settings on first load (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: modify protobuf directly Created 5 years, 9 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <queue> 5 #include <queue>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/linked_ptr.h" 9 #include "base/memory/linked_ptr.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 PrefsChecker checker(service, provider_.get()); 116 PrefsChecker checker(service, provider_.get());
117 checker.Set(setting, in_value); 117 checker.Set(setting, in_value);
118 FlushDeviceSettings(); 118 FlushDeviceSettings();
119 checker.Wait(); 119 checker.Wait();
120 } 120 }
121 121
122 void OnManagementSettingsSet(bool success) { 122 void OnManagementSettingsSet(bool success) {
123 management_settings_set_ = success; 123 management_settings_set_ = success;
124 } 124 }
125 125
126 protected:
126 OwnerSettingsServiceChromeOS* service_; 127 OwnerSettingsServiceChromeOS* service_;
127 ScopedTestingLocalState local_state_; 128 ScopedTestingLocalState local_state_;
128 scoped_ptr<DeviceSettingsProvider> provider_; 129 scoped_ptr<DeviceSettingsProvider> provider_;
129 base::ScopedPathOverride user_data_dir_override_; 130 base::ScopedPathOverride user_data_dir_override_;
130 bool management_settings_set_; 131 bool management_settings_set_;
131 132
132 private: 133 private:
133 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOSTest); 134 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOSTest);
134 }; 135 };
135 136
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // Check that the loaded policy_data contains the expected values. 288 // Check that the loaded policy_data contains the expected values.
288 const em::PolicyData* policy_data = device_settings_service_.policy_data(); 289 const em::PolicyData* policy_data = device_settings_service_.policy_data();
289 EXPECT_EQ(policy::dm_protocol::kChromeDevicePolicyType, 290 EXPECT_EQ(policy::dm_protocol::kChromeDevicePolicyType,
290 policy_data->policy_type()); 291 policy_data->policy_type());
291 EXPECT_EQ(device_settings_service_.GetUsername(), policy_data->username()); 292 EXPECT_EQ(device_settings_service_.GetUsername(), policy_data->username());
292 EXPECT_EQ(em::PolicyData::CONSUMER_MANAGED, policy_data->management_mode()); 293 EXPECT_EQ(em::PolicyData::CONSUMER_MANAGED, policy_data->management_mode());
293 EXPECT_EQ("fake_request_token", policy_data->request_token()); 294 EXPECT_EQ("fake_request_token", policy_data->request_token());
294 EXPECT_EQ("fake_device_id", policy_data->device_id()); 295 EXPECT_EQ("fake_device_id", policy_data->device_id());
295 } 296 }
296 297
298 namespace {
299 bool FindInListValue(const std::string& needle, const base::Value* haystack) {
Mattias Nissler (ping if slow) 2015/03/18 08:36:42 int: We'd usually put these helpers in the anonymo
Chris Masone 2015/03/24 20:53:37 Done.
300 const base::ListValue* list;
301 if (!haystack->GetAsList(&list))
302 return false;
303 return list->end() != list->Find(base::StringValue(needle));
304 }
305 } // namespace
306
307 TEST_F(OwnerSettingsServiceChromeOSTest, ForceWhitelist) {
308 EXPECT_FALSE(FindInListValue(device_policy_.policy_data().username(),
309 provider_->Get(kAccountsPrefUsers)));
310 // Force a settings write.
311 TestSingleSet(service_, kReleaseChannel, base::StringValue("dev-channel"));
312 EXPECT_TRUE(FindInListValue(device_policy_.policy_data().username(),
313 provider_->Get(kAccountsPrefUsers)));
314 }
Mattias Nissler (ping if slow) 2015/03/18 08:36:42 Would be good to have an additional test case that
Chris Masone 2015/03/20 19:13:11 ANy pointers on how to drive that transition in a
Mattias Nissler (ping if slow) 2015/03/24 12:03:11 OwnerSettingsServiceChromeOSTest::Setup() above ca
315
297 class OwnerSettingsServiceChromeOSNoOwnerTest 316 class OwnerSettingsServiceChromeOSNoOwnerTest
298 : public OwnerSettingsServiceChromeOSTest { 317 : public OwnerSettingsServiceChromeOSTest {
299 public: 318 public:
300 OwnerSettingsServiceChromeOSNoOwnerTest() {} 319 OwnerSettingsServiceChromeOSNoOwnerTest() {}
301 ~OwnerSettingsServiceChromeOSNoOwnerTest() override {} 320 ~OwnerSettingsServiceChromeOSNoOwnerTest() override {}
302 321
303 void SetUp() override { 322 void SetUp() override {
304 DeviceSettingsTestBase::SetUp(); 323 DeviceSettingsTestBase::SetUp();
305 provider_.reset(new DeviceSettingsProvider(base::Bind(&OnPrefChanged), 324 provider_.reset(new DeviceSettingsProvider(base::Bind(&OnPrefChanged),
306 &device_settings_service_)); 325 &device_settings_service_));
307 FlushDeviceSettings(); 326 FlushDeviceSettings();
308 service_ = OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( 327 service_ = OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(
309 profile_.get()); 328 profile_.get());
310 ASSERT_TRUE(service_); 329 ASSERT_TRUE(service_);
311 ASSERT_FALSE(service_->IsOwner()); 330 ASSERT_FALSE(service_->IsOwner());
312 } 331 }
313 332
314 void TearDown() override { DeviceSettingsTestBase::TearDown(); } 333 void TearDown() override { DeviceSettingsTestBase::TearDown(); }
315 334
316 private: 335 private:
317 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOSNoOwnerTest); 336 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOSNoOwnerTest);
318 }; 337 };
319 338
320 TEST_F(OwnerSettingsServiceChromeOSNoOwnerTest, SingleSetTest) { 339 TEST_F(OwnerSettingsServiceChromeOSNoOwnerTest, SingleSetTest) {
321 ASSERT_FALSE(service_->SetBoolean(kAccountsPrefAllowGuest, false)); 340 ASSERT_FALSE(service_->SetBoolean(kAccountsPrefAllowGuest, false));
322 } 341 }
323 342
324 } // namespace chromeos 343 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698