OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include <queue> | |
6 #include <utility> | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/memory/linked_ptr.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/run_loop.h" | |
12 #include "base/test/scoped_path_override.h" | |
13 #include "base/values.h" | |
14 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | |
15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" | |
16 #include "chrome/browser/chromeos/settings/device_settings_provider.h" | |
17 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | |
18 #include "chrome/common/chrome_paths.h" | |
19 #include "chrome/test/base/scoped_testing_local_state.h" | |
20 #include "chrome/test/base/testing_browser_process.h" | |
21 #include "chrome/test/base/testing_profile.h" | |
22 #include "chromeos/settings/cros_settings_names.h" | |
23 #include "testing/gtest/include/gtest/gtest.h" | |
24 | |
25 namespace chromeos { | |
26 | |
27 namespace { | |
28 | |
29 void OnPrefChanged(const std::string& /* setting */) { | |
30 } | |
31 | |
32 class PrefsChecker : public ownership::OwnerSettingsService::Observer { | |
33 public: | |
34 PrefsChecker(OwnerSettingsServiceChromeOS* service, | |
35 DeviceSettingsProvider* provider) | |
36 : service_(service), provider_(provider) { | |
37 CHECK(service_); | |
38 CHECK(provider_); | |
39 service_->AddObserver(this); | |
40 } | |
41 | |
42 virtual ~PrefsChecker() { service_->RemoveObserver(this); } | |
43 | |
44 // OwnerSettingsService::Observer implementation: | |
45 virtual void OnSignedPolicyStored(bool success) override { | |
46 CHECK(success); | |
47 | |
48 if (service_->has_pending_changes()) | |
49 return; | |
50 | |
51 while (!set_requests_.empty()) { | |
52 SetRequest request = set_requests_.front(); | |
53 set_requests_.pop(); | |
54 const base::Value* value = provider_->Get(request.first); | |
55 CHECK(request.second->Equals(value)) | |
Mattias Nissler (ping if slow)
2014/10/24 08:29:56
Why not ASSERT_EQ?
ygorshenin1
2014/10/24 10:33:01
I'm not sure that operator==() behaves properly on
Mattias Nissler (ping if slow)
2014/10/24 10:48:12
Sorry, I meant ASSERT_TRUE().
ygorshenin1
2014/10/24 12:10:00
Done.
| |
56 << "Incorrect value for setting: " << request.first; | |
57 } | |
58 loop_.Quit(); | |
59 } | |
60 | |
61 void Set(const std::string& setting, const base::Value& value) { | |
62 service_->Set(setting, value); | |
63 set_requests_.push( | |
64 SetRequest(setting, linked_ptr<base::Value>(value.DeepCopy()))); | |
65 } | |
66 | |
67 void Wait() { loop_.Run(); } | |
68 | |
69 private: | |
70 OwnerSettingsServiceChromeOS* service_; | |
71 DeviceSettingsProvider* provider_; | |
72 base::RunLoop loop_; | |
73 | |
74 typedef std::pair<std::string, linked_ptr<base::Value>> SetRequest; | |
75 std::queue<SetRequest> set_requests_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(PrefsChecker); | |
78 }; | |
79 | |
80 } // namespace | |
81 | |
82 class OwnerSettingsServiceChromeOSTest : public DeviceSettingsTestBase { | |
83 public: | |
84 OwnerSettingsServiceChromeOSTest() | |
85 : local_state_(TestingBrowserProcess::GetGlobal()), | |
86 user_data_dir_override_(chrome::DIR_USER_DATA) {} | |
87 | |
88 virtual void SetUp() override { | |
89 DeviceSettingsTestBase::SetUp(); | |
90 provider_.reset(new DeviceSettingsProvider(base::Bind(&OnPrefChanged), | |
91 &device_settings_service_)); | |
92 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); | |
93 InitOwner(device_policy_.policy_data().username(), true); | |
94 FlushDeviceSettings(); | |
95 } | |
96 | |
97 virtual void TearDown() override { DeviceSettingsTestBase::TearDown(); } | |
98 | |
99 void TestSingleSet(OwnerSettingsServiceChromeOS* service, | |
100 const std::string& setting, | |
101 const base::Value& in_value) { | |
102 PrefsChecker checker(service, provider_.get()); | |
103 checker.Set(setting, in_value); | |
104 FlushDeviceSettings(); | |
105 checker.Wait(); | |
106 } | |
107 | |
108 ScopedTestingLocalState local_state_; | |
109 scoped_ptr<DeviceSettingsProvider> provider_; | |
110 base::ScopedPathOverride user_data_dir_override_; | |
111 | |
112 private: | |
113 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOSTest); | |
114 }; | |
115 | |
116 TEST_F(OwnerSettingsServiceChromeOSTest, SingleSetTest) { | |
117 OwnerSettingsServiceChromeOS* service = | |
118 OwnerSettingsServiceChromeOSFactory::GetForProfile(profile_.get()); | |
119 ASSERT_TRUE(service); | |
120 ASSERT_TRUE(service->IsOwner()); | |
121 TestSingleSet(service, kReleaseChannel, base::StringValue("dev-channel")); | |
122 TestSingleSet(service, kReleaseChannel, base::StringValue("beta-channel")); | |
123 TestSingleSet(service, kReleaseChannel, base::StringValue("stable-channel")); | |
124 } | |
125 | |
126 TEST_F(OwnerSettingsServiceChromeOSTest, MultipleSetTest) { | |
127 OwnerSettingsServiceChromeOS* service = | |
128 OwnerSettingsServiceChromeOSFactory::GetForProfile(profile_.get()); | |
129 ASSERT_TRUE(service); | |
130 ASSERT_TRUE(service->IsOwner()); | |
131 base::FundamentalValue allow_guest(false); | |
132 base::StringValue release_channel("stable-channel"); | |
133 base::FundamentalValue show_user_names(true); | |
134 | |
135 PrefsChecker checker(service, provider_.get()); | |
136 | |
137 checker.Set(kAccountsPrefAllowGuest, allow_guest); | |
138 checker.Set(kReleaseChannel, release_channel); | |
139 checker.Set(kAccountsPrefShowUserNamesOnSignIn, show_user_names); | |
140 | |
141 FlushDeviceSettings(); | |
142 checker.Wait(); | |
143 } | |
144 | |
145 } // namespace chromeos | |
OLD | NEW |