Commit 6edddec4 authored by pmarko's avatar pmarko Committed by Commit bot

Machine-local policy files should not affect tests

Override location of machine-local policy directory for both unit tests
and browser tests. This makes sure that any policy data the machine has
does not affect the test results.

BUG=630614

Review-Url: https://codereview.chromium.org/2612733003
Cr-Commit-Position: refs/heads/master@{#442852}
parent d1f2198a
......@@ -106,6 +106,12 @@ bool OverrideUserDataDir(const base::FilePath& user_data_dir) {
// value to the child process. This is the simplest way to do it.
std::unique_ptr<base::Environment> env(base::Environment::Create());
success = success && env->SetVar("XDG_CACHE_HOME", user_data_dir.value());
// Also make sure that the machine policy directory is inside the clear
// profile. Otherwise the machine's policies could affect tests.
base::FilePath policy_files = user_data_dir.AppendASCII("policies");
success =
success && PathService::Override(chrome::DIR_POLICY_FILES, policy_files);
#endif
return success;
......
......@@ -4,6 +4,7 @@
#include "chrome/test/base/testing_browser_process.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/time/default_clock.h"
#include "base/time/default_tick_clock.h"
......@@ -17,6 +18,7 @@
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/features.h"
#include "chrome/test/base/testing_browser_process_platform_part.h"
#include "components/network_time/network_time_tracker.h"
......@@ -151,6 +153,19 @@ policy::BrowserPolicyConnector*
if (!browser_policy_connector_) {
EXPECT_FALSE(created_browser_policy_connector_);
created_browser_policy_connector_ = true;
#if defined(OS_POSIX) && !defined(OS_MACOSX)
// Make sure that the machine policy directory does not exist so that
// machine-wide policies do not affect tests.
// Note that passing false as last argument to OverrideAndCreateIfNeeded
// means that the directory will not be created.
// If a test needs to place a file in this directory in the future, we could
// create a temporary directory and make its path available to tests.
base::FilePath local_policy_path("/tmp/non/existing/directory");
EXPECT_TRUE(PathService::OverrideAndCreateIfNeeded(
chrome::DIR_POLICY_FILES, local_policy_path, true, false));
#endif
browser_policy_connector_ = platform_part_->CreateBrowserPolicyConnector();
// Note: creating the ChromeBrowserPolicyConnector invokes BrowserThread::
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment