| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "crypto/rsa_private_key.h" | 21 #include "crypto/rsa_private_key.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 using ::testing::_; | 25 using ::testing::_; |
| 26 using ::testing::AnyNumber; | 26 using ::testing::AnyNumber; |
| 27 using ::testing::Return; | 27 using ::testing::Return; |
| 28 | 28 |
| 29 namespace policy { | 29 namespace policy { |
| 30 | 30 |
| 31 namespace { |
| 32 |
| 33 void WriteInstallAttributesFile(const std::string& install_attrs_blob) { |
| 34 base::FilePath install_attrs_file; |
| 35 ASSERT_TRUE( |
| 36 PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &install_attrs_file)); |
| 37 ASSERT_EQ(base::checked_cast<int>(install_attrs_blob.size()), |
| 38 base::WriteFile(install_attrs_file, install_attrs_blob.c_str(), |
| 39 install_attrs_blob.size())); |
| 40 } |
| 41 |
| 42 } // namespace |
| 43 |
| 31 DevicePolicyCrosTestHelper::DevicePolicyCrosTestHelper() {} | 44 DevicePolicyCrosTestHelper::DevicePolicyCrosTestHelper() {} |
| 32 | 45 |
| 33 DevicePolicyCrosTestHelper::~DevicePolicyCrosTestHelper() {} | 46 DevicePolicyCrosTestHelper::~DevicePolicyCrosTestHelper() {} |
| 34 | 47 |
| 35 // static | 48 // static |
| 36 void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwnedBy( | 49 void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwnedBy( |
| 37 const std::string& user_name) { | 50 const std::string& user_name) { |
| 38 OverridePaths(); | 51 OverridePaths(); |
| 39 | 52 WriteInstallAttributesFile( |
| 40 const std::string install_attrs_blob( | |
| 41 chromeos::InstallAttributes:: | 53 chromeos::InstallAttributes:: |
| 42 GetEnterpriseOwnedInstallAttributesBlobForTesting(user_name)); | 54 GetEnterpriseOwnedInstallAttributesBlobForTesting(user_name)); |
| 55 } |
| 43 | 56 |
| 44 base::FilePath install_attrs_file; | 57 // static |
| 45 ASSERT_TRUE( | 58 void DevicePolicyCrosTestHelper::MarkAsActiveDirectoryEnterpriseOwned( |
| 46 PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &install_attrs_file)); | 59 const std::string& realm) { |
| 47 ASSERT_EQ(base::checked_cast<int>(install_attrs_blob.size()), | 60 OverridePaths(); |
| 48 base::WriteFile(install_attrs_file, install_attrs_blob.c_str(), | 61 WriteInstallAttributesFile( |
| 49 install_attrs_blob.size())); | 62 chromeos::InstallAttributes:: |
| 63 GetActiveDirectoryEnterpriseOwnedInstallAttributesBlobForTesting( |
| 64 realm)); |
| 50 } | 65 } |
| 51 | 66 |
| 52 void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() { | 67 void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() { |
| 53 MarkAsEnterpriseOwnedBy(device_policy_.policy_data().username()); | 68 MarkAsEnterpriseOwnedBy(device_policy_.policy_data().username()); |
| 54 } | 69 } |
| 55 | 70 |
| 56 void DevicePolicyCrosTestHelper::InstallOwnerKey() { | 71 void DevicePolicyCrosTestHelper::InstallOwnerKey() { |
| 57 OverridePaths(); | 72 OverridePaths(); |
| 58 | 73 |
| 59 base::FilePath owner_key_file; | 74 base::FilePath owner_key_file; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 77 | 92 |
| 78 DevicePolicyCrosBrowserTest::DevicePolicyCrosBrowserTest() | 93 DevicePolicyCrosBrowserTest::DevicePolicyCrosBrowserTest() |
| 79 : fake_session_manager_client_(new chromeos::FakeSessionManagerClient) { | 94 : fake_session_manager_client_(new chromeos::FakeSessionManagerClient) { |
| 80 } | 95 } |
| 81 | 96 |
| 82 DevicePolicyCrosBrowserTest::~DevicePolicyCrosBrowserTest() { | 97 DevicePolicyCrosBrowserTest::~DevicePolicyCrosBrowserTest() { |
| 83 } | 98 } |
| 84 | 99 |
| 85 void DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture() { | 100 void DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture() { |
| 86 InstallOwnerKey(); | 101 InstallOwnerKey(); |
| 87 MarkAsEnterpriseOwned(); | 102 MarkOwnership(); |
| 88 dbus_setter_ = chromeos::DBusThreadManager::GetSetterForTesting(); | 103 dbus_setter_ = chromeos::DBusThreadManager::GetSetterForTesting(); |
| 89 dbus_setter_->SetSessionManagerClient( | 104 dbus_setter_->SetSessionManagerClient( |
| 90 std::unique_ptr<chromeos::SessionManagerClient>( | 105 std::unique_ptr<chromeos::SessionManagerClient>( |
| 91 fake_session_manager_client_)); | 106 fake_session_manager_client_)); |
| 92 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 107 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 93 } | 108 } |
| 94 | 109 |
| 95 void DevicePolicyCrosBrowserTest::TearDownInProcessBrowserTestFixture() { | 110 void DevicePolicyCrosBrowserTest::TearDownInProcessBrowserTestFixture() { |
| 96 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | 111 InProcessBrowserTest::TearDownInProcessBrowserTestFixture(); |
| 97 } | 112 } |
| 98 | 113 |
| 114 void DevicePolicyCrosBrowserTest::MarkOwnership() { |
| 115 MarkAsEnterpriseOwned(); |
| 116 } |
| 117 |
| 99 void DevicePolicyCrosBrowserTest::MarkAsEnterpriseOwned() { | 118 void DevicePolicyCrosBrowserTest::MarkAsEnterpriseOwned() { |
| 100 test_helper_.MarkAsEnterpriseOwned(); | 119 test_helper_.MarkAsEnterpriseOwned(); |
| 101 } | 120 } |
| 102 | 121 |
| 103 void DevicePolicyCrosBrowserTest::InstallOwnerKey() { | 122 void DevicePolicyCrosBrowserTest::InstallOwnerKey() { |
| 104 test_helper_.InstallOwnerKey(); | 123 test_helper_.InstallOwnerKey(); |
| 105 } | 124 } |
| 106 | 125 |
| 107 void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() { | 126 void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() { |
| 108 // Reset the key to its original state. | 127 // Reset the key to its original state. |
| 109 device_policy()->SetDefaultSigningKey(); | 128 device_policy()->SetDefaultSigningKey(); |
| 110 device_policy()->Build(); | 129 device_policy()->Build(); |
| 111 session_manager_client()->set_device_policy(device_policy()->GetBlob()); | 130 session_manager_client()->set_device_policy(device_policy()->GetBlob()); |
| 112 session_manager_client()->OnPropertyChangeComplete(true); | 131 session_manager_client()->OnPropertyChangeComplete(true); |
| 113 } | 132 } |
| 114 | 133 |
| 115 } // namespace policy | 134 } // namespace policy |
| OLD | NEW |