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

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

Issue 14268009: Support VariationsRestrictParameter in VariationsService for Chrome OS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Browsertest + comments 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 <vector>
6
7 #include "base/file_util.h"
8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h"
10 #include "base/path_service.h"
11 #include "base/stl_util.h"
12 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
13 #include "chrome/browser/chromeos/policy/device_policy_builder.h"
14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
15 #include "chrome/browser/metrics/variations/variations_service.h"
16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/test/base/testing_browser_process.h"
18 #include "chromeos/dbus/fake_session_manager_client.h"
19 #include "chromeos/dbus/mock_dbus_thread_manager.h"
20 #include "chromeos/dbus/mock_image_burner_client.h"
21 #include "crypto/rsa_private_key.h"
22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24
25 using ::testing::_;
26 using ::testing::AnyNumber;
27 using ::testing::Return;
28
29 namespace em = enterprise_management;
Alexei Svitkine (slow) 2013/04/18 19:27:53 You're only using em:: once in the file, this does
Mathieu 2013/04/18 19:51:14 Done.
30
31 namespace policy {
32
33 class DeviceVariationsServicePolicyTest :
34 public chromeos::CrosInProcessBrowserTest {
35 protected:
36 DeviceVariationsServicePolicyTest() {};
37
38 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
39 chromeos::MockDBusThreadManager* mock_dbus_thread_manager =
40 new chromeos::MockDBusThreadManager;
41
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 SetUpSessionManager(mock_dbus_thread_manager);
50
51 chromeos::DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
52 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
53 }
54
55 void SetUpSessionManager(
56 chromeos::MockDBusThreadManager* mock_dbus_thread_manager) {
57 EXPECT_CALL(*mock_dbus_thread_manager, GetSessionManagerClient())
58 .WillRepeatedly(Return(&session_manager_client_));
59
60 // Install the owner key.
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 // Setup the device policy DeviceVariationsRestrictParameter.
74 em::ChromeDeviceSettingsProto& proto(device_policy_.payload());
75 proto.mutable_variations_parameter()->set_parameter("restricted");
76 RefreshDevicePolicy();
77 }
Alexei Svitkine (slow) 2013/04/18 19:27:53 This seems like a lot of boilerplate for a pretty
Mathieu 2013/04/18 19:51:14 It comes from: https://code.google.com/p/chromium/
Alexei Svitkine (slow) 2013/04/18 20:01:27 I suggest making a common superclass, derived from
78
79 void RefreshDevicePolicy() {
80 // Reset the key to its original state.
81 device_policy_.set_signing_key(
82 policy::PolicyBuilder::CreateTestSigningKey());
83 device_policy_.Build();
84 // Trick the device into thinking it's enterprise-enrolled by
85 // removing the local private key. This will allow it to accept
86 // cloud policy for device owner settings.
87 device_policy_.set_signing_key(
88 make_scoped_ptr<crypto::RSAPrivateKey>(NULL));
89 device_policy_.set_new_signing_key(
90 make_scoped_ptr<crypto::RSAPrivateKey>(NULL));
91 session_manager_client_.set_device_policy(device_policy_.GetBlob());
92 session_manager_client_.OnPropertyChangeComplete(true);
93 }
94
95 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
96 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture();
97 chromeos::DBusThreadManager::Shutdown();
98 }
99
100 private:
101 // Mock out policy loads/stores from/to the device.
102 chromeos::FakeSessionManagerClient session_manager_client_;
103
104 // Stores the device owner key.
105 base::ScopedTempDir temp_dir_;
106
107 // Carries Chrome OS device policies for tests.
108 DevicePolicyBuilder device_policy_;
109
110 DISALLOW_COPY_AND_ASSIGN(DeviceVariationsServicePolicyTest);
111 };
112
113 IN_PROC_BROWSER_TEST_F(DeviceVariationsServicePolicyTest, VariationsURLValid) {
114 const std::string default_variations_url =
115 chrome_variations::VariationsService::
116 GetDefaultVariationsServerURLForTesting();
117
118 // Device policy has updated the cros settings.
119 EXPECT_EQ(default_variations_url + "?restrict=restricted",
120 chrome_variations::VariationsService::GetVariationsServerURL(
121 g_browser_process->local_state()).spec());
122 }
123
124 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698