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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/device_policy_cros_browsertest.cc
diff --git a/chrome/browser/chromeos/policy/device_policy_cros_browsertest.cc b/chrome/browser/chromeos/policy/device_policy_cros_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6513da6b4f5b0fb45b67a55ac1a005da561ed97a
--- /dev/null
+++ b/chrome/browser/chromeos/policy/device_policy_cros_browsertest.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/policy/device_policy_cros_browsertest.h"
+
+#include <vector>
+
+#include "base/file_util.h"
+#include "base/files/file_path.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/path_service.h"
+#include "base/stl_util.h"
+#include "chrome/browser/chromeos/policy/device_policy_builder.h"
+#include "chrome/common/chrome_paths.h"
+#include "chromeos/dbus/fake_session_manager_client.h"
+#include "chromeos/dbus/mock_dbus_thread_manager.h"
+#include "chromeos/dbus/mock_image_burner_client.h"
+#include "crypto/rsa_private_key.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+using ::testing::AnyNumber;
+using ::testing::Return;
+
+namespace policy {
+
+DevicePolicyCrosBrowserTest::DevicePolicyCrosBrowserTest() :
+ mock_dbus_thread_manager_(new chromeos::MockDBusThreadManager) {
+}
+
+void DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture() {
+ SetMockDBusThreadManagerExpectations();
+ SetUpSessionManager();
+ chromeos::DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager_);
+ SetUpAdditionalCrosMocks();
+ CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
+}
+
+void DevicePolicyCrosBrowserTest::SetMockDBusThreadManagerExpectations() {
+ EXPECT_CALL(*mock_dbus_thread_manager_->mock_image_burner_client(),
+ ResetEventHandlers())
+ .Times(AnyNumber());
+ EXPECT_CALL(*mock_dbus_thread_manager_->mock_image_burner_client(),
+ SetEventHandlers(_, _))
+ .Times(AnyNumber());
+}
+
+void DevicePolicyCrosBrowserTest::SetUpSessionManager() {
+ EXPECT_CALL(*mock_dbus_thread_manager_, GetSessionManagerClient())
+ .WillRepeatedly(Return(&session_manager_client_));
+
+ InstallOwnerKey();
+ SetSpecificDevicePolicies();
+ RefreshDevicePolicy();
+ SetDeviceLocalAccountPolicy();
+}
+
+void DevicePolicyCrosBrowserTest::InstallOwnerKey() {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ base::FilePath owner_key_file = temp_dir_.path().AppendASCII("owner.key");
+ std::vector<uint8> owner_key_bits;
+ ASSERT_TRUE(device_policy()->signing_key()->ExportPublicKey(&owner_key_bits));
+ ASSERT_EQ(
+ file_util::WriteFile(
+ owner_key_file,
+ reinterpret_cast<const char*>(vector_as_array(&owner_key_bits)),
+ owner_key_bits.size()),
+ static_cast<int>(owner_key_bits.size()));
+ ASSERT_TRUE(PathService::Override(chrome::FILE_OWNER_KEY, owner_key_file));
+}
+
+void DevicePolicyCrosBrowserTest::RefreshDevicePolicy() {
+ // Reset the key to its original state.
+ device_policy_.set_signing_key(
+ policy::PolicyBuilder::CreateTestSigningKey());
+ device_policy_.Build();
+ // The local instance of the private half of the owner key must be dropped
+ // as otherwise the NSS library will tell Chrome that the key is available -
+ // which is incorrect and leads to Chrome behaving as if a local owner were
+ // logged in.
+ device_policy_.set_signing_key(
+ make_scoped_ptr<crypto::RSAPrivateKey>(NULL));
+ device_policy_.set_new_signing_key(
+ make_scoped_ptr<crypto::RSAPrivateKey>(NULL));
+ session_manager_client_.set_device_policy(device_policy_.GetBlob());
+ session_manager_client_.OnPropertyChangeComplete(true);
+}
+
+void DevicePolicyCrosBrowserTest::TearDownInProcessBrowserTestFixture() {
+ CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture();
+ chromeos::DBusThreadManager::Shutdown();
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698