Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/file_util.h" | |
| 10 #include "base/files/file_path.h" | |
| 11 #include "base/files/scoped_temp_dir.h" | |
| 12 #include "base/path_service.h" | |
| 13 #include "base/stl_util.h" | |
| 14 #include "chrome/browser/chromeos/policy/device_policy_builder.h" | |
| 15 #include "chrome/common/chrome_paths.h" | |
| 16 #include "chromeos/dbus/fake_session_manager_client.h" | |
|
Mattias Nissler (ping if slow)
2013/04/22 10:07:43
no need to repeat #includes already present in the
Mathieu
2013/04/22 14:14:23
Done.
| |
| 17 #include "chromeos/dbus/mock_dbus_thread_manager.h" | |
| 18 #include "chromeos/dbus/mock_image_burner_client.h" | |
| 19 #include "crypto/rsa_private_key.h" | |
| 20 #include "testing/gmock/include/gmock/gmock.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | |
| 22 | |
| 23 using ::testing::_; | |
| 24 using ::testing::AnyNumber; | |
| 25 using ::testing::Return; | |
| 26 | |
| 27 namespace policy { | |
| 28 | |
| 29 DevicePolicyCrosBrowserTest::DevicePolicyCrosBrowserTest() : | |
|
Mattias Nissler (ping if slow)
2013/04/22 10:07:43
nit: break before colon, indent following line by
Mathieu
2013/04/22 14:14:23
Done.
| |
| 30 mock_dbus_thread_manager_(new chromeos::MockDBusThreadManager) { | |
| 31 } | |
| 32 | |
| 33 DevicePolicyCrosBrowserTest::~DevicePolicyCrosBrowserTest() { | |
| 34 } | |
| 35 | |
| 36 void DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture() { | |
| 37 EXPECT_CALL(*mock_dbus_thread_manager_, GetSessionManagerClient()) | |
| 38 .WillRepeatedly(Return(&session_manager_client_)); | |
| 39 | |
| 40 SetMockDBusThreadManagerExpectations(); | |
| 41 chromeos::DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager_); | |
| 42 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | |
| 43 } | |
| 44 | |
| 45 void DevicePolicyCrosBrowserTest::SetMockDBusThreadManagerExpectations() { | |
| 46 // TODO(satorux): MockImageBurnerClient seems unnecessary. Remove it? | |
| 47 EXPECT_CALL(*mock_dbus_thread_manager_->mock_image_burner_client(), | |
| 48 ResetEventHandlers()) | |
| 49 .Times(AnyNumber()); | |
| 50 EXPECT_CALL(*mock_dbus_thread_manager_->mock_image_burner_client(), | |
| 51 SetEventHandlers(_, _)) | |
| 52 .Times(AnyNumber()); | |
| 53 } | |
| 54 | |
| 55 void DevicePolicyCrosBrowserTest::InstallOwnerKey() { | |
| 56 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 57 base::FilePath owner_key_file = temp_dir_.path().AppendASCII("owner.key"); | |
| 58 std::vector<uint8> owner_key_bits; | |
| 59 ASSERT_TRUE(device_policy()->signing_key()->ExportPublicKey(&owner_key_bits)); | |
| 60 ASSERT_EQ( | |
| 61 file_util::WriteFile( | |
| 62 owner_key_file, | |
| 63 reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)), | |
| 64 owner_key_bits.size()), | |
| 65 static_cast<int>(owner_key_bits.size())); | |
| 66 ASSERT_TRUE(PathService::Override(chrome::FILE_OWNER_KEY, owner_key_file)); | |
| 67 } | |
| 68 | |
| 69 void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() { | |
| 70 // Reset the key to its original state. | |
| 71 device_policy_.set_signing_key( | |
| 72 policy::PolicyBuilder::CreateTestSigningKey()); | |
| 73 device_policy_.Build(); | |
| 74 // The local instance of the private half of the owner key must be dropped | |
| 75 // as otherwise the NSS library will tell Chrome that the key is available - | |
| 76 // which is incorrect and leads to Chrome behaving as if a local owner were | |
| 77 // logged in. | |
| 78 device_policy_.set_signing_key( | |
| 79 make_scoped_ptr<crypto::RSAPrivateKey>(NULL)); | |
| 80 device_policy_.set_new_signing_key( | |
| 81 make_scoped_ptr<crypto::RSAPrivateKey>(NULL)); | |
| 82 session_manager_client_.set_device_policy(device_policy_.GetBlob()); | |
| 83 session_manager_client_.OnPropertyChangeComplete(true); | |
| 84 } | |
| 85 | |
| 86 void DevicePolicyCrosBrowserTest::TearDownInProcessBrowserTestFixture() { | |
| 87 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | |
| 88 chromeos::DBusThreadManager::Shutdown(); | |
| 89 } | |
| 90 | |
| 91 } // namespace policy | |
| OLD | NEW |