scoped_path_override.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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
  3. // found in the LICENSE file.
  4. #ifndef BASE_TEST_SCOPED_PATH_OVERRIDE_H_
  5. #define BASE_TEST_SCOPED_PATH_OVERRIDE_H_
  6. #include "base/files/scoped_temp_dir.h"
  7. #include "base/macros.h"
  8. namespace base {
  9. class FilePath;
  10. // Sets a path override on construction, and removes it when the object goes out
  11. // of scope. This class is intended to be used by tests that need to override
  12. // paths to ensure their overrides are properly handled and reverted when the
  13. // scope of the test is left.
  14. class ScopedPathOverride {
  15. public:
  16. // Contructor that initializes the override to a scoped temp directory.
  17. explicit ScopedPathOverride(int key);
  18. // Constructor that would use a path provided by the user.
  19. ScopedPathOverride(int key, const FilePath& dir);
  20. // See PathService::OverrideAndCreateIfNeeded.
  21. ScopedPathOverride(int key,
  22. const FilePath& path,
  23. bool is_absolute,
  24. bool create);
  25. ~ScopedPathOverride();
  26. private:
  27. int key_;
  28. ScopedTempDir temp_dir_;
  29. DISALLOW_COPY_AND_ASSIGN(ScopedPathOverride);
  30. };
  31. } // namespace base
  32. #endif // BASE_TEST_SCOPED_PATH_OVERRIDE_H_