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

Side by Side Diff: chrome/browser/media_galleries/gallery_watch_manager_unittest.cc

Issue 2318033002: c/browser, c/common, components M-N: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Fix ItunesFileUtilTest 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/gallery_watch_manager.h" 5 #include "chrome/browser/media_galleries/gallery_watch_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 bool expect_gallery_changed_; 193 bool expect_gallery_changed_;
194 bool expect_gallery_watch_dropped_; 194 bool expect_gallery_watch_dropped_;
195 base::RunLoop* pending_loop_; 195 base::RunLoop* pending_loop_;
196 196
197 DISALLOW_COPY_AND_ASSIGN(GalleryWatchManagerTest); 197 DISALLOW_COPY_AND_ASSIGN(GalleryWatchManagerTest);
198 }; 198 };
199 199
200 TEST_F(GalleryWatchManagerTest, Basic) { 200 TEST_F(GalleryWatchManagerTest, Basic) {
201 base::ScopedTempDir temp_dir; 201 base::ScopedTempDir temp_dir;
202 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 202 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
203 MediaGalleryPrefId id = AddGallery(temp_dir.path()); 203 MediaGalleryPrefId id = AddGallery(temp_dir.GetPath());
204 204
205 base::RunLoop loop; 205 base::RunLoop loop;
206 if (GalleryWatchesSupported()) { 206 if (GalleryWatchesSupported()) {
207 manager()->AddWatch(profile(), 207 manager()->AddWatch(profile(),
208 extension(), 208 extension(),
209 id, 209 id,
210 base::Bind(&ConfirmWatch, base::Unretained(&loop))); 210 base::Bind(&ConfirmWatch, base::Unretained(&loop)));
211 } else { 211 } else {
212 manager()->AddWatch( 212 manager()->AddWatch(
213 profile(), 213 profile(),
214 extension(), 214 extension(),
215 id, 215 id,
216 base::Bind(&ExpectWatchError, 216 base::Bind(&ExpectWatchError,
217 base::Unretained(&loop), 217 base::Unretained(&loop),
218 GalleryWatchManager::kCouldNotWatchGalleryError)); 218 GalleryWatchManager::kCouldNotWatchGalleryError));
219 } 219 }
220 loop.Run(); 220 loop.Run();
221 } 221 }
222 222
223 TEST_F(GalleryWatchManagerTest, AddAndRemoveTwoWatches) { 223 TEST_F(GalleryWatchManagerTest, AddAndRemoveTwoWatches) {
224 if (!GalleryWatchesSupported()) 224 if (!GalleryWatchesSupported())
225 return; 225 return;
226 226
227 EXPECT_TRUE(manager()->GetWatchSet(profile(), extension()->id()).empty()); 227 EXPECT_TRUE(manager()->GetWatchSet(profile(), extension()->id()).empty());
228 228
229 base::ScopedTempDir temp1; 229 base::ScopedTempDir temp1;
230 ASSERT_TRUE(temp1.CreateUniqueTempDir()); 230 ASSERT_TRUE(temp1.CreateUniqueTempDir());
231 MediaGalleryPrefId id1 = AddGallery(temp1.path()); 231 MediaGalleryPrefId id1 = AddGallery(temp1.GetPath());
232 232
233 base::ScopedTempDir temp2; 233 base::ScopedTempDir temp2;
234 ASSERT_TRUE(temp2.CreateUniqueTempDir()); 234 ASSERT_TRUE(temp2.CreateUniqueTempDir());
235 MediaGalleryPrefId id2 = AddGallery(temp2.path()); 235 MediaGalleryPrefId id2 = AddGallery(temp2.GetPath());
236 236
237 // Add first watch and test it was added correctly. 237 // Add first watch and test it was added correctly.
238 AddAndConfirmWatch(id1); 238 AddAndConfirmWatch(id1);
239 MediaGalleryPrefIdSet set1 = 239 MediaGalleryPrefIdSet set1 =
240 manager()->GetWatchSet(profile(), extension()->id()); 240 manager()->GetWatchSet(profile(), extension()->id());
241 EXPECT_EQ(1u, set1.size()); 241 EXPECT_EQ(1u, set1.size());
242 EXPECT_TRUE(base::ContainsKey(set1, id1)); 242 EXPECT_TRUE(base::ContainsKey(set1, id1));
243 243
244 // Test that the second watch was added correctly too. 244 // Test that the second watch was added correctly too.
245 AddAndConfirmWatch(id2); 245 AddAndConfirmWatch(id2);
(...skipping 18 matching lines...) Expand all
264 manager()->RemoveWatch(profile(), extension()->id(), id2); 264 manager()->RemoveWatch(profile(), extension()->id(), id2);
265 EXPECT_TRUE(manager()->GetWatchSet(profile(), extension()->id()).empty()); 265 EXPECT_TRUE(manager()->GetWatchSet(profile(), extension()->id()).empty());
266 } 266 }
267 267
268 TEST_F(GalleryWatchManagerTest, RemoveAllWatches) { 268 TEST_F(GalleryWatchManagerTest, RemoveAllWatches) {
269 if (!GalleryWatchesSupported()) 269 if (!GalleryWatchesSupported())
270 return; 270 return;
271 271
272 base::ScopedTempDir temp1; 272 base::ScopedTempDir temp1;
273 ASSERT_TRUE(temp1.CreateUniqueTempDir()); 273 ASSERT_TRUE(temp1.CreateUniqueTempDir());
274 MediaGalleryPrefId id1 = AddGallery(temp1.path()); 274 MediaGalleryPrefId id1 = AddGallery(temp1.GetPath());
275 275
276 base::ScopedTempDir temp2; 276 base::ScopedTempDir temp2;
277 ASSERT_TRUE(temp2.CreateUniqueTempDir()); 277 ASSERT_TRUE(temp2.CreateUniqueTempDir());
278 MediaGalleryPrefId id2 = AddGallery(temp2.path()); 278 MediaGalleryPrefId id2 = AddGallery(temp2.GetPath());
279 279
280 // Add watches. 280 // Add watches.
281 AddAndConfirmWatch(id1); 281 AddAndConfirmWatch(id1);
282 AddAndConfirmWatch(id2); 282 AddAndConfirmWatch(id2);
283 283
284 EXPECT_EQ(2u, manager()->GetWatchSet(profile(), extension()->id()).size()); 284 EXPECT_EQ(2u, manager()->GetWatchSet(profile(), extension()->id()).size());
285 285
286 // RemoveAllWatches using a different extension ID and verify watches remain. 286 // RemoveAllWatches using a different extension ID and verify watches remain.
287 manager()->RemoveAllWatches(profile(), "OtherExtensionId"); 287 manager()->RemoveAllWatches(profile(), "OtherExtensionId");
288 EXPECT_EQ(2u, manager()->GetWatchSet(profile(), extension()->id()).size()); 288 EXPECT_EQ(2u, manager()->GetWatchSet(profile(), extension()->id()).size());
289 289
290 // RemoveAllWatches using the correct extension ID and verify watches gone. 290 // RemoveAllWatches using the correct extension ID and verify watches gone.
291 291
292 manager()->RemoveAllWatches(profile(), extension()->id()); 292 manager()->RemoveAllWatches(profile(), extension()->id());
293 EXPECT_TRUE(manager()->GetWatchSet(profile(), extension()->id()).empty()); 293 EXPECT_TRUE(manager()->GetWatchSet(profile(), extension()->id()).empty());
294 } 294 }
295 295
296 TEST_F(GalleryWatchManagerTest, DropWatchOnGalleryRemoved) { 296 TEST_F(GalleryWatchManagerTest, DropWatchOnGalleryRemoved) {
297 if (!GalleryWatchesSupported()) 297 if (!GalleryWatchesSupported())
298 return; 298 return;
299 299
300 base::ScopedTempDir temp_dir; 300 base::ScopedTempDir temp_dir;
301 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 301 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
302 MediaGalleryPrefId id = AddGallery(temp_dir.path()); 302 MediaGalleryPrefId id = AddGallery(temp_dir.GetPath());
303 AddAndConfirmWatch(id); 303 AddAndConfirmWatch(id);
304 304
305 base::RunLoop success_loop; 305 base::RunLoop success_loop;
306 ExpectGalleryWatchDropped(&success_loop); 306 ExpectGalleryWatchDropped(&success_loop);
307 gallery_prefs()->EraseGalleryById(id); 307 gallery_prefs()->EraseGalleryById(id);
308 success_loop.Run(); 308 success_loop.Run();
309 } 309 }
310 310
311 TEST_F(GalleryWatchManagerTest, DropWatchOnGalleryPermissionRevoked) { 311 TEST_F(GalleryWatchManagerTest, DropWatchOnGalleryPermissionRevoked) {
312 if (!GalleryWatchesSupported()) 312 if (!GalleryWatchesSupported())
313 return; 313 return;
314 314
315 base::ScopedTempDir temp_dir; 315 base::ScopedTempDir temp_dir;
316 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 316 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
317 MediaGalleryPrefId id = AddGallery(temp_dir.path()); 317 MediaGalleryPrefId id = AddGallery(temp_dir.GetPath());
318 AddAndConfirmWatch(id); 318 AddAndConfirmWatch(id);
319 319
320 base::RunLoop success_loop; 320 base::RunLoop success_loop;
321 ExpectGalleryWatchDropped(&success_loop); 321 ExpectGalleryWatchDropped(&success_loop);
322 gallery_prefs()->SetGalleryPermissionForExtension(*extension(), id, false); 322 gallery_prefs()->SetGalleryPermissionForExtension(*extension(), id, false);
323 success_loop.Run(); 323 success_loop.Run();
324 } 324 }
325 325
326 TEST_F(GalleryWatchManagerTest, DropWatchOnStorageRemoved) { 326 TEST_F(GalleryWatchManagerTest, DropWatchOnStorageRemoved) {
327 if (!GalleryWatchesSupported()) 327 if (!GalleryWatchesSupported())
328 return; 328 return;
329 329
330 // Create a temporary directory and treat is as a removable storage device. 330 // Create a temporary directory and treat is as a removable storage device.
331 base::ScopedTempDir temp_dir; 331 base::ScopedTempDir temp_dir;
332 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 332 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
333 storage_monitor()->AddRemovablePath(temp_dir.path()); 333 storage_monitor()->AddRemovablePath(temp_dir.GetPath());
334 storage_monitor::StorageInfo storage_info; 334 storage_monitor::StorageInfo storage_info;
335 ASSERT_TRUE( 335 ASSERT_TRUE(storage_monitor()->GetStorageInfoForPath(temp_dir.GetPath(),
336 storage_monitor()->GetStorageInfoForPath(temp_dir.path(), &storage_info)); 336 &storage_info));
337 storage_monitor()->receiver()->ProcessAttach(storage_info); 337 storage_monitor()->receiver()->ProcessAttach(storage_info);
338 338
339 MediaGalleryPrefId id = AddGallery(temp_dir.path()); 339 MediaGalleryPrefId id = AddGallery(temp_dir.GetPath());
340 AddAndConfirmWatch(id); 340 AddAndConfirmWatch(id);
341 341
342 base::RunLoop success_loop; 342 base::RunLoop success_loop;
343 ExpectGalleryWatchDropped(&success_loop); 343 ExpectGalleryWatchDropped(&success_loop);
344 storage_monitor()->receiver()->ProcessDetach(storage_info.device_id()); 344 storage_monitor()->receiver()->ProcessDetach(storage_info.device_id());
345 success_loop.Run(); 345 success_loop.Run();
346 } 346 }
347 347
348 TEST_F(GalleryWatchManagerTest, TestWatchOperation) { 348 TEST_F(GalleryWatchManagerTest, TestWatchOperation) {
349 if (!GalleryWatchesSupported()) 349 if (!GalleryWatchesSupported())
350 return; 350 return;
351 351
352 base::ScopedTempDir temp_dir; 352 base::ScopedTempDir temp_dir;
353 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 353 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
354 MediaGalleryPrefId id = AddGallery(temp_dir.path()); 354 MediaGalleryPrefId id = AddGallery(temp_dir.GetPath());
355 AddAndConfirmWatch(id); 355 AddAndConfirmWatch(id);
356 356
357 base::RunLoop success_loop; 357 base::RunLoop success_loop;
358 ExpectGalleryChanged(&success_loop); 358 ExpectGalleryChanged(&success_loop);
359 ASSERT_EQ( 359 ASSERT_EQ(4, base::WriteFile(temp_dir.GetPath().AppendASCII("fake file"),
360 4, base::WriteFile(temp_dir.path().AppendASCII("fake file"), "blah", 4)); 360 "blah", 4));
361 success_loop.Run(); 361 success_loop.Run();
362 } 362 }
363 363
364 TEST_F(GalleryWatchManagerTest, TestWatchOperationAfterProfileShutdown) { 364 TEST_F(GalleryWatchManagerTest, TestWatchOperationAfterProfileShutdown) {
365 if (!GalleryWatchesSupported()) 365 if (!GalleryWatchesSupported())
366 return; 366 return;
367 367
368 base::ScopedTempDir temp_dir; 368 base::ScopedTempDir temp_dir;
369 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 369 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
370 MediaGalleryPrefId id = AddGallery(temp_dir.path()); 370 MediaGalleryPrefId id = AddGallery(temp_dir.GetPath());
371 AddAndConfirmWatch(id); 371 AddAndConfirmWatch(id);
372 372
373 ShutdownProfile(); 373 ShutdownProfile();
374 374
375 // Trigger a watch that should have been removed when the profile was 375 // Trigger a watch that should have been removed when the profile was
376 // destroyed to catch regressions. crbug.com/467627 376 // destroyed to catch regressions. crbug.com/467627
377 base::RunLoop run_loop; 377 base::RunLoop run_loop;
378 ASSERT_EQ( 378 ASSERT_EQ(4, base::WriteFile(temp_dir.GetPath().AppendASCII("fake file"),
379 4, base::WriteFile(temp_dir.path().AppendASCII("fake file"), "blah", 4)); 379 "blah", 4));
380 run_loop.RunUntilIdle(); 380 run_loop.RunUntilIdle();
381 } 381 }
382 382
383 TEST_F(GalleryWatchManagerTest, TestStorageRemovedAfterProfileShutdown) { 383 TEST_F(GalleryWatchManagerTest, TestStorageRemovedAfterProfileShutdown) {
384 if (!GalleryWatchesSupported()) 384 if (!GalleryWatchesSupported())
385 return; 385 return;
386 386
387 // Create a temporary directory and treat is as a removable storage device. 387 // Create a temporary directory and treat is as a removable storage device.
388 base::ScopedTempDir temp_dir; 388 base::ScopedTempDir temp_dir;
389 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 389 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
390 storage_monitor()->AddRemovablePath(temp_dir.path()); 390 storage_monitor()->AddRemovablePath(temp_dir.GetPath());
391 storage_monitor::StorageInfo storage_info; 391 storage_monitor::StorageInfo storage_info;
392 ASSERT_TRUE( 392 ASSERT_TRUE(storage_monitor()->GetStorageInfoForPath(temp_dir.GetPath(),
393 storage_monitor()->GetStorageInfoForPath(temp_dir.path(), &storage_info)); 393 &storage_info));
394 storage_monitor()->receiver()->ProcessAttach(storage_info); 394 storage_monitor()->receiver()->ProcessAttach(storage_info);
395 395
396 MediaGalleryPrefId id = AddGallery(temp_dir.path()); 396 MediaGalleryPrefId id = AddGallery(temp_dir.GetPath());
397 AddAndConfirmWatch(id); 397 AddAndConfirmWatch(id);
398 398
399 ShutdownProfile(); 399 ShutdownProfile();
400 400
401 // Trigger a removable storage event that should be ignored now that the 401 // Trigger a removable storage event that should be ignored now that the
402 // profile has been destroyed to catch regressions. crbug.com/467627 402 // profile has been destroyed to catch regressions. crbug.com/467627
403 base::RunLoop run_loop; 403 base::RunLoop run_loop;
404 storage_monitor()->receiver()->ProcessDetach(storage_info.device_id()); 404 storage_monitor()->receiver()->ProcessDetach(storage_info.device_id());
405 run_loop.RunUntilIdle(); 405 run_loop.RunUntilIdle();
406 } 406 }
407 407
408 } // namespace component_updater 408 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698