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 "base/base_paths.h" | 5 #include "base/base_paths.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "content/public/test/test_utils.h" | 30 #include "content/public/test/test_utils.h" |
31 #include "googleurl/src/gurl.h" | 31 #include "googleurl/src/gurl.h" |
32 #include "net/test/test_server.h" | 32 #include "net/test/test_server.h" |
33 #include "policy/policy_constants.h" | 33 #include "policy/policy_constants.h" |
34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
36 | 36 |
37 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
38 #include "chrome/browser/chromeos/login/user_manager.h" | 38 #include "chrome/browser/chromeos/login/user_manager.h" |
39 #include "chrome/browser/policy/user_cloud_policy_manager_chromeos.h" | 39 #include "chrome/browser/policy/user_cloud_policy_manager_chromeos.h" |
40 #include "chromeos/dbus/mock_cryptohome_client.h" | |
41 #include "chromeos/dbus/mock_dbus_thread_manager.h" | |
42 #include "chromeos/dbus/mock_session_manager_client.h" | |
40 #else | 43 #else |
41 #include "chrome/browser/policy/user_cloud_policy_manager.h" | 44 #include "chrome/browser/policy/user_cloud_policy_manager.h" |
42 #include "chrome/browser/policy/user_cloud_policy_manager_factory.h" | 45 #include "chrome/browser/policy/user_cloud_policy_manager_factory.h" |
43 #include "chrome/browser/signin/signin_manager.h" | 46 #include "chrome/browser/signin/signin_manager.h" |
44 #include "chrome/browser/signin/signin_manager_factory.h" | 47 #include "chrome/browser/signin/signin_manager_factory.h" |
45 #endif | 48 #endif |
46 | 49 |
50 using testing::AnyNumber; | |
47 using testing::InvokeWithoutArgs; | 51 using testing::InvokeWithoutArgs; |
48 using testing::Mock; | 52 using testing::Mock; |
49 using testing::_; | 53 using testing::_; |
50 | 54 |
51 namespace em = enterprise_management; | 55 namespace em = enterprise_management; |
52 | 56 |
53 namespace policy { | 57 namespace policy { |
54 | 58 |
55 namespace { | 59 namespace { |
56 | 60 |
57 class MockCloudPolicyClientObserver : public CloudPolicyClient::Observer { | 61 class MockCloudPolicyClientObserver : public CloudPolicyClient::Observer { |
58 public: | 62 public: |
59 MockCloudPolicyClientObserver() {} | 63 MockCloudPolicyClientObserver() {} |
60 virtual ~MockCloudPolicyClientObserver() {} | 64 virtual ~MockCloudPolicyClientObserver() {} |
61 | 65 |
62 MOCK_METHOD1(OnPolicyFetched, void(CloudPolicyClient*)); | 66 MOCK_METHOD1(OnPolicyFetched, void(CloudPolicyClient*)); |
63 MOCK_METHOD1(OnRegistrationStateChanged, void(CloudPolicyClient*)); | 67 MOCK_METHOD1(OnRegistrationStateChanged, void(CloudPolicyClient*)); |
64 MOCK_METHOD1(OnClientError, void(CloudPolicyClient*)); | 68 MOCK_METHOD1(OnClientError, void(CloudPolicyClient*)); |
65 }; | 69 }; |
66 | 70 |
71 #if defined(OS_CHROMEOS) | |
72 | |
73 const char kSanitizedUsername[] = "0123456789ABCDEF0123456789ABCDEF01234567"; | |
74 | |
75 ACTION(GetSanitizedUsername) { | |
76 MessageLoop::current()->PostTask( | |
77 FROM_HERE, | |
78 base::Bind(arg1, chromeos::DBUS_METHOD_CALL_SUCCESS, kSanitizedUsername)); | |
79 } | |
80 | |
81 ACTION_P(RetrieveUserPolicy, storage) { | |
82 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(arg0, *storage)); | |
83 } | |
84 | |
85 ACTION_P2(StoreUserPolicy, storage, user_policy_key_file) { | |
86 // The session_manager stores a copy of the policy key at | |
87 // /var/run/user_policy/$hash/policy.pub. Simulate that behavior here, so | |
88 // that the policy signature can be validated. | |
89 em::PolicyFetchResponse policy; | |
90 ASSERT_TRUE(policy.ParseFromString(arg0)); | |
91 if (policy.has_new_public_key()) { | |
92 ASSERT_TRUE(file_util::CreateDirectory(user_policy_key_file.DirName())); | |
93 int result = file_util::WriteFile( | |
94 user_policy_key_file, | |
95 policy.new_public_key().data(), | |
96 policy.new_public_key().size()); | |
97 ASSERT_EQ(static_cast<int>(policy.new_public_key().size()), result); | |
98 } | |
99 | |
100 *storage = arg0; | |
101 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(arg1, true)); | |
102 } | |
103 | |
104 #endif | |
105 | |
67 const char* GetTestUser() { | 106 const char* GetTestUser() { |
68 #if defined(OS_CHROMEOS) | 107 #if defined(OS_CHROMEOS) |
69 return chromeos::UserManager::kStubUser; | 108 return chromeos::UserManager::kStubUser; |
70 #else | 109 #else |
71 return "user@example.com"; | 110 return "user@example.com"; |
72 #endif | 111 #endif |
73 } | 112 } |
74 | 113 |
75 std::string GetEmptyPolicy() { | 114 std::string GetEmptyPolicy() { |
76 const char kEmptyPolicy[] = | 115 const char kEmptyPolicy[] = |
77 "{" | 116 "{" |
78 " \"%s\": {" | 117 " \"%s\": {" |
79 " \"mandatory\": {}," | 118 " \"mandatory\": {}," |
80 " \"recommended\": {}" | 119 " \"recommended\": {}" |
81 " }," | 120 " }," |
82 " \"managed_users\": [ \"*\" ]," | 121 " \"managed_users\": [ \"*\" ]," |
83 " \"policy_user\": \"%s\"" | 122 " \"policy_user\": \"%s\"," |
123 " \"current_key_index\": 0" | |
84 "}"; | 124 "}"; |
85 | 125 |
86 return base::StringPrintf(kEmptyPolicy, dm_protocol::kChromeUserPolicyType, | 126 return base::StringPrintf( |
87 GetTestUser()); | 127 kEmptyPolicy, dm_protocol::kChromeUserPolicyType, GetTestUser()); |
88 } | 128 } |
89 | 129 |
90 std::string GetTestPolicy() { | 130 std::string GetTestPolicy(int key_version) { |
91 const char kTestPolicy[] = | 131 const char kTestPolicy[] = |
92 "{" | 132 "{" |
93 " \"%s\": {" | 133 " \"%s\": {" |
94 " \"mandatory\": {" | 134 " \"mandatory\": {" |
95 " \"ShowHomeButton\": true," | 135 " \"ShowHomeButton\": true," |
96 " \"MaxConnectionsPerProxy\": 42," | 136 " \"MaxConnectionsPerProxy\": 42," |
97 " \"URLBlacklist\": [ \"dev.chromium.org\", \"youtube.com\" ]" | 137 " \"URLBlacklist\": [ \"dev.chromium.org\", \"youtube.com\" ]" |
98 " }," | 138 " }," |
99 " \"recommended\": {" | 139 " \"recommended\": {" |
100 " \"HomepageLocation\": \"google.com\"" | 140 " \"HomepageLocation\": \"google.com\"" |
101 " }" | 141 " }" |
102 " }," | 142 " }," |
103 " \"managed_users\": [ \"*\" ]," | 143 " \"managed_users\": [ \"*\" ]," |
104 " \"policy_user\": \"%s\"" | 144 " \"policy_user\": \"%s\"," |
145 " \"current_key_index\": %d" | |
105 "}"; | 146 "}"; |
106 | 147 |
107 return base::StringPrintf(kTestPolicy, dm_protocol::kChromeUserPolicyType, | 148 return base::StringPrintf(kTestPolicy, |
108 GetTestUser()); | 149 dm_protocol::kChromeUserPolicyType, |
150 GetTestUser(), | |
151 key_version); | |
152 } | |
153 | |
154 void GetExpectedTestPolicy(PolicyMap* expected) { | |
155 expected->Set(key::kShowHomeButton, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | |
156 base::Value::CreateBooleanValue(true)); | |
157 expected->Set(key::kMaxConnectionsPerProxy, POLICY_LEVEL_MANDATORY, | |
158 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(42)); | |
159 base::ListValue list; | |
160 list.AppendString("dev.chromium.org"); | |
161 list.AppendString("youtube.com"); | |
162 expected->Set( | |
163 key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | |
164 list.DeepCopy()); | |
165 expected->Set( | |
166 key::kHomepageLocation, POLICY_LEVEL_RECOMMENDED, | |
167 POLICY_SCOPE_USER, base::Value::CreateStringValue("google.com")); | |
109 } | 168 } |
110 | 169 |
111 } // namespace | 170 } // namespace |
112 | 171 |
113 // Tests the cloud policy stack(s). | 172 // Tests the cloud policy stack(s). |
114 class CloudPolicyTest : public InProcessBrowserTest { | 173 class CloudPolicyTest : public InProcessBrowserTest { |
115 protected: | 174 protected: |
116 CloudPolicyTest() {} | 175 CloudPolicyTest() {} |
117 virtual ~CloudPolicyTest() {} | 176 virtual ~CloudPolicyTest() {} |
118 | 177 |
119 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 178 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
120 // The TestServer wants the docroot as a path relative to the source dir. | 179 // The TestServer wants the docroot as a path relative to the source dir. |
121 FilePath source; | 180 FilePath source; |
122 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source)); | 181 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source)); |
123 ASSERT_TRUE(temp_dir_.CreateUniqueTempDirUnderPath(source)); | 182 ASSERT_TRUE(temp_dir_.CreateUniqueTempDirUnderPath(source)); |
124 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetEmptyPolicy())); | 183 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetEmptyPolicy())); |
125 | 184 |
126 test_server_.reset( | 185 test_server_.reset( |
127 new net::TestServer( | 186 new net::TestServer( |
128 net::TestServer::TYPE_HTTP, | 187 net::TestServer::TYPE_HTTP, |
129 net::TestServer::kLocalhost, | 188 net::TestServer::kLocalhost, |
130 temp_dir_.path().BaseName())); | 189 testserver_relative_docroot())); |
Mattias Nissler (ping if slow)
2013/02/07 14:12:07
any reason not to use an absolute path here?
Joao da Silva
2013/02/07 16:32:00
Yes, see comment in line 179.
Mattias Nissler (ping if slow)
2013/02/08 13:36:42
I don't think it's OK to write to the source dir t
Joao da Silva
2013/02/08 16:47:04
Yea, if the test crashes then it leaves a scoped_t
| |
131 ASSERT_TRUE(test_server_->Start()); | 190 ASSERT_TRUE(test_server_->Start()); |
132 | 191 |
133 std::string url = test_server_->GetURL("device_management").spec(); | 192 std::string url = test_server_->GetURL("device_management").spec(); |
134 | 193 |
135 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 194 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
136 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url); | 195 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url); |
196 | |
197 root_path_ = root_path().value(); | |
198 BrowserPolicyConnector::SetRootPathForTesting(root_path_.c_str()); | |
199 | |
200 #if defined(OS_CHROMEOS) | |
201 mock_dbus_thread_manager_ = new chromeos::MockDBusThreadManager(); | |
202 chromeos::DBusThreadManager::InitializeForTesting( | |
203 mock_dbus_thread_manager_); | |
204 EXPECT_CALL(*mock_dbus_thread_manager_->mock_cryptohome_client(), | |
205 GetSanitizedUsername(_, _)) | |
206 .WillRepeatedly(GetSanitizedUsername()); | |
207 EXPECT_CALL(*mock_dbus_thread_manager_->mock_session_manager_client(), | |
208 StoreUserPolicy(_, _)) | |
209 .WillRepeatedly(StoreUserPolicy(&session_manager_user_policy_, | |
210 user_policy_key_file())); | |
211 EXPECT_CALL(*mock_dbus_thread_manager_->mock_session_manager_client(), | |
212 RetrieveUserPolicy(_)) | |
213 .WillRepeatedly(RetrieveUserPolicy(&session_manager_user_policy_)); | |
214 #endif | |
137 } | 215 } |
138 | 216 |
139 virtual void SetUpOnMainThread() OVERRIDE { | 217 virtual void SetUpOnMainThread() OVERRIDE { |
140 // Checks that no policies have been loaded by the other providers before | 218 // Checks that no policies have been loaded by the other providers before |
141 // setting up the cloud connection. Other policies configured in the test | 219 // setting up the cloud connection. Other policies configured in the test |
142 // machine will interfere with these tests. | 220 // machine will interfere with these tests. |
143 const PolicyMap& map = g_browser_process->policy_service()->GetPolicies( | 221 const PolicyMap& map = g_browser_process->policy_service()->GetPolicies( |
144 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 222 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
145 if (!map.empty()) { | 223 if (!map.empty()) { |
146 base::DictionaryValue dict; | 224 base::DictionaryValue dict; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 policy_manager->core()->client()->AddObserver(&observer); | 260 policy_manager->core()->client()->AddObserver(&observer); |
183 | 261 |
184 // Give a bogus OAuth token to the |policy_manager|. This should make its | 262 // Give a bogus OAuth token to the |policy_manager|. This should make its |
185 // CloudPolicyClient fetch the DMToken. | 263 // CloudPolicyClient fetch the DMToken. |
186 policy_manager->RegisterClient("bogus"); | 264 policy_manager->RegisterClient("bogus"); |
187 run_loop.Run(); | 265 run_loop.Run(); |
188 Mock::VerifyAndClearExpectations(&observer); | 266 Mock::VerifyAndClearExpectations(&observer); |
189 policy_manager->core()->client()->RemoveObserver(&observer); | 267 policy_manager->core()->client()->RemoveObserver(&observer); |
190 } | 268 } |
191 | 269 |
270 FilePath testserver_docroot() { | |
271 return temp_dir_.path().AppendASCII("testserver"); | |
Mattias Nissler (ping if slow)
2013/02/07 14:12:07
inline into testserver_device_management_file?
Joao da Silva
2013/02/07 16:32:00
Done.
| |
272 } | |
273 | |
274 FilePath testserver_relative_docroot() { | |
275 return temp_dir_.path().BaseName().AppendASCII("testserver"); | |
276 } | |
277 | |
278 FilePath testserver_device_management_file() { | |
279 return testserver_docroot().AppendASCII("device_management"); | |
280 } | |
281 | |
282 FilePath root_path() { | |
Mattias Nissler (ping if slow)
2013/02/07 14:12:07
you probably want to rename this if you switch to
Joao da Silva
2013/02/07 16:32:00
Done.
| |
283 return temp_dir_.path().AppendASCII("root"); | |
284 } | |
285 | |
286 #if defined(OS_CHROMEOS) | |
287 FilePath user_policy_key_file() { | |
288 return root_path().AppendASCII("var/run/user_policy") | |
289 .AppendASCII(kSanitizedUsername) | |
290 .AppendASCII("policy.pub"); | |
291 } | |
292 #endif | |
293 | |
192 void SetServerPolicy(const std::string& policy) { | 294 void SetServerPolicy(const std::string& policy) { |
295 ASSERT_TRUE(file_util::CreateDirectory( | |
296 testserver_device_management_file().DirName())); | |
193 int result = file_util::WriteFile( | 297 int result = file_util::WriteFile( |
194 temp_dir_.path().AppendASCII("device_management"), | 298 testserver_device_management_file(), policy.data(), policy.size()); |
195 policy.data(), policy.size()); | |
196 ASSERT_EQ(static_cast<int>(policy.size()), result); | 299 ASSERT_EQ(static_cast<int>(policy.size()), result); |
197 } | 300 } |
198 | 301 |
302 FilePath::StringType root_path_; | |
Mattias Nissler (ping if slow)
2013/02/07 14:12:07
needed?
Joao da Silva
2013/02/07 16:32:00
Done.
| |
199 base::ScopedTempDir temp_dir_; | 303 base::ScopedTempDir temp_dir_; |
200 scoped_ptr<net::TestServer> test_server_; | 304 scoped_ptr<net::TestServer> test_server_; |
305 | |
306 #if defined(OS_CHROMEOS) | |
307 std::string session_manager_user_policy_; | |
308 chromeos::MockDBusThreadManager* mock_dbus_thread_manager_; | |
309 #endif | |
201 }; | 310 }; |
202 | 311 |
203 IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicy) { | 312 IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicy) { |
204 PolicyService* policy_service = browser()->profile()->GetPolicyService(); | 313 PolicyService* policy_service = browser()->profile()->GetPolicyService(); |
205 { | 314 { |
206 base::RunLoop run_loop; | 315 base::RunLoop run_loop; |
316 // This does the initial fetch and stores the initial key. | |
207 policy_service->RefreshPolicies(run_loop.QuitClosure()); | 317 policy_service->RefreshPolicies(run_loop.QuitClosure()); |
208 run_loop.Run(); | 318 run_loop.Run(); |
209 } | 319 } |
210 | 320 |
211 PolicyMap empty; | 321 PolicyMap empty; |
212 EXPECT_TRUE(empty.Equals(policy_service->GetPolicies( | 322 EXPECT_TRUE(empty.Equals(policy_service->GetPolicies( |
213 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); | 323 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); |
214 | 324 |
215 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy())); | 325 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy(0))); |
216 PolicyMap expected; | 326 PolicyMap expected; |
217 expected.Set(key::kShowHomeButton, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 327 GetExpectedTestPolicy(&expected); |
218 base::Value::CreateBooleanValue(true)); | |
219 expected.Set(key::kMaxConnectionsPerProxy, POLICY_LEVEL_MANDATORY, | |
220 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(42)); | |
221 base::ListValue list; | |
222 list.AppendString("dev.chromium.org"); | |
223 list.AppendString("youtube.com"); | |
224 expected.Set( | |
225 key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | |
226 list.DeepCopy()); | |
227 expected.Set( | |
228 key::kHomepageLocation, POLICY_LEVEL_RECOMMENDED, | |
229 POLICY_SCOPE_USER, base::Value::CreateStringValue("google.com")); | |
230 { | 328 { |
231 base::RunLoop run_loop; | 329 base::RunLoop run_loop; |
330 // This fetches the new policies, using the same key. | |
232 policy_service->RefreshPolicies(run_loop.QuitClosure()); | 331 policy_service->RefreshPolicies(run_loop.QuitClosure()); |
233 run_loop.Run(); | 332 run_loop.Run(); |
234 } | 333 } |
235 EXPECT_TRUE(expected.Equals(policy_service->GetPolicies( | 334 EXPECT_TRUE(expected.Equals(policy_service->GetPolicies( |
236 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); | 335 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); |
237 } | 336 } |
238 | 337 |
338 #if defined(OS_CHROMEOS) | |
Mattias Nissler (ping if slow)
2013/02/07 14:12:07
It seems like everything that's really chromeos-sp
Joao da Silva
2013/02/07 16:32:00
They're mocked at the session_manager mock, which
| |
339 IN_PROC_BROWSER_TEST_F(CloudPolicyTest, FetchPolicyWithRotatedKey) { | |
340 PolicyService* policy_service = browser()->profile()->GetPolicyService(); | |
341 { | |
342 base::RunLoop run_loop; | |
343 // This does the initial fetch and stores the initial key. | |
344 policy_service->RefreshPolicies(run_loop.QuitClosure()); | |
345 run_loop.Run(); | |
346 } | |
347 | |
348 // Read the initial key. | |
349 std::string initial_key; | |
350 ASSERT_TRUE( | |
351 file_util::ReadFileToString(user_policy_key_file(), &initial_key)); | |
352 | |
353 PolicyMap empty; | |
354 EXPECT_TRUE(empty.Equals(policy_service->GetPolicies( | |
355 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); | |
356 | |
357 // Set the new policies and a new key at the server. | |
358 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy(1))); | |
359 PolicyMap expected; | |
360 GetExpectedTestPolicy(&expected); | |
361 { | |
362 base::RunLoop run_loop; | |
363 // This fetches the new policies and does a key rotation. | |
364 policy_service->RefreshPolicies(run_loop.QuitClosure()); | |
365 run_loop.Run(); | |
366 } | |
367 EXPECT_TRUE(expected.Equals(policy_service->GetPolicies( | |
368 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); | |
369 | |
370 // Verify that the key was rotated. | |
371 std::string rotated_key; | |
372 ASSERT_TRUE( | |
373 file_util::ReadFileToString(user_policy_key_file(), &rotated_key)); | |
374 EXPECT_NE(rotated_key, initial_key); | |
375 | |
376 // Another refresh using the same key won't rotate it again. | |
377 { | |
378 base::RunLoop run_loop; | |
379 policy_service->RefreshPolicies(run_loop.QuitClosure()); | |
380 run_loop.Run(); | |
381 } | |
382 EXPECT_TRUE(expected.Equals(policy_service->GetPolicies( | |
383 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); | |
384 std::string current_key; | |
385 ASSERT_TRUE( | |
386 file_util::ReadFileToString(user_policy_key_file(), ¤t_key)); | |
387 EXPECT_EQ(rotated_key, current_key); | |
388 } | |
389 #endif | |
390 | |
239 TEST(CloudPolicyProtoTest, VerifyProtobufEquivalence) { | 391 TEST(CloudPolicyProtoTest, VerifyProtobufEquivalence) { |
240 // There are 2 protobufs that can be used for user cloud policy: | 392 // There are 2 protobufs that can be used for user cloud policy: |
241 // cloud_policy.proto and chrome_settings.proto. chrome_settings.proto is the | 393 // cloud_policy.proto and chrome_settings.proto. chrome_settings.proto is the |
242 // version used by the server, but generates one proto message per policy; to | 394 // version used by the server, but generates one proto message per policy; to |
243 // save binary size on the client, the other version shares proto messages for | 395 // save binary size on the client, the other version shares proto messages for |
244 // policies of the same type. They generate the same bytes on the wire though, | 396 // policies of the same type. They generate the same bytes on the wire though, |
245 // so they are compatible. This test verifies that that stays true. | 397 // so they are compatible. This test verifies that that stays true. |
246 | 398 |
247 // Build a ChromeSettingsProto message with one policy of each supported type. | 399 // Build a ChromeSettingsProto message with one policy of each supported type. |
248 em::ChromeSettingsProto chrome_settings; | 400 em::ChromeSettingsProto chrome_settings; |
(...skipping 30 matching lines...) Expand all Loading... | |
279 | 431 |
280 // They should now serialize to the same bytes. | 432 // They should now serialize to the same bytes. |
281 std::string chrome_settings_serialized; | 433 std::string chrome_settings_serialized; |
282 std::string cloud_policy_serialized; | 434 std::string cloud_policy_serialized; |
283 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); | 435 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); |
284 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); | 436 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); |
285 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); | 437 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); |
286 } | 438 } |
287 | 439 |
288 } // namespace policy | 440 } // namespace policy |
OLD | NEW |