| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 5 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "chrome/browser/chromeos/policy/device_policy_builder.h" | 14 #include "chrome/browser/chromeos/policy/device_policy_builder.h" |
| 15 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 15 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 16 #include "chrome/browser/chromeos/policy/proto/install_attributes.pb.h" | |
| 17 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 18 #include "chromeos/chromeos_paths.h" | 17 #include "chromeos/chromeos_paths.h" |
| 19 #include "chromeos/dbus/fake_dbus_thread_manager.h" | 18 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
| 20 #include "chromeos/dbus/fake_session_manager_client.h" | 19 #include "chromeos/dbus/fake_session_manager_client.h" |
| 21 #include "crypto/rsa_private_key.h" | 20 #include "crypto/rsa_private_key.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 23 |
| 25 using ::testing::_; | 24 using ::testing::_; |
| 26 using ::testing::AnyNumber; | 25 using ::testing::AnyNumber; |
| 27 using ::testing::Return; | 26 using ::testing::Return; |
| 28 | 27 |
| 29 namespace policy { | 28 namespace policy { |
| 30 | 29 |
| 31 DevicePolicyCrosTestHelper::DevicePolicyCrosTestHelper() {} | 30 DevicePolicyCrosTestHelper::DevicePolicyCrosTestHelper() {} |
| 32 | 31 |
| 33 DevicePolicyCrosTestHelper::~DevicePolicyCrosTestHelper() {} | 32 DevicePolicyCrosTestHelper::~DevicePolicyCrosTestHelper() {} |
| 34 | 33 |
| 35 void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() { | 34 void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() { |
| 36 OverridePaths(); | 35 OverridePaths(); |
| 37 | 36 |
| 38 cryptohome::SerializedInstallAttributes install_attrs_proto; | 37 const std::string install_attrs_blob( |
| 39 cryptohome::SerializedInstallAttributes::Attribute* attribute = NULL; | 38 EnterpriseInstallAttributes:: |
| 40 | 39 GetEnterpriseOwnedInstallAttributesBlobForTesting( |
| 41 attribute = install_attrs_proto.add_attributes(); | 40 device_policy_.policy_data().username())); |
| 42 attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseOwned); | |
| 43 attribute->set_value("true"); | |
| 44 | |
| 45 attribute = install_attrs_proto.add_attributes(); | |
| 46 attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseUser); | |
| 47 attribute->set_value(device_policy_.policy_data().username()); | |
| 48 | 41 |
| 49 base::FilePath install_attrs_file; | 42 base::FilePath install_attrs_file; |
| 50 ASSERT_TRUE( | 43 ASSERT_TRUE( |
| 51 PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &install_attrs_file)); | 44 PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &install_attrs_file)); |
| 52 const std::string install_attrs_blob( | |
| 53 install_attrs_proto.SerializeAsString()); | |
| 54 ASSERT_EQ(static_cast<int>(install_attrs_blob.size()), | 45 ASSERT_EQ(static_cast<int>(install_attrs_blob.size()), |
| 55 base::WriteFile(install_attrs_file, | 46 base::WriteFile(install_attrs_file, |
| 56 install_attrs_blob.c_str(), | 47 install_attrs_blob.c_str(), |
| 57 install_attrs_blob.size())); | 48 install_attrs_blob.size())); |
| 58 } | 49 } |
| 59 | 50 |
| 60 void DevicePolicyCrosTestHelper::InstallOwnerKey() { | 51 void DevicePolicyCrosTestHelper::InstallOwnerKey() { |
| 61 OverridePaths(); | 52 OverridePaths(); |
| 62 | 53 |
| 63 base::FilePath owner_key_file; | 54 base::FilePath owner_key_file; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 102 |
| 112 void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() { | 103 void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() { |
| 113 // Reset the key to its original state. | 104 // Reset the key to its original state. |
| 114 device_policy()->SetDefaultSigningKey(); | 105 device_policy()->SetDefaultSigningKey(); |
| 115 device_policy()->Build(); | 106 device_policy()->Build(); |
| 116 session_manager_client()->set_device_policy(device_policy()->GetBlob()); | 107 session_manager_client()->set_device_policy(device_policy()->GetBlob()); |
| 117 session_manager_client()->OnPropertyChangeComplete(true); | 108 session_manager_client()->OnPropertyChangeComplete(true); |
| 118 } | 109 } |
| 119 | 110 |
| 120 } // namespace policy | 111 } // namespace policy |
| OLD | NEW |