| 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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 using ::testing::_; | 24 using ::testing::_; |
| 25 using ::testing::AnyNumber; | 25 using ::testing::AnyNumber; |
| 26 using ::testing::Return; | 26 using ::testing::Return; |
| 27 | 27 |
| 28 namespace policy { | 28 namespace policy { |
| 29 | 29 |
| 30 DevicePolicyCrosTestHelper::DevicePolicyCrosTestHelper() {} | 30 DevicePolicyCrosTestHelper::DevicePolicyCrosTestHelper() {} |
| 31 | 31 |
| 32 DevicePolicyCrosTestHelper::~DevicePolicyCrosTestHelper() {} | 32 DevicePolicyCrosTestHelper::~DevicePolicyCrosTestHelper() {} |
| 33 | 33 |
| 34 void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() { | 34 // static |
| 35 void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwnedBy( |
| 36 const std::string& user_name) { |
| 35 OverridePaths(); | 37 OverridePaths(); |
| 36 | 38 |
| 37 const std::string install_attrs_blob( | 39 const std::string install_attrs_blob( |
| 38 EnterpriseInstallAttributes:: | 40 EnterpriseInstallAttributes:: |
| 39 GetEnterpriseOwnedInstallAttributesBlobForTesting( | 41 GetEnterpriseOwnedInstallAttributesBlobForTesting(user_name)); |
| 40 device_policy_.policy_data().username())); | |
| 41 | 42 |
| 42 base::FilePath install_attrs_file; | 43 base::FilePath install_attrs_file; |
| 43 ASSERT_TRUE( | 44 ASSERT_TRUE( |
| 44 PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &install_attrs_file)); | 45 PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &install_attrs_file)); |
| 45 ASSERT_EQ(static_cast<int>(install_attrs_blob.size()), | 46 ASSERT_EQ(static_cast<int>(install_attrs_blob.size()), |
| 46 base::WriteFile(install_attrs_file, | 47 base::WriteFile(install_attrs_file, |
| 47 install_attrs_blob.c_str(), | 48 install_attrs_blob.c_str(), |
| 48 install_attrs_blob.size())); | 49 install_attrs_blob.size())); |
| 49 } | 50 } |
| 50 | 51 |
| 52 void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() { |
| 53 MarkAsEnterpriseOwnedBy(device_policy_.policy_data().username()); |
| 54 } |
| 55 |
| 51 void DevicePolicyCrosTestHelper::InstallOwnerKey() { | 56 void DevicePolicyCrosTestHelper::InstallOwnerKey() { |
| 52 OverridePaths(); | 57 OverridePaths(); |
| 53 | 58 |
| 54 base::FilePath owner_key_file; | 59 base::FilePath owner_key_file; |
| 55 ASSERT_TRUE(PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_file)); | 60 ASSERT_TRUE(PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_file)); |
| 56 std::vector<uint8> owner_key_bits; | 61 std::vector<uint8> owner_key_bits; |
| 57 ASSERT_TRUE( | 62 ASSERT_TRUE( |
| 58 device_policy()->GetSigningKey()->ExportPublicKey(&owner_key_bits)); | 63 device_policy()->GetSigningKey()->ExportPublicKey(&owner_key_bits)); |
| 59 ASSERT_EQ(base::WriteFile( | 64 ASSERT_EQ(base::WriteFile( |
| 60 owner_key_file, | 65 owner_key_file, |
| 61 reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)), | 66 reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)), |
| 62 owner_key_bits.size()), | 67 owner_key_bits.size()), |
| 63 static_cast<int>(owner_key_bits.size())); | 68 static_cast<int>(owner_key_bits.size())); |
| 64 } | 69 } |
| 65 | 70 |
| 71 // static |
| 66 void DevicePolicyCrosTestHelper::OverridePaths() { | 72 void DevicePolicyCrosTestHelper::OverridePaths() { |
| 67 // This is usually done by ChromeBrowserMainChromeOS, but some tests | 73 // This is usually done by ChromeBrowserMainChromeOS, but some tests |
| 68 // use the overridden paths before ChromeBrowserMain starts. Make sure that | 74 // use the overridden paths before ChromeBrowserMain starts. Make sure that |
| 69 // the paths are overridden before using them. | 75 // the paths are overridden before using them. |
| 70 base::FilePath user_data_dir; | 76 base::FilePath user_data_dir; |
| 71 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | 77 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
| 72 chromeos::RegisterStubPathOverrides(user_data_dir); | 78 chromeos::RegisterStubPathOverrides(user_data_dir); |
| 73 } | 79 } |
| 74 | 80 |
| 75 DevicePolicyCrosBrowserTest::DevicePolicyCrosBrowserTest() | 81 DevicePolicyCrosBrowserTest::DevicePolicyCrosBrowserTest() |
| (...skipping 24 matching lines...) Expand all Loading... |
| 100 | 106 |
| 101 void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() { | 107 void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() { |
| 102 // Reset the key to its original state. | 108 // Reset the key to its original state. |
| 103 device_policy()->SetDefaultSigningKey(); | 109 device_policy()->SetDefaultSigningKey(); |
| 104 device_policy()->Build(); | 110 device_policy()->Build(); |
| 105 session_manager_client()->set_device_policy(device_policy()->GetBlob()); | 111 session_manager_client()->set_device_policy(device_policy()->GetBlob()); |
| 106 session_manager_client()->OnPropertyChangeComplete(true); | 112 session_manager_client()->OnPropertyChangeComplete(true); |
| 107 } | 113 } |
| 108 | 114 |
| 109 } // namespace policy | 115 } // namespace policy |
| OLD | NEW |