Chromium Code Reviews| 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" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/policy/browser_policy_connector.h" | 14 #include "chrome/browser/policy/browser_policy_connector.h" |
| 15 #include "chrome/browser/policy/cloud_policy_client.h" | 15 #include "chrome/browser/policy/cloud_policy_client.h" |
| 16 #include "chrome/browser/policy/cloud_policy_constants.h" | 16 #include "chrome/browser/policy/cloud_policy_constants.h" |
| 17 #include "chrome/browser/policy/cloud_policy_data_store.h" | |
| 18 #include "chrome/browser/policy/policy_map.h" | 17 #include "chrome/browser/policy/policy_map.h" |
| 19 #include "chrome/browser/policy/policy_service.h" | 18 #include "chrome/browser/policy/policy_service.h" |
| 20 #include "chrome/browser/policy/proto/chrome_settings.pb.h" | 19 #include "chrome/browser/policy/proto/chrome_settings.pb.h" |
| 21 #include "chrome/browser/policy/proto/cloud_policy.pb.h" | 20 #include "chrome/browser/policy/proto/cloud_policy.pb.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 " }" | 101 " }" |
| 103 " }," | 102 " }," |
| 104 " \"managed_users\": [ \"*\" ]," | 103 " \"managed_users\": [ \"*\" ]," |
| 105 " \"policy_user\": \"%s\"" | 104 " \"policy_user\": \"%s\"" |
| 106 "}"; | 105 "}"; |
| 107 | 106 |
| 108 return base::StringPrintf(kTestPolicy, dm_protocol::kChromeUserPolicyType, | 107 return base::StringPrintf(kTestPolicy, dm_protocol::kChromeUserPolicyType, |
| 109 GetTestUser()); | 108 GetTestUser()); |
| 110 } | 109 } |
| 111 | 110 |
| 112 #if defined(OS_CHROMEOS) | |
| 113 void SetUpOldStackBeforeCreatingBrowser() { | |
| 114 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 115 command_line->AppendSwitch(switches::kDisableCloudPolicyService); | |
| 116 } | |
| 117 | |
| 118 void SetUpOldStackAfterCreatingBrowser(Browser* browser) { | |
| 119 // Flush the token cache loading. | |
| 120 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | |
| 121 content::RunAllPendingInMessageLoop(); | |
| 122 // Set a fake gaia token. | |
| 123 BrowserPolicyConnector* connector = | |
| 124 g_browser_process->browser_policy_connector(); | |
| 125 CloudPolicyDataStore* store = connector->GetUserCloudPolicyDataStore(); | |
| 126 ASSERT_TRUE(store); | |
| 127 store->SetupForTesting("", "bogus", GetTestUser(), "bogus", true); | |
| 128 } | |
| 129 #endif | |
| 130 | |
| 131 void SetUpNewStackBeforeCreatingBrowser() { | 111 void SetUpNewStackBeforeCreatingBrowser() { |
| 132 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 112 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 133 command_line->AppendSwitch(switches::kLoadCloudPolicyOnSignin); | 113 command_line->AppendSwitch(switches::kLoadCloudPolicyOnSignin); |
| 134 } | 114 } |
| 135 | 115 |
| 136 void SetUpNewStackAfterCreatingBrowser(Browser* browser) { | 116 void SetUpNewStackAfterCreatingBrowser(Browser* browser) { |
| 137 BrowserPolicyConnector* connector = | 117 BrowserPolicyConnector* connector = |
| 138 g_browser_process->browser_policy_connector(); | 118 g_browser_process->browser_policy_connector(); |
| 139 connector->ScheduleServiceInitialization(0); | 119 connector->ScheduleServiceInitialization(0); |
| 140 | 120 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 POLICY_SCOPE_USER, base::Value::CreateStringValue("google.com")); | 251 POLICY_SCOPE_USER, base::Value::CreateStringValue("google.com")); |
| 272 { | 252 { |
| 273 base::RunLoop run_loop; | 253 base::RunLoop run_loop; |
| 274 policy_service->RefreshPolicies(run_loop.QuitClosure()); | 254 policy_service->RefreshPolicies(run_loop.QuitClosure()); |
| 275 run_loop.Run(); | 255 run_loop.Run(); |
| 276 } | 256 } |
| 277 EXPECT_TRUE( | 257 EXPECT_TRUE( |
| 278 expected.Equals(policy_service->GetPolicies(POLICY_DOMAIN_CHROME, ""))); | 258 expected.Equals(policy_service->GetPolicies(POLICY_DOMAIN_CHROME, ""))); |
| 279 } | 259 } |
| 280 | 260 |
| 281 #if defined(OS_CHROMEOS) | |
| 282 INSTANTIATE_TEST_CASE_P( | |
| 283 OldStackCloudPolicyTest, | |
| 284 CloudPolicyTest, | |
| 285 testing::Values( | |
| 286 TestSetup(SetUpOldStackBeforeCreatingBrowser, | |
| 287 SetUpOldStackAfterCreatingBrowser))); | |
| 288 #endif | |
| 289 | |
| 290 INSTANTIATE_TEST_CASE_P( | 261 INSTANTIATE_TEST_CASE_P( |
|
Joao da Silva
2013/01/17 09:38:05
There's no need to make these test parameterized n
Mattias Nissler (ping if slow)
2013/01/22 10:31:39
Done.
| |
| 291 NewStackCloudPolicyTest, | 262 NewStackCloudPolicyTest, |
| 292 CloudPolicyTest, | 263 CloudPolicyTest, |
| 293 testing::Values( | 264 testing::Values( |
| 294 TestSetup(SetUpNewStackBeforeCreatingBrowser, | 265 TestSetup(SetUpNewStackBeforeCreatingBrowser, |
| 295 SetUpNewStackAfterCreatingBrowser))); | 266 SetUpNewStackAfterCreatingBrowser))); |
| 296 | 267 |
| 297 TEST(CloudPolicyProtoTest, VerifyProtobufEquivalence) { | 268 TEST(CloudPolicyProtoTest, VerifyProtobufEquivalence) { |
| 298 // There are 2 protobufs that can be used for user cloud policy: | 269 // There are 2 protobufs that can be used for user cloud policy: |
| 299 // cloud_policy.proto and chrome_settings.proto. chrome_settings.proto is the | 270 // cloud_policy.proto and chrome_settings.proto. chrome_settings.proto is the |
| 300 // version used by the server, but generates one proto message per policy; to | 271 // version used by the server, but generates one proto message per policy; to |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 | 308 |
| 338 // They should now serialize to the same bytes. | 309 // They should now serialize to the same bytes. |
| 339 std::string chrome_settings_serialized; | 310 std::string chrome_settings_serialized; |
| 340 std::string cloud_policy_serialized; | 311 std::string cloud_policy_serialized; |
| 341 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); | 312 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); |
| 342 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); | 313 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); |
| 343 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); | 314 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); |
| 344 } | 315 } |
| 345 | 316 |
| 346 } // namespace policy | 317 } // namespace policy |
| OLD | NEW |