OLD | NEW |
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/browser/media_galleries/media_galleries_test_util.h" | 5 #include "chrome/browser/media_galleries/media_galleries_test_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/threading/thread_restrictions.h" |
16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" | 19 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
21 #include "components/crx_file/id_util.h" | 22 #include "components/crx_file/id_util.h" |
22 #include "extensions/browser/extension_prefs.h" | 23 #include "extensions/browser/extension_prefs.h" |
23 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
24 #include "extensions/common/manifest_constants.h" | 25 #include "extensions/common/manifest_constants.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 EnsureMediaDirectoriesExists::EnsureMediaDirectoriesExists() | 90 EnsureMediaDirectoriesExists::EnsureMediaDirectoriesExists() |
90 : num_galleries_(0), times_overrides_changed_(0) { | 91 : num_galleries_(0), times_overrides_changed_(0) { |
91 Init(); | 92 Init(); |
92 } | 93 } |
93 | 94 |
94 EnsureMediaDirectoriesExists::~EnsureMediaDirectoriesExists() { | 95 EnsureMediaDirectoriesExists::~EnsureMediaDirectoriesExists() { |
95 #if defined(OS_MACOSX) | 96 #if defined(OS_MACOSX) |
96 iapps::SetMacPreferencesForTesting(NULL); | 97 iapps::SetMacPreferencesForTesting(NULL); |
97 picasa::SetMacPreferencesForTesting(NULL); | 98 picasa::SetMacPreferencesForTesting(NULL); |
98 #endif // OS_MACOSX | 99 #endif // OS_MACOSX |
| 100 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 101 ignore_result(fake_dir_.Delete()); |
99 } | 102 } |
100 | 103 |
101 void EnsureMediaDirectoriesExists::ChangeMediaPathOverrides() { | 104 void EnsureMediaDirectoriesExists::ChangeMediaPathOverrides() { |
102 // Each pointer must be reset an extra time so as to destroy the existing | 105 // Each pointer must be reset an extra time so as to destroy the existing |
103 // override prior to creating a new one. This is because the PathService, | 106 // override prior to creating a new one. This is because the PathService, |
104 // which supports these overrides, only allows one override to exist per path | 107 // which supports these overrides, only allows one override to exist per path |
105 // in its internal bookkeeping; attempting to add a second override invokes | 108 // in its internal bookkeeping; attempting to add a second override invokes |
106 // a CHECK crash. | 109 // a CHECK crash. |
107 music_override_.reset(); | 110 music_override_.reset(); |
108 std::string music_path_string("music"); | 111 std::string music_path_string("music"); |
(...skipping 15 matching lines...) Expand all Loading... |
124 video_override_.reset(new base::ScopedPathOverride( | 127 video_override_.reset(new base::ScopedPathOverride( |
125 chrome::DIR_USER_VIDEOS, | 128 chrome::DIR_USER_VIDEOS, |
126 fake_dir_.GetPath().AppendASCII(videos_path_string))); | 129 fake_dir_.GetPath().AppendASCII(videos_path_string))); |
127 | 130 |
128 times_overrides_changed_++; | 131 times_overrides_changed_++; |
129 | 132 |
130 num_galleries_ = 3; | 133 num_galleries_ = 3; |
131 } | 134 } |
132 | 135 |
133 base::FilePath EnsureMediaDirectoriesExists::GetFakeAppDataPath() const { | 136 base::FilePath EnsureMediaDirectoriesExists::GetFakeAppDataPath() const { |
| 137 base::ThreadRestrictions::ScopedAllowIO allow_io; |
134 DCHECK(fake_dir_.IsValid()); | 138 DCHECK(fake_dir_.IsValid()); |
135 return fake_dir_.GetPath().AppendASCII("appdata"); | 139 return fake_dir_.GetPath().AppendASCII("appdata"); |
136 } | 140 } |
137 | 141 |
138 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
139 base::FilePath EnsureMediaDirectoriesExists::GetFakeLocalAppDataPath() const { | 143 base::FilePath EnsureMediaDirectoriesExists::GetFakeLocalAppDataPath() const { |
140 DCHECK(fake_dir_.IsValid()); | 144 DCHECK(fake_dir_.IsValid()); |
141 return fake_dir_.GetPath().AppendASCII("localappdata"); | 145 return fake_dir_.GetPath().AppendASCII("localappdata"); |
142 } | 146 } |
143 | 147 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 222 |
219 base::FilePath MakeMediaGalleriesTestingPath(const std::string& dir) { | 223 base::FilePath MakeMediaGalleriesTestingPath(const std::string& dir) { |
220 #if defined(OS_WIN) | 224 #if defined(OS_WIN) |
221 return base::FilePath(FILE_PATH_LITERAL("C:\\")).AppendASCII(dir); | 225 return base::FilePath(FILE_PATH_LITERAL("C:\\")).AppendASCII(dir); |
222 #elif defined(OS_POSIX) | 226 #elif defined(OS_POSIX) |
223 return base::FilePath(FILE_PATH_LITERAL("/")).Append(dir); | 227 return base::FilePath(FILE_PATH_LITERAL("/")).Append(dir); |
224 #else | 228 #else |
225 NOTREACHED(); | 229 NOTREACHED(); |
226 #endif | 230 #endif |
227 } | 231 } |
OLD | NEW |