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

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

Issue 15294020: StorageMonitor: Make StorageInfo a real class. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address nits Created 7 years, 7 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 | Annotate | Revision Log
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 // MediaGalleriesPreferences unit tests. 5 // MediaGalleriesPreferences unit tests.
6 6
7 #include "chrome/browser/media_galleries/media_galleries_preferences.h" 7 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 TEST_F(MediaGalleriesPreferencesTest, GalleryManagement) { 244 TEST_F(MediaGalleriesPreferencesTest, GalleryManagement) {
245 MediaGalleryPrefId auto_id, user_added_id, id; 245 MediaGalleryPrefId auto_id, user_added_id, id;
246 base::FilePath path; 246 base::FilePath path;
247 base::FilePath relative_path; 247 base::FilePath relative_path;
248 Verify(); 248 Verify();
249 249
250 // Add a new auto detected gallery. 250 // Add a new auto detected gallery.
251 path = MakePath("new_auto"); 251 path = MakePath("new_auto");
252 StorageInfo info; 252 StorageInfo info;
253 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 253 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
254 info.name = ASCIIToUTF16("NewAutoGallery"); 254 info.set_name(ASCIIToUTF16("NewAutoGallery"));
255 id = gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 255 id = gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
256 relative_path, false /*auto*/); 256 relative_path, false /*auto*/);
257 EXPECT_EQ(default_galleries_count() + 1UL, id); 257 EXPECT_EQ(default_galleries_count() + 1UL, id);
258 auto_id = id; 258 auto_id = id;
259 AddGalleryExpectation(id, info.name, info.device_id, relative_path, 259 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
260 MediaGalleryPrefInfo::kAutoDetected); 260 MediaGalleryPrefInfo::kAutoDetected);
261 Verify(); 261 Verify();
262 262
263 // Add it again (as user), nothing should happen. 263 // Add it again (as user), nothing should happen.
264 id = gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 264 id = gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
265 relative_path, true /*auto*/); 265 relative_path, true /*auto*/);
266 EXPECT_EQ(auto_id, id); 266 EXPECT_EQ(auto_id, id);
267 Verify(); 267 Verify();
268 268
269 // Add a new user added gallery. 269 // Add a new user added gallery.
270 path = MakePath("new_user"); 270 path = MakePath("new_user");
271 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 271 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
272 info.name = ASCIIToUTF16("NewUserGallery"); 272 info.set_name(ASCIIToUTF16("NewUserGallery"));
273 id = gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 273 id = gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
274 relative_path, true /*user*/); 274 relative_path, true /*user*/);
275 EXPECT_EQ(default_galleries_count() + 2UL, id); 275 EXPECT_EQ(default_galleries_count() + 2UL, id);
276 user_added_id = id; 276 user_added_id = id;
277 AddGalleryExpectation(id, info.name, info.device_id, relative_path, 277 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
278 MediaGalleryPrefInfo::kUserAdded); 278 MediaGalleryPrefInfo::kUserAdded);
279 Verify(); 279 Verify();
280 280
281 // Lookup some galleries. 281 // Lookup some galleries.
282 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"), NULL)); 282 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"), NULL));
283 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_user"), NULL)); 283 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_user"), NULL));
284 EXPECT_FALSE(gallery_prefs()->LookUpGalleryByPath(MakePath("other"), NULL)); 284 EXPECT_FALSE(gallery_prefs()->LookUpGalleryByPath(MakePath("other"), NULL));
285 285
286 // Check that we always get the gallery info. 286 // Check that we always get the gallery info.
287 MediaGalleryPrefInfo gallery_info; 287 MediaGalleryPrefInfo gallery_info;
288 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"), 288 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"),
289 &gallery_info)); 289 &gallery_info));
290 VerifyGalleryInfo(gallery_info, auto_id); 290 VerifyGalleryInfo(gallery_info, auto_id);
291 EXPECT_FALSE(gallery_info.volume_metadata_valid); 291 EXPECT_FALSE(gallery_info.volume_metadata_valid);
292 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_user"), 292 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_user"),
293 &gallery_info)); 293 &gallery_info));
294 VerifyGalleryInfo(gallery_info, user_added_id); 294 VerifyGalleryInfo(gallery_info, user_added_id);
295 EXPECT_FALSE(gallery_info.volume_metadata_valid); 295 EXPECT_FALSE(gallery_info.volume_metadata_valid);
296 296
297 path = MakePath("other"); 297 path = MakePath("other");
298 EXPECT_FALSE(gallery_prefs()->LookUpGalleryByPath(path, &gallery_info)); 298 EXPECT_FALSE(gallery_prefs()->LookUpGalleryByPath(path, &gallery_info));
299 EXPECT_EQ(kInvalidMediaGalleryPrefId, gallery_info.pref_id); 299 EXPECT_EQ(kInvalidMediaGalleryPrefId, gallery_info.pref_id);
300 EXPECT_EQ(path.BaseName().LossyDisplayName(), gallery_info.display_name); 300 EXPECT_EQ(path.BaseName().LossyDisplayName(), gallery_info.display_name);
301 StorageInfo other_info; 301 StorageInfo other_info;
302 MediaStorageUtil::GetDeviceInfoFromPath(path, &other_info, &relative_path); 302 MediaStorageUtil::GetDeviceInfoFromPath(path, &other_info, &relative_path);
303 EXPECT_EQ(other_info.device_id, gallery_info.device_id); 303 EXPECT_EQ(other_info.device_id(), gallery_info.device_id);
304 EXPECT_EQ(relative_path.value(), gallery_info.path.value()); 304 EXPECT_EQ(relative_path.value(), gallery_info.path.value());
305 305
306 // Remove an auto added gallery (i.e. make it blacklisted). 306 // Remove an auto added gallery (i.e. make it blacklisted).
307 gallery_prefs()->ForgetGalleryById(auto_id); 307 gallery_prefs()->ForgetGalleryById(auto_id);
308 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed; 308 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed;
309 expected_galleries_for_all.erase(auto_id); 309 expected_galleries_for_all.erase(auto_id);
310 Verify(); 310 Verify();
311 311
312 // Remove a user added gallery and it should go away. 312 // Remove a user added gallery and it should go away.
313 gallery_prefs()->ForgetGalleryById(user_added_id); 313 gallery_prefs()->ForgetGalleryById(user_added_id);
314 expected_galleries_.erase(user_added_id); 314 expected_galleries_.erase(user_added_id);
315 expected_device_map[info.device_id].erase(user_added_id); 315 expected_device_map[info.device_id()].erase(user_added_id);
316 Verify(); 316 Verify();
317 } 317 }
318 318
319 TEST_F(MediaGalleriesPreferencesTest, AddGalleryWithVolumeMetadata) { 319 TEST_F(MediaGalleriesPreferencesTest, AddGalleryWithVolumeMetadata) {
320 MediaGalleryPrefId id; 320 MediaGalleryPrefId id;
321 StorageInfo info; 321 StorageInfo info;
322 base::FilePath path; 322 base::FilePath path;
323 base::FilePath relative_path; 323 base::FilePath relative_path;
324 base::Time now = base::Time::Now(); 324 base::Time now = base::Time::Now();
325 Verify(); 325 Verify();
326 326
327 // Add a new auto detected gallery. 327 // Add a new auto detected gallery.
328 path = MakePath("new_auto"); 328 path = MakePath("new_auto");
329 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 329 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
330 id = gallery_prefs()->AddGallery(info.device_id, relative_path, 330 id = gallery_prefs()->AddGallery(info.device_id(), relative_path,
331 false /*auto*/, 331 false /*auto*/,
332 ASCIIToUTF16("volume label"), 332 ASCIIToUTF16("volume label"),
333 ASCIIToUTF16("vendor name"), 333 ASCIIToUTF16("vendor name"),
334 ASCIIToUTF16("model name"), 334 ASCIIToUTF16("model name"),
335 1000000ULL, now); 335 1000000ULL, now);
336 EXPECT_EQ(default_galleries_count() + 1UL, id); 336 EXPECT_EQ(default_galleries_count() + 1UL, id);
337 AddGalleryExpectation(id, string16(), info.device_id, relative_path, 337 AddGalleryExpectation(id, string16(), info.device_id(), relative_path,
338 MediaGalleryPrefInfo::kAutoDetected); 338 MediaGalleryPrefInfo::kAutoDetected);
339 Verify(); 339 Verify();
340 340
341 MediaGalleryPrefInfo gallery_info; 341 MediaGalleryPrefInfo gallery_info;
342 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"), 342 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"),
343 &gallery_info)); 343 &gallery_info));
344 EXPECT_TRUE(gallery_info.volume_metadata_valid); 344 EXPECT_TRUE(gallery_info.volume_metadata_valid);
345 EXPECT_EQ(ASCIIToUTF16("volume label"), gallery_info.volume_label); 345 EXPECT_EQ(ASCIIToUTF16("volume label"), gallery_info.volume_label);
346 EXPECT_EQ(ASCIIToUTF16("vendor name"), gallery_info.vendor_name); 346 EXPECT_EQ(ASCIIToUTF16("vendor name"), gallery_info.vendor_name);
347 EXPECT_EQ(ASCIIToUTF16("model name"), gallery_info.model_name); 347 EXPECT_EQ(ASCIIToUTF16("model name"), gallery_info.model_name);
348 EXPECT_EQ(1000000ULL, gallery_info.total_size_in_bytes); 348 EXPECT_EQ(1000000ULL, gallery_info.total_size_in_bytes);
349 // Note: we put the microseconds time into a double, so there'll 349 // Note: we put the microseconds time into a double, so there'll
350 // be some possible rounding errors. If it's less than 100, we don't 350 // be some possible rounding errors. If it's less than 100, we don't
351 // care. 351 // care.
352 EXPECT_LE(abs(now.ToInternalValue() - 352 EXPECT_LE(abs(now.ToInternalValue() -
353 gallery_info.last_attach_time.ToInternalValue()), 100); 353 gallery_info.last_attach_time.ToInternalValue()), 100);
354 } 354 }
355 355
356 TEST_F(MediaGalleriesPreferencesTest, ReplaceGalleryWithVolumeMetadata) { 356 TEST_F(MediaGalleriesPreferencesTest, ReplaceGalleryWithVolumeMetadata) {
357 MediaGalleryPrefId id, metadata_id; 357 MediaGalleryPrefId id, metadata_id;
358 base::FilePath path; 358 base::FilePath path;
359 StorageInfo info; 359 StorageInfo info;
360 base::FilePath relative_path; 360 base::FilePath relative_path;
361 base::Time now = base::Time::Now(); 361 base::Time now = base::Time::Now();
362 Verify(); 362 Verify();
363 363
364 // Add an auto detected gallery in the prefs version 0 format. 364 // Add an auto detected gallery in the prefs version 0 format.
365 path = MakePath("new_auto"); 365 path = MakePath("new_auto");
366 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 366 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
367 info.name = ASCIIToUTF16("NewAutoGallery"); 367 info.set_name(ASCIIToUTF16("NewAutoGallery"));
368 id = AddGalleryWithNameV0(info.device_id, info.name, 368 id = AddGalleryWithNameV0(info.device_id(), info.name(),
369 relative_path, false /*auto*/); 369 relative_path, false /*auto*/);
370 EXPECT_EQ(default_galleries_count() + 1UL, id); 370 EXPECT_EQ(default_galleries_count() + 1UL, id);
371 AddGalleryExpectation(id, info.name, info.device_id, relative_path, 371 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
372 MediaGalleryPrefInfo::kAutoDetected); 372 MediaGalleryPrefInfo::kAutoDetected);
373 Verify(); 373 Verify();
374 374
375 metadata_id = gallery_prefs()->AddGallery(info.device_id, 375 metadata_id = gallery_prefs()->AddGallery(info.device_id(),
376 relative_path, 376 relative_path,
377 false /*auto*/, 377 false /*auto*/,
378 ASCIIToUTF16("volume label"), 378 ASCIIToUTF16("volume label"),
379 ASCIIToUTF16("vendor name"), 379 ASCIIToUTF16("vendor name"),
380 ASCIIToUTF16("model name"), 380 ASCIIToUTF16("model name"),
381 1000000ULL, now); 381 1000000ULL, now);
382 EXPECT_EQ(id, metadata_id); 382 EXPECT_EQ(id, metadata_id);
383 AddGalleryExpectation(id, string16(), info.device_id, relative_path, 383 AddGalleryExpectation(id, string16(), info.device_id(), relative_path,
384 MediaGalleryPrefInfo::kAutoDetected); 384 MediaGalleryPrefInfo::kAutoDetected);
385 385
386 // Make sure the display_name is set to empty now, as the metadata 386 // Make sure the display_name is set to empty now, as the metadata
387 // upgrade should set the manual override name empty. 387 // upgrade should set the manual override name empty.
388 Verify(); 388 Verify();
389 } 389 }
390 390
391 391
392 // Whenever a gallery is added, its type is either set to "AutoDetected" or 392 // Whenever a gallery is added, its type is either set to "AutoDetected" or
393 // "UserAdded". When the gallery is removed, user added galleries are actually 393 // "UserAdded". When the gallery is removed, user added galleries are actually
394 // deleted and the auto detected galleries are moved to black listed state. 394 // deleted and the auto detected galleries are moved to black listed state.
395 // When the gallery is added again, the black listed state is updated back to 395 // When the gallery is added again, the black listed state is updated back to
396 // "AutoDetected" type. 396 // "AutoDetected" type.
397 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryType) { 397 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryType) {
398 MediaGalleryPrefId auto_id, id; 398 MediaGalleryPrefId auto_id, id;
399 base::FilePath path; 399 base::FilePath path;
400 StorageInfo info; 400 StorageInfo info;
401 base::FilePath relative_path; 401 base::FilePath relative_path;
402 Verify(); 402 Verify();
403 403
404 // Add a new auto detect gallery to test with. 404 // Add a new auto detect gallery to test with.
405 path = MakePath("new_auto"); 405 path = MakePath("new_auto");
406 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 406 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
407 info.name = ASCIIToUTF16("NewAutoGallery"); 407 info.set_name(ASCIIToUTF16("NewAutoGallery"));
408 id = gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 408 id = gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
409 relative_path, false /*auto*/); 409 relative_path, false /*auto*/);
410 EXPECT_EQ(default_galleries_count() + 1UL, id); 410 EXPECT_EQ(default_galleries_count() + 1UL, id);
411 auto_id = id; 411 auto_id = id;
412 AddGalleryExpectation(id, info.name, info.device_id, relative_path, 412 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
413 MediaGalleryPrefInfo::kAutoDetected); 413 MediaGalleryPrefInfo::kAutoDetected);
414 Verify(); 414 Verify();
415 415
416 // Remove an auto added gallery (i.e. make it blacklisted). 416 // Remove an auto added gallery (i.e. make it blacklisted).
417 gallery_prefs()->ForgetGalleryById(auto_id); 417 gallery_prefs()->ForgetGalleryById(auto_id);
418 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed; 418 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed;
419 expected_galleries_for_all.erase(auto_id); 419 expected_galleries_for_all.erase(auto_id);
420 Verify(); 420 Verify();
421 421
422 // Add the gallery again as a user action. 422 // Add the gallery again as a user action.
423 id = gallery_prefs()->AddGalleryByPath(path); 423 id = gallery_prefs()->AddGalleryByPath(path);
424 EXPECT_EQ(auto_id, id); 424 EXPECT_EQ(auto_id, id);
425 AddGalleryExpectation(id, info.name, info.device_id, relative_path, 425 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
426 MediaGalleryPrefInfo::kAutoDetected); 426 MediaGalleryPrefInfo::kAutoDetected);
427 Verify(); 427 Verify();
428 428
429 // Remove an auto added gallery (i.e. make it blacklisted). 429 // Remove an auto added gallery (i.e. make it blacklisted).
430 gallery_prefs()->ForgetGalleryById(auto_id); 430 gallery_prefs()->ForgetGalleryById(auto_id);
431 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed; 431 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed;
432 expected_galleries_for_all.erase(auto_id); 432 expected_galleries_for_all.erase(auto_id);
433 Verify(); 433 Verify();
434 434
435 // Try adding the gallery again automatically and it should be a no-op. 435 // Try adding the gallery again automatically and it should be a no-op.
436 id = gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 436 id = gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
437 relative_path, false /*auto*/); 437 relative_path, false /*auto*/);
438 EXPECT_EQ(auto_id, id); 438 EXPECT_EQ(auto_id, id);
439 Verify(); 439 Verify();
440 } 440 }
441 441
442 TEST_F(MediaGalleriesPreferencesTest, GalleryPermissions) { 442 TEST_F(MediaGalleriesPreferencesTest, GalleryPermissions) {
443 MediaGalleryPrefId auto_id, user_added_id, to_blacklist_id, id; 443 MediaGalleryPrefId auto_id, user_added_id, to_blacklist_id, id;
444 base::FilePath path; 444 base::FilePath path;
445 StorageInfo info; 445 StorageInfo info;
446 base::FilePath relative_path; 446 base::FilePath relative_path;
447 Verify(); 447 Verify();
448 448
449 // Add some galleries to test with. 449 // Add some galleries to test with.
450 path = MakePath("new_user"); 450 path = MakePath("new_user");
451 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 451 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
452 info.name = ASCIIToUTF16("NewUserGallery"); 452 info.set_name(ASCIIToUTF16("NewUserGallery"));
453 id = gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 453 id = gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
454 relative_path, true /*user*/); 454 relative_path, true /*user*/);
455 EXPECT_EQ(default_galleries_count() + 1UL, id); 455 EXPECT_EQ(default_galleries_count() + 1UL, id);
456 user_added_id = id; 456 user_added_id = id;
457 AddGalleryExpectation(id, info.name, info.device_id, relative_path, 457 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
458 MediaGalleryPrefInfo::kUserAdded); 458 MediaGalleryPrefInfo::kUserAdded);
459 Verify(); 459 Verify();
460 460
461 path = MakePath("new_auto"); 461 path = MakePath("new_auto");
462 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 462 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
463 info.name = ASCIIToUTF16("NewAutoGallery"); 463 info.set_name(ASCIIToUTF16("NewAutoGallery"));
464 id = gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 464 id = gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
465 relative_path, false /*auto*/); 465 relative_path, false /*auto*/);
466 EXPECT_EQ(default_galleries_count() + 2UL, id); 466 EXPECT_EQ(default_galleries_count() + 2UL, id);
467 auto_id = id; 467 auto_id = id;
468 AddGalleryExpectation(id, info.name, info.device_id, relative_path, 468 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
469 MediaGalleryPrefInfo::kAutoDetected); 469 MediaGalleryPrefInfo::kAutoDetected);
470 Verify(); 470 Verify();
471 471
472 path = MakePath("to_blacklist"); 472 path = MakePath("to_blacklist");
473 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 473 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
474 info.name = ASCIIToUTF16("ToBlacklistGallery"); 474 info.set_name(ASCIIToUTF16("ToBlacklistGallery"));
475 id = gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 475 id = gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
476 relative_path, false /*auto*/); 476 relative_path, false /*auto*/);
477 EXPECT_EQ(default_galleries_count() + 3UL, id); 477 EXPECT_EQ(default_galleries_count() + 3UL, id);
478 to_blacklist_id = id; 478 to_blacklist_id = id;
479 AddGalleryExpectation(id, info.name, info.device_id, relative_path, 479 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
480 MediaGalleryPrefInfo::kAutoDetected); 480 MediaGalleryPrefInfo::kAutoDetected);
481 Verify(); 481 Verify();
482 482
483 // Remove permission for all galleries from the all-permission extension. 483 // Remove permission for all galleries from the all-permission extension.
484 gallery_prefs()->SetGalleryPermissionForExtension( 484 gallery_prefs()->SetGalleryPermissionForExtension(
485 *all_permission_extension.get(), auto_id, false); 485 *all_permission_extension.get(), auto_id, false);
486 expected_galleries_for_all.erase(auto_id); 486 expected_galleries_for_all.erase(auto_id);
487 Verify(); 487 Verify();
488 488
489 gallery_prefs()->SetGalleryPermissionForExtension( 489 gallery_prefs()->SetGalleryPermissionForExtension(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryDetails) { 560 TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryDetails) {
561 MediaGalleryPrefId auto_id, id; 561 MediaGalleryPrefId auto_id, id;
562 base::FilePath path; 562 base::FilePath path;
563 StorageInfo info; 563 StorageInfo info;
564 base::FilePath relative_path; 564 base::FilePath relative_path;
565 Verify(); 565 Verify();
566 566
567 // Add a new auto detect gallery to test with. 567 // Add a new auto detect gallery to test with.
568 path = MakePath("new_auto"); 568 path = MakePath("new_auto");
569 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 569 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
570 info.name = ASCIIToUTF16("NewAutoGallery"); 570 info.set_name(ASCIIToUTF16("NewAutoGallery"));
571 id = gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 571 id = gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
572 relative_path, false /*auto*/); 572 relative_path, false /*auto*/);
573 EXPECT_EQ(default_galleries_count() + 1UL, id); 573 EXPECT_EQ(default_galleries_count() + 1UL, id);
574 auto_id = id; 574 auto_id = id;
575 AddGalleryExpectation(id, info.name, info.device_id, relative_path, 575 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
576 MediaGalleryPrefInfo::kAutoDetected); 576 MediaGalleryPrefInfo::kAutoDetected);
577 Verify(); 577 Verify();
578 578
579 // Update the device name and add the gallery again. 579 // Update the device name and add the gallery again.
580 info.name = ASCIIToUTF16("AutoGallery2"); 580 info.set_name(ASCIIToUTF16("AutoGallery2"));
581 id = gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 581 id = gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
582 relative_path, false /*auto*/); 582 relative_path, false /*auto*/);
583 EXPECT_EQ(auto_id, id); 583 EXPECT_EQ(auto_id, id);
584 AddGalleryExpectation(id, info.name, info.device_id, relative_path, 584 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
585 MediaGalleryPrefInfo::kAutoDetected); 585 MediaGalleryPrefInfo::kAutoDetected);
586 Verify(); 586 Verify();
587 } 587 }
588 588
589 TEST_F(MediaGalleriesPreferencesTest, MultipleGalleriesPerDevices) { 589 TEST_F(MediaGalleriesPreferencesTest, MultipleGalleriesPerDevices) {
590 base::FilePath path; 590 base::FilePath path;
591 StorageInfo info; 591 StorageInfo info;
592 base::FilePath relative_path; 592 base::FilePath relative_path;
593 Verify(); 593 Verify();
594 594
595 // Add a regular gallery 595 // Add a regular gallery
596 path = MakePath("new_user"); 596 path = MakePath("new_user");
597 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 597 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
598 info.name = ASCIIToUTF16("NewUserGallery"); 598 info.set_name(ASCIIToUTF16("NewUserGallery"));
599 MediaGalleryPrefId user_added_id = 599 MediaGalleryPrefId user_added_id =
600 gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 600 gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
601 relative_path, 601 relative_path,
602 true /*user*/); 602 true /*user*/);
603 EXPECT_EQ(default_galleries_count() + 1UL, user_added_id); 603 EXPECT_EQ(default_galleries_count() + 1UL, user_added_id);
604 AddGalleryExpectation(user_added_id, info.name, info.device_id, 604 AddGalleryExpectation(user_added_id, info.name(), info.device_id(),
605 relative_path, MediaGalleryPrefInfo::kUserAdded); 605 relative_path, MediaGalleryPrefInfo::kUserAdded);
606 Verify(); 606 Verify();
607 607
608 // Find it by device id and fail to find something related. 608 // Find it by device id and fail to find something related.
609 MediaGalleryPrefIdSet pref_id_set; 609 MediaGalleryPrefIdSet pref_id_set;
610 pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id); 610 pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id());
611 EXPECT_EQ(1U, pref_id_set.size()); 611 EXPECT_EQ(1U, pref_id_set.size());
612 EXPECT_TRUE(pref_id_set.find(user_added_id) != pref_id_set.end()); 612 EXPECT_TRUE(pref_id_set.find(user_added_id) != pref_id_set.end());
613 613
614 MediaStorageUtil::GetDeviceInfoFromPath(MakePath("new_user/foo"), &info, 614 MediaStorageUtil::GetDeviceInfoFromPath(MakePath("new_user/foo"), &info,
615 &relative_path); 615 &relative_path);
616 pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id); 616 pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id());
617 EXPECT_EQ(0U, pref_id_set.size()); 617 EXPECT_EQ(0U, pref_id_set.size());
618 618
619 // Add some galleries on the same device. 619 // Add some galleries on the same device.
620 relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device1")); 620 relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device1"));
621 info.name = ASCIIToUTF16("Device1Path1"); 621 info.set_name(ASCIIToUTF16("Device1Path1"));
622 std::string device_id = "path:device1"; 622 std::string device_id = "path:device1";
623 MediaGalleryPrefId dev1_path1_id = gallery_prefs()->AddGalleryWithName( 623 MediaGalleryPrefId dev1_path1_id = gallery_prefs()->AddGalleryWithName(
624 device_id, info.name, relative_path, true /*user*/); 624 device_id, info.name(), relative_path, true /*user*/);
625 EXPECT_EQ(default_galleries_count() + 2UL, dev1_path1_id); 625 EXPECT_EQ(default_galleries_count() + 2UL, dev1_path1_id);
626 AddGalleryExpectation(dev1_path1_id, info.name, device_id, relative_path, 626 AddGalleryExpectation(dev1_path1_id, info.name(), device_id, relative_path,
627 MediaGalleryPrefInfo::kUserAdded); 627 MediaGalleryPrefInfo::kUserAdded);
628 Verify(); 628 Verify();
629 629
630 relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device1")); 630 relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device1"));
631 info.name = ASCIIToUTF16("Device1Path2"); 631 info.set_name(ASCIIToUTF16("Device1Path2"));
632 MediaGalleryPrefId dev1_path2_id = gallery_prefs()->AddGalleryWithName( 632 MediaGalleryPrefId dev1_path2_id = gallery_prefs()->AddGalleryWithName(
633 device_id, info.name, relative_path, true /*user*/); 633 device_id, info.name(), relative_path, true /*user*/);
634 EXPECT_EQ(default_galleries_count() + 3UL, dev1_path2_id); 634 EXPECT_EQ(default_galleries_count() + 3UL, dev1_path2_id);
635 AddGalleryExpectation(dev1_path2_id, info.name, device_id, relative_path, 635 AddGalleryExpectation(dev1_path2_id, info.name(), device_id, relative_path,
636 MediaGalleryPrefInfo::kUserAdded); 636 MediaGalleryPrefInfo::kUserAdded);
637 Verify(); 637 Verify();
638 638
639 relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device2")); 639 relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device2"));
640 info.name = ASCIIToUTF16("Device2Path1"); 640 info.set_name(ASCIIToUTF16("Device2Path1"));
641 device_id = "path:device2"; 641 device_id = "path:device2";
642 MediaGalleryPrefId dev2_path1_id = gallery_prefs()->AddGalleryWithName( 642 MediaGalleryPrefId dev2_path1_id = gallery_prefs()->AddGalleryWithName(
643 device_id, info.name, relative_path, true /*user*/); 643 device_id, info.name(), relative_path, true /*user*/);
644 EXPECT_EQ(default_galleries_count() + 4UL, dev2_path1_id); 644 EXPECT_EQ(default_galleries_count() + 4UL, dev2_path1_id);
645 AddGalleryExpectation(dev2_path1_id, info.name, device_id, relative_path, 645 AddGalleryExpectation(dev2_path1_id, info.name(), device_id, relative_path,
646 MediaGalleryPrefInfo::kUserAdded); 646 MediaGalleryPrefInfo::kUserAdded);
647 Verify(); 647 Verify();
648 648
649 relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device2")); 649 relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device2"));
650 info.name = ASCIIToUTF16("Device2Path2"); 650 info.set_name(ASCIIToUTF16("Device2Path2"));
651 MediaGalleryPrefId dev2_path2_id = gallery_prefs()->AddGalleryWithName( 651 MediaGalleryPrefId dev2_path2_id = gallery_prefs()->AddGalleryWithName(
652 device_id, info.name, relative_path, true /*user*/); 652 device_id, info.name(), relative_path, true /*user*/);
653 EXPECT_EQ(default_galleries_count() + 5UL, dev2_path2_id); 653 EXPECT_EQ(default_galleries_count() + 5UL, dev2_path2_id);
654 AddGalleryExpectation(dev2_path2_id, info.name, device_id, relative_path, 654 AddGalleryExpectation(dev2_path2_id, info.name(), device_id, relative_path,
655 MediaGalleryPrefInfo::kUserAdded); 655 MediaGalleryPrefInfo::kUserAdded);
656 Verify(); 656 Verify();
657 657
658 // Check that adding one of them again works as expected. 658 // Check that adding one of them again works as expected.
659 MediaGalleryPrefId id = gallery_prefs()->AddGalleryWithName( 659 MediaGalleryPrefId id = gallery_prefs()->AddGalleryWithName(
660 device_id, info.name, relative_path, true /*user*/); 660 device_id, info.name(), relative_path, true /*user*/);
661 EXPECT_EQ(dev2_path2_id, id); 661 EXPECT_EQ(dev2_path2_id, id);
662 Verify(); 662 Verify();
663 } 663 }
664 664
665 TEST_F(MediaGalleriesPreferencesTest, GalleryChangeObserver) { 665 TEST_F(MediaGalleriesPreferencesTest, GalleryChangeObserver) {
666 // Start with one observer. 666 // Start with one observer.
667 MockGalleryChangeObserver observer1(gallery_prefs()); 667 MockGalleryChangeObserver observer1(gallery_prefs());
668 gallery_prefs()->AddGalleryChangeObserver(&observer1); 668 gallery_prefs()->AddGalleryChangeObserver(&observer1);
669 669
670 // Add a new auto detected gallery. 670 // Add a new auto detected gallery.
671 base::FilePath path = MakePath("new_auto"); 671 base::FilePath path = MakePath("new_auto");
672 StorageInfo info; 672 StorageInfo info;
673 base::FilePath relative_path; 673 base::FilePath relative_path;
674 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 674 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
675 info.name = ASCIIToUTF16("NewAutoGallery"); 675 info.set_name(ASCIIToUTF16("NewAutoGallery"));
676 MediaGalleryPrefId auto_id = 676 MediaGalleryPrefId auto_id =
677 gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 677 gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
678 relative_path, false /*auto*/); 678 relative_path, false /*auto*/);
679 EXPECT_EQ(default_galleries_count() + 1UL, auto_id); 679 EXPECT_EQ(default_galleries_count() + 1UL, auto_id);
680 AddGalleryExpectation(auto_id, info.name, info.device_id, 680 AddGalleryExpectation(auto_id, info.name(), info.device_id(),
681 relative_path, MediaGalleryPrefInfo::kAutoDetected); 681 relative_path, MediaGalleryPrefInfo::kAutoDetected);
682 EXPECT_EQ(1, observer1.notifications()); 682 EXPECT_EQ(1, observer1.notifications());
683 683
684 // Add a second observer. 684 // Add a second observer.
685 MockGalleryChangeObserver observer2(gallery_prefs()); 685 MockGalleryChangeObserver observer2(gallery_prefs());
686 gallery_prefs()->AddGalleryChangeObserver(&observer2); 686 gallery_prefs()->AddGalleryChangeObserver(&observer2);
687 687
688 // Add a new user added gallery. 688 // Add a new user added gallery.
689 path = MakePath("new_user"); 689 path = MakePath("new_user");
690 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 690 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
691 info.name = ASCIIToUTF16("NewUserGallery"); 691 info.set_name(ASCIIToUTF16("NewUserGallery"));
692 MediaGalleryPrefId user_added_id = 692 MediaGalleryPrefId user_added_id =
693 gallery_prefs()->AddGalleryWithName(info.device_id, info.name, 693 gallery_prefs()->AddGalleryWithName(info.device_id(), info.name(),
694 relative_path, true /*user*/); 694 relative_path, true /*user*/);
695 AddGalleryExpectation(user_added_id, info.name, info.device_id, 695 AddGalleryExpectation(user_added_id, info.name(), info.device_id(),
696 relative_path, MediaGalleryPrefInfo::kUserAdded); 696 relative_path, MediaGalleryPrefInfo::kUserAdded);
697 EXPECT_EQ(default_galleries_count() + 2UL, user_added_id); 697 EXPECT_EQ(default_galleries_count() + 2UL, user_added_id);
698 EXPECT_EQ(2, observer1.notifications()); 698 EXPECT_EQ(2, observer1.notifications());
699 EXPECT_EQ(1, observer2.notifications()); 699 EXPECT_EQ(1, observer2.notifications());
700 700
701 // Remove the first observer. 701 // Remove the first observer.
702 gallery_prefs()->RemoveGalleryChangeObserver(&observer1); 702 gallery_prefs()->RemoveGalleryChangeObserver(&observer1);
703 703
704 // Remove an auto added gallery (i.e. make it blacklisted). 704 // Remove an auto added gallery (i.e. make it blacklisted).
705 gallery_prefs()->ForgetGalleryById(auto_id); 705 gallery_prefs()->ForgetGalleryById(auto_id);
706 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed; 706 expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed;
707 expected_galleries_for_all.erase(auto_id); 707 expected_galleries_for_all.erase(auto_id);
708 708
709 EXPECT_EQ(2, observer1.notifications()); 709 EXPECT_EQ(2, observer1.notifications());
710 EXPECT_EQ(2, observer2.notifications()); 710 EXPECT_EQ(2, observer2.notifications());
711 711
712 // Remove a user added gallery and it should go away. 712 // Remove a user added gallery and it should go away.
713 gallery_prefs()->ForgetGalleryById(user_added_id); 713 gallery_prefs()->ForgetGalleryById(user_added_id);
714 expected_galleries_.erase(user_added_id); 714 expected_galleries_.erase(user_added_id);
715 expected_device_map[info.device_id].erase(user_added_id); 715 expected_device_map[info.device_id()].erase(user_added_id);
716 716
717 EXPECT_EQ(2, observer1.notifications()); 717 EXPECT_EQ(2, observer1.notifications());
718 EXPECT_EQ(3, observer2.notifications()); 718 EXPECT_EQ(3, observer2.notifications());
719 } 719 }
720 720
721 } // namespace chrome 721 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698