Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: chrome/browser/chromeos/policy/device_policy_cros_browsertest.cc

Issue 14268009: Support VariationsRestrictParameter in VariationsService for Chrome OS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Browser tests refactored Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_browsertest.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"
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() :
30 mock_dbus_thread_manager_(new chromeos::MockDBusThreadManager) {
31 }
32
33 void DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture() {
34 SetMockDBusThreadManagerExpectations();
35 SetUpSessionManager();
36 chromeos::DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager_);
37 SetUpAdditionalCrosMocks();
38 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
39 }
40
41 void DevicePolicyCrosBrowserTest::SetMockDBusThreadManagerExpectations() {
42 EXPECT_CALL(*mock_dbus_thread_manager_->mock_image_burner_client(),
43 ResetEventHandlers())
44 .Times(AnyNumber());
45 EXPECT_CALL(*mock_dbus_thread_manager_->mock_image_burner_client(),
46 SetEventHandlers(_, _))
47 .Times(AnyNumber());
48 }
49
50 void DevicePolicyCrosBrowserTest::SetUpSessionManager() {
51 EXPECT_CALL(*mock_dbus_thread_manager_, GetSessionManagerClient())
52 .WillRepeatedly(Return(&session_manager_client_));
53
54 InstallOwnerKey();
55 SetSpecificDevicePolicies();
56 RefreshDevicePolicy();
57 SetDeviceLocalAccountPolicy();
58 }
59
60 void DevicePolicyCrosBrowserTest::InstallOwnerKey() {
61 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
62 base::FilePath owner_key_file = temp_dir_.path().AppendASCII("owner.key");
63 std::vector<uint8> owner_key_bits;
64 ASSERT_TRUE(device_policy()->signing_key()->ExportPublicKey(&owner_key_bits));
65 ASSERT_EQ(
66 file_util::WriteFile(
67 owner_key_file,
68 reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)),
69 owner_key_bits.size()),
70 static_cast<int>(owner_key_bits.size()));
71 ASSERT_TRUE(PathService::Override(chrome::FILE_OWNER_KEY, owner_key_file));
72 }
73
74 void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() {
75 // Reset the key to its original state.
76 device_policy_.set_signing_key(
77 policy::PolicyBuilder::CreateTestSigningKey());
78 device_policy_.Build();
79 // The local instance of the private half of the owner key must be dropped
80 // as otherwise the NSS library will tell Chrome that the key is available -
81 // which is incorrect and leads to Chrome behaving as if a local owner were
82 // logged in.
83 device_policy_.set_signing_key(
84 make_scoped_ptr<crypto::RSAPrivateKey>(NULL));
85 device_policy_.set_new_signing_key(
86 make_scoped_ptr<crypto::RSAPrivateKey>(NULL));
87 session_manager_client_.set_device_policy(device_policy_.GetBlob());
88 session_manager_client_.OnPropertyChangeComplete(true);
89 }
90
91 void DevicePolicyCrosBrowserTest::TearDownInProcessBrowserTestFixture() {
92 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture();
93 chromeos::DBusThreadManager::Shutdown();
94 }
95
96 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698