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

Side by Side Diff: chrome/test/base/testing_browser_process.cc

Issue 2612733003: Machine-local policy files should not affect tests (Closed)
Patch Set: Improve comment Created 3 years, 11 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
« no previous file with comments | « chrome/test/base/test_launcher_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/test/base/testing_browser_process.h" 5 #include "chrome/test/base/testing_browser_process.h"
6 6
7 #include "base/path_service.h"
7 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
8 #include "base/time/default_clock.h" 9 #include "base/time/default_clock.h"
9 #include "base/time/default_tick_clock.h" 10 #include "base/time/default_tick_clock.h"
10 #include "build/build_config.h" 11 #include "build/build_config.h"
11 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/browser_process_impl.h" 13 #include "chrome/browser/browser_process_impl.h"
13 #include "chrome/browser/lifetime/application_lifetime.h" 14 #include "chrome/browser/lifetime/application_lifetime.h"
14 #include "chrome/browser/memory/tab_manager.h" 15 #include "chrome/browser/memory/tab_manager.h"
15 #include "chrome/browser/notifications/notification_platform_bridge.h" 16 #include "chrome/browser/notifications/notification_platform_bridge.h"
16 #include "chrome/browser/notifications/notification_ui_manager.h" 17 #include "chrome/browser/notifications/notification_ui_manager.h"
17 #include "chrome/browser/printing/print_job_manager.h" 18 #include "chrome/browser/printing/print_job_manager.h"
18 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
21 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/features.h" 22 #include "chrome/common/features.h"
21 #include "chrome/test/base/testing_browser_process_platform_part.h" 23 #include "chrome/test/base/testing_browser_process_platform_part.h"
22 #include "components/network_time/network_time_tracker.h" 24 #include "components/network_time/network_time_tracker.h"
23 #include "components/policy/core/browser/browser_policy_connector.h" 25 #include "components/policy/core/browser/browser_policy_connector.h"
24 #include "components/prefs/pref_service.h" 26 #include "components/prefs/pref_service.h"
25 #include "components/subresource_filter/core/browser/ruleset_service.h" 27 #include "components/subresource_filter/core/browser/ruleset_service.h"
26 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
27 #include "extensions/features/features.h" 29 #include "extensions/features/features.h"
28 #include "media/media_features.h" 30 #include "media/media_features.h"
29 #include "net/url_request/url_request_context_getter.h" 31 #include "net/url_request/url_request_context_getter.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 146
145 variations::VariationsService* TestingBrowserProcess::variations_service() { 147 variations::VariationsService* TestingBrowserProcess::variations_service() {
146 return nullptr; 148 return nullptr;
147 } 149 }
148 150
149 policy::BrowserPolicyConnector* 151 policy::BrowserPolicyConnector*
150 TestingBrowserProcess::browser_policy_connector() { 152 TestingBrowserProcess::browser_policy_connector() {
151 if (!browser_policy_connector_) { 153 if (!browser_policy_connector_) {
152 EXPECT_FALSE(created_browser_policy_connector_); 154 EXPECT_FALSE(created_browser_policy_connector_);
153 created_browser_policy_connector_ = true; 155 created_browser_policy_connector_ = true;
156
157 #if defined(OS_POSIX) && !defined(OS_MACOSX)
158 // Make sure that the machine policy directory does not exist so that
159 // machine-wide policies do not affect tests.
160 // Note that passing false as last argument to OverrideAndCreateIfNeeded
161 // means that the directory will not be created.
162 // If a test needs to place a file in this directory in the future, we could
163 // create a temporary directory and make its path available to tests.
164 base::FilePath local_policy_path("/tmp/non/existing/directory");
165 EXPECT_TRUE(PathService::OverrideAndCreateIfNeeded(
166 chrome::DIR_POLICY_FILES, local_policy_path, true, false));
167 #endif
168
154 browser_policy_connector_ = platform_part_->CreateBrowserPolicyConnector(); 169 browser_policy_connector_ = platform_part_->CreateBrowserPolicyConnector();
155 170
156 // Note: creating the ChromeBrowserPolicyConnector invokes BrowserThread:: 171 // Note: creating the ChromeBrowserPolicyConnector invokes BrowserThread::
157 // GetTaskRunnerForThread(), which initializes a base::LazyInstance of 172 // GetTaskRunnerForThread(), which initializes a base::LazyInstance of
158 // BrowserThreadTaskRunners. However, the threads that these task runners 173 // BrowserThreadTaskRunners. However, the threads that these task runners
159 // would run tasks on are *also* created lazily and might not exist yet. 174 // would run tasks on are *also* created lazily and might not exist yet.
160 // Creating them requires a MessageLoop, which a test can optionally create 175 // Creating them requires a MessageLoop, which a test can optionally create
161 // and manage itself, so don't do it here. 176 // and manage itself, so don't do it here.
162 } 177 }
163 return browser_policy_connector_.get(); 178 return browser_policy_connector_.get();
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 471
457 /////////////////////////////////////////////////////////////////////////////// 472 ///////////////////////////////////////////////////////////////////////////////
458 473
459 TestingBrowserProcessInitializer::TestingBrowserProcessInitializer() { 474 TestingBrowserProcessInitializer::TestingBrowserProcessInitializer() {
460 TestingBrowserProcess::CreateInstance(); 475 TestingBrowserProcess::CreateInstance();
461 } 476 }
462 477
463 TestingBrowserProcessInitializer::~TestingBrowserProcessInitializer() { 478 TestingBrowserProcessInitializer::~TestingBrowserProcessInitializer() {
464 TestingBrowserProcess::DeleteInstance(); 479 TestingBrowserProcess::DeleteInstance();
465 } 480 }
OLDNEW
« no previous file with comments | « chrome/test/base/test_launcher_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698