xref: /aosp_15_r20/external/libchrome/base/test/scoped_path_override.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #ifndef BASE_TEST_SCOPED_PATH_OVERRIDE_H_
6*635a8641SAndroid Build Coastguard Worker #define BASE_TEST_SCOPED_PATH_OVERRIDE_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include "base/files/scoped_temp_dir.h"
9*635a8641SAndroid Build Coastguard Worker #include "base/macros.h"
10*635a8641SAndroid Build Coastguard Worker 
11*635a8641SAndroid Build Coastguard Worker namespace base {
12*635a8641SAndroid Build Coastguard Worker 
13*635a8641SAndroid Build Coastguard Worker class FilePath;
14*635a8641SAndroid Build Coastguard Worker 
15*635a8641SAndroid Build Coastguard Worker // Sets a path override on construction, and removes it when the object goes out
16*635a8641SAndroid Build Coastguard Worker // of scope. This class is intended to be used by tests that need to override
17*635a8641SAndroid Build Coastguard Worker // paths to ensure their overrides are properly handled and reverted when the
18*635a8641SAndroid Build Coastguard Worker // scope of the test is left.
19*635a8641SAndroid Build Coastguard Worker class ScopedPathOverride {
20*635a8641SAndroid Build Coastguard Worker  public:
21*635a8641SAndroid Build Coastguard Worker   // Contructor that initializes the override to a scoped temp directory.
22*635a8641SAndroid Build Coastguard Worker   explicit ScopedPathOverride(int key);
23*635a8641SAndroid Build Coastguard Worker 
24*635a8641SAndroid Build Coastguard Worker   // Constructor that would use a path provided by the user.
25*635a8641SAndroid Build Coastguard Worker   ScopedPathOverride(int key, const FilePath& dir);
26*635a8641SAndroid Build Coastguard Worker 
27*635a8641SAndroid Build Coastguard Worker   // See PathService::OverrideAndCreateIfNeeded.
28*635a8641SAndroid Build Coastguard Worker   ScopedPathOverride(int key,
29*635a8641SAndroid Build Coastguard Worker                      const FilePath& path,
30*635a8641SAndroid Build Coastguard Worker                      bool is_absolute,
31*635a8641SAndroid Build Coastguard Worker                      bool create);
32*635a8641SAndroid Build Coastguard Worker   ~ScopedPathOverride();
33*635a8641SAndroid Build Coastguard Worker 
34*635a8641SAndroid Build Coastguard Worker  private:
35*635a8641SAndroid Build Coastguard Worker   int key_;
36*635a8641SAndroid Build Coastguard Worker   ScopedTempDir temp_dir_;
37*635a8641SAndroid Build Coastguard Worker 
38*635a8641SAndroid Build Coastguard Worker   DISALLOW_COPY_AND_ASSIGN(ScopedPathOverride);
39*635a8641SAndroid Build Coastguard Worker };
40*635a8641SAndroid Build Coastguard Worker 
41*635a8641SAndroid Build Coastguard Worker }  // namespace base
42*635a8641SAndroid Build Coastguard Worker 
43*635a8641SAndroid Build Coastguard Worker #endif  // BASE_TEST_SCOPED_PATH_OVERRIDE_H_
44