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

Side by Side Diff: chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc

Issue 2314363002: extensions: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Comment addressed Created 4 years, 3 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
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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // a common_injected.js to the temporary copy and run it. 101 // a common_injected.js to the temporary copy and run it.
102 const char kTestDir[] = "api_test/media_galleries/"; 102 const char kTestDir[] = "api_test/media_galleries/";
103 base::FilePath from_dir = 103 base::FilePath from_dir =
104 test_data_dir_.AppendASCII(kTestDir + extension_name); 104 test_data_dir_.AppendASCII(kTestDir + extension_name);
105 from_dir = from_dir.NormalizePathSeparators(); 105 from_dir = from_dir.NormalizePathSeparators();
106 106
107 base::ScopedTempDir temp_dir; 107 base::ScopedTempDir temp_dir;
108 if (!temp_dir.CreateUniqueTempDir()) 108 if (!temp_dir.CreateUniqueTempDir())
109 return false; 109 return false;
110 110
111 if (!base::CopyDirectory(from_dir, temp_dir.path(), true)) 111 if (!base::CopyDirectory(from_dir, temp_dir.GetPath(), true))
112 return false; 112 return false;
113 113
114 base::FilePath common_js_path( 114 base::FilePath common_js_path(
115 GetCommonDataDir().AppendASCII("common_injected.js")); 115 GetCommonDataDir().AppendASCII("common_injected.js"));
116 base::FilePath inject_js_path( 116 base::FilePath inject_js_path(temp_dir.GetPath()
117 temp_dir.path().AppendASCII(extension_name) 117 .AppendASCII(extension_name)
118 .AppendASCII("common_injected.js")); 118 .AppendASCII("common_injected.js"));
119 if (!base::CopyFile(common_js_path, inject_js_path)) 119 if (!base::CopyFile(common_js_path, inject_js_path))
120 return false; 120 return false;
121 121
122 const char* custom_arg = NULL; 122 const char* custom_arg = NULL;
123 std::string json_string; 123 std::string json_string;
124 if (!custom_arg_value.empty()) { 124 if (!custom_arg_value.empty()) {
125 base::JSONWriter::Write(custom_arg_value, &json_string); 125 base::JSONWriter::Write(custom_arg_value, &json_string);
126 custom_arg = json_string.c_str(); 126 custom_arg = json_string.c_str();
127 } 127 }
128 128
129 base::AutoReset<base::FilePath> reset(&test_data_dir_, temp_dir.path()); 129 base::AutoReset<base::FilePath> reset(&test_data_dir_, temp_dir.GetPath());
130 bool result = RunPlatformAppTestWithArg(extension_name, custom_arg); 130 bool result = RunPlatformAppTestWithArg(extension_name, custom_arg);
131 content::RunAllPendingInMessageLoop(); // avoid race on exit in registry. 131 content::RunAllPendingInMessageLoop(); // avoid race on exit in registry.
132 return result; 132 return result;
133 } 133 }
134 134
135 void AttachFakeDevice() { 135 void AttachFakeDevice() {
136 device_id_ = StorageInfo::MakeDeviceId( 136 device_id_ = StorageInfo::MakeDeviceId(
137 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId); 137 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, kDeviceId);
138 138
139 StorageMonitor::GetInstance()->receiver()->ProcessAttach( 139 StorageMonitor::GetInstance()->receiver()->ProcessAttach(
(...skipping 23 matching lines...) Expand all
163 // This function makes a single fake gallery. This is needed to test platforms 163 // This function makes a single fake gallery. This is needed to test platforms
164 // with no default media galleries, such as CHROMEOS. This fake gallery is 164 // with no default media galleries, such as CHROMEOS. This fake gallery is
165 // pre-populated with a test.jpg and test.txt. 165 // pre-populated with a test.jpg and test.txt.
166 void MakeSingleFakeGallery(MediaGalleryPrefId* pref_id) { 166 void MakeSingleFakeGallery(MediaGalleryPrefId* pref_id) {
167 ASSERT_FALSE(fake_gallery_temp_dir_.IsValid()); 167 ASSERT_FALSE(fake_gallery_temp_dir_.IsValid());
168 ASSERT_TRUE(fake_gallery_temp_dir_.CreateUniqueTempDir()); 168 ASSERT_TRUE(fake_gallery_temp_dir_.CreateUniqueTempDir());
169 169
170 MediaGalleriesPreferences* preferences = GetAndInitializePreferences(); 170 MediaGalleriesPreferences* preferences = GetAndInitializePreferences();
171 171
172 MediaGalleryPrefInfo gallery_info; 172 MediaGalleryPrefInfo gallery_info;
173 ASSERT_FALSE(preferences->LookUpGalleryByPath(fake_gallery_temp_dir_.path(), 173 ASSERT_FALSE(preferences->LookUpGalleryByPath(
174 &gallery_info)); 174 fake_gallery_temp_dir_.GetPath(), &gallery_info));
175 MediaGalleryPrefId id = preferences->AddGallery( 175 MediaGalleryPrefId id = preferences->AddGallery(
176 gallery_info.device_id, 176 gallery_info.device_id,
177 gallery_info.path, 177 gallery_info.path,
178 MediaGalleryPrefInfo::kAutoDetected, 178 MediaGalleryPrefInfo::kAutoDetected,
179 gallery_info.volume_label, 179 gallery_info.volume_label,
180 gallery_info.vendor_name, 180 gallery_info.vendor_name,
181 gallery_info.model_name, 181 gallery_info.model_name,
182 gallery_info.total_size_in_bytes, 182 gallery_info.total_size_in_bytes,
183 gallery_info.last_attach_time, 183 gallery_info.last_attach_time,
184 0, 0, 0); 184 0, 0, 0);
185 if (pref_id) 185 if (pref_id)
186 *pref_id = id; 186 *pref_id = id;
187 187
188 content::RunAllPendingInMessageLoop(); 188 content::RunAllPendingInMessageLoop();
189 189
190 // Valid file, should show up in JS as a FileEntry. 190 // Valid file, should show up in JS as a FileEntry.
191 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.jpg")); 191 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.jpg"));
192 192
193 // Invalid file, should not show up as a FileEntry in JS at all. 193 // Invalid file, should not show up as a FileEntry in JS at all.
194 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.txt")); 194 AddFileToSingleFakeGallery(GetCommonDataDir().AppendASCII("test.txt"));
195 } 195 }
196 196
197 void AddFileToSingleFakeGallery(const base::FilePath& source_path) { 197 void AddFileToSingleFakeGallery(const base::FilePath& source_path) {
198 ASSERT_TRUE(fake_gallery_temp_dir_.IsValid()); 198 ASSERT_TRUE(fake_gallery_temp_dir_.IsValid());
199 199
200 ASSERT_TRUE(base::CopyFile( 200 ASSERT_TRUE(base::CopyFile(
201 source_path, 201 source_path,
202 fake_gallery_temp_dir_.path().Append(source_path.BaseName()))); 202 fake_gallery_temp_dir_.GetPath().Append(source_path.BaseName())));
203 } 203 }
204 204
205 #if defined(OS_WIN) || defined(OS_MACOSX) 205 #if defined(OS_WIN) || defined(OS_MACOSX)
206 void PopulatePicasaTestData(const base::FilePath& picasa_app_data_root) { 206 void PopulatePicasaTestData(const base::FilePath& picasa_app_data_root) {
207 base::FilePath picasa_database_path = 207 base::FilePath picasa_database_path =
208 picasa::MakePicasaDatabasePath(picasa_app_data_root); 208 picasa::MakePicasaDatabasePath(picasa_app_data_root);
209 base::FilePath picasa_temp_dir_path = 209 base::FilePath picasa_temp_dir_path =
210 picasa_database_path.DirName().AppendASCII(picasa::kPicasaTempDirName); 210 picasa_database_path.DirName().AppendASCII(picasa::kPicasaTempDirName);
211 ASSERT_TRUE(base::CreateDirectory(picasa_database_path)); 211 ASSERT_TRUE(base::CreateDirectory(picasa_database_path));
212 ASSERT_TRUE(base::CreateDirectory(picasa_temp_dir_path)); 212 ASSERT_TRUE(base::CreateDirectory(picasa_temp_dir_path));
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 457
458 base::ListValue custom_args; 458 base::ListValue custom_args;
459 #if defined(USE_PROPRIETARY_CODECS) 459 #if defined(USE_PROPRIETARY_CODECS)
460 custom_args.AppendBoolean(true); 460 custom_args.AppendBoolean(true);
461 #else 461 #else
462 custom_args.AppendBoolean(false); 462 custom_args.AppendBoolean(false);
463 #endif 463 #endif
464 ASSERT_TRUE(RunMediaGalleriesTestWithArg("media_metadata", custom_args)) 464 ASSERT_TRUE(RunMediaGalleriesTestWithArg("media_metadata", custom_args))
465 << message_; 465 << message_;
466 } 466 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698