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 <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 policy { | |
30 | |
31 class DeviceVariationsServicePolicyTest : | |
32 public chromeos::CrosInProcessBrowserTest { | |
33 protected: | |
34 DeviceVariationsServicePolicyTest() {}; | |
35 | |
36 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | |
37 chromeos::MockDBusThreadManager* mock_dbus_thread_manager = | |
38 new chromeos::MockDBusThreadManager; | |
39 | |
40 EXPECT_CALL(*mock_dbus_thread_manager->mock_image_burner_client(), | |
41 ResetEventHandlers()) | |
42 .Times(AnyNumber()); | |
43 EXPECT_CALL(*mock_dbus_thread_manager->mock_image_burner_client(), | |
44 SetEventHandlers(_, _)) | |
45 .Times(AnyNumber()); | |
Mattias Nissler (ping if slow)
2013/04/19 10:37:00
I think these are just for silencing gmock? I don'
satorux1
2013/04/19 11:46:20
We are in the process of removing gmock from chrom
satorux1
2013/04/19 12:04:13
Sorry. my previous comment didn't answer your ques
Mathieu
2013/04/19 17:58:25
Fakes won't work for this browsertest. Seems like
Mathieu
2013/04/19 17:58:25
It doesn't seem used, let me know if you want me t
satorux1
2013/04/22 01:04:35
That's fine. haruki@ will be removing unused mocks
| |
46 | |
47 SetUpSessionManager(mock_dbus_thread_manager); | |
48 | |
49 chromeos::DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); | |
50 CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | |
51 } | |
52 | |
53 void SetUpSessionManager( | |
54 chromeos::MockDBusThreadManager* mock_dbus_thread_manager) { | |
55 EXPECT_CALL(*mock_dbus_thread_manager, GetSessionManagerClient()) | |
56 .WillRepeatedly(Return(&session_manager_client_)); | |
57 | |
58 // Install the owner key. | |
59 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
60 base::FilePath owner_key_file = temp_dir_.path().AppendASCII("owner.key"); | |
61 std::vector<uint8> owner_key_bits; | |
62 ASSERT_TRUE(device_policy_.signing_key()->ExportPublicKey(&owner_key_bits)); | |
63 ASSERT_EQ( | |
64 file_util::WriteFile( | |
65 owner_key_file, | |
66 reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)), | |
67 owner_key_bits.size()), | |
68 static_cast<int>(owner_key_bits.size())); | |
69 ASSERT_TRUE(PathService::Override(chrome::FILE_OWNER_KEY, owner_key_file)); | |
70 | |
71 // Setup the device policy DeviceVariationsRestrictParameter. | |
72 enterprise_management::ChromeDeviceSettingsProto& proto( | |
73 device_policy_.payload()); | |
74 proto.mutable_variations_parameter()->set_parameter("restricted"); | |
75 RefreshDevicePolicy(); | |
76 } | |
77 | |
78 void RefreshDevicePolicy() { | |
79 // Reset the key to its original state. | |
80 device_policy_.set_signing_key( | |
81 policy::PolicyBuilder::CreateTestSigningKey()); | |
82 device_policy_.Build(); | |
83 // Trick the device into thinking it's enterprise-enrolled by | |
84 // removing the local private key. This will allow it to accept | |
85 // cloud policy for device owner settings. | |
Mattias Nissler (ping if slow)
2013/04/19 10:37:00
Not sure who wrote that comment, but it's a bit un
Mathieu
2013/04/19 17:58:25
Done.
| |
86 device_policy_.set_signing_key( | |
87 make_scoped_ptr<crypto::RSAPrivateKey>(NULL)); | |
88 device_policy_.set_new_signing_key( | |
89 make_scoped_ptr<crypto::RSAPrivateKey>(NULL)); | |
90 session_manager_client_.set_device_policy(device_policy_.GetBlob()); | |
91 session_manager_client_.OnPropertyChangeComplete(true); | |
92 } | |
93 | |
94 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | |
95 CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | |
96 chromeos::DBusThreadManager::Shutdown(); | |
97 } | |
98 | |
99 private: | |
100 // Mock out policy loads/stores from/to the device. | |
101 chromeos::FakeSessionManagerClient session_manager_client_; | |
102 | |
103 // Stores the device owner key. | |
104 base::ScopedTempDir temp_dir_; | |
105 | |
106 // Carries Chrome OS device policies for tests. | |
107 DevicePolicyBuilder device_policy_; | |
108 | |
109 DISALLOW_COPY_AND_ASSIGN(DeviceVariationsServicePolicyTest); | |
110 }; | |
111 | |
112 IN_PROC_BROWSER_TEST_F(DeviceVariationsServicePolicyTest, VariationsURLValid) { | |
113 const std::string default_variations_url = | |
114 chrome_variations::VariationsService:: | |
115 GetDefaultVariationsServerURLForTesting(); | |
116 | |
117 // Device policy has updated the cros settings. | |
118 EXPECT_EQ(default_variations_url + "?restrict=restricted", | |
119 chrome_variations::VariationsService::GetVariationsServerURL( | |
120 g_browser_process->local_state()).spec()); | |
121 } | |
122 | |
123 } // namespace policy | |
OLD | NEW |