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

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

Issue 24269007: Media Galleries API: Fix MediaGalleriesPreferences finders race. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | 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 // MediaFileSystemRegistry unit tests. 5 // MediaFileSystemRegistry unit tests.
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 return media_directories_.num_galleries(); 349 return media_directories_.num_galleries();
350 } 350 }
351 351
352 protected: 352 protected:
353 virtual void SetUp() OVERRIDE; 353 virtual void SetUp() OVERRIDE;
354 virtual void TearDown() OVERRIDE; 354 virtual void TearDown() OVERRIDE;
355 355
356 private: 356 private:
357 // This makes sure that at least one default gallery exists on the file 357 // This makes sure that at least one default gallery exists on the file
358 // system. 358 // system.
359 EnsureMediaDirectoriesExists media_directories_; 359 TestMediaDirectoriesOverrides media_directories_;
360 360
361 // Some test gallery directories. 361 // Some test gallery directories.
362 base::ScopedTempDir galleries_dir_; 362 base::ScopedTempDir galleries_dir_;
363 // An empty directory in |galleries_dir_| 363 // An empty directory in |galleries_dir_|
364 base::FilePath empty_dir_; 364 base::FilePath empty_dir_;
365 // A directory in |galleries_dir_| with a DCIM directory in it. 365 // A directory in |galleries_dir_| with a DCIM directory in it.
366 base::FilePath dcim_dir_; 366 base::FilePath dcim_dir_;
367 367
368 // MediaFileSystemRegistry owns this. 368 // MediaFileSystemRegistry owns this.
369 TestMediaFileSystemContext* test_file_system_context_; 369 TestMediaFileSystemContext* test_file_system_context_;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 // delete everything that references the profile. 465 // delete everything that references the profile.
466 single_web_contents_.reset(); 466 single_web_contents_.reset();
467 shared_web_contents1_.reset(); 467 shared_web_contents1_.reset();
468 shared_web_contents2_.reset(); 468 shared_web_contents2_.reset();
469 profile_.reset(); 469 profile_.reset();
470 470
471 base::MessageLoop::current()->RunUntilIdle(); 471 base::MessageLoop::current()->RunUntilIdle();
472 } 472 }
473 473
474 MediaGalleriesPreferences* ProfileState::GetMediaGalleriesPrefs() { 474 MediaGalleriesPreferences* ProfileState::GetMediaGalleriesPrefs() {
475 return MediaGalleriesPreferencesFactory::GetForProfile(profile_.get()); 475 MediaGalleriesPreferences* prefs =
476 MediaGalleriesPreferencesFactory::GetForProfile(profile_.get());
477 base::RunLoop loop;
478 prefs->EnsureInitialized(loop.QuitClosure());
479 loop.Run();
480 return prefs;
476 } 481 }
477 482
478 void ProfileState::CheckGalleries( 483 void ProfileState::CheckGalleries(
479 const std::string& test, 484 const std::string& test,
480 const std::vector<MediaFileSystemInfo>& regular_extension_galleries, 485 const std::vector<MediaFileSystemInfo>& regular_extension_galleries,
481 const std::vector<MediaFileSystemInfo>& all_extension_galleries) { 486 const std::vector<MediaFileSystemInfo>& all_extension_galleries) {
482 content::RenderViewHost* rvh = single_web_contents_->GetRenderViewHost(); 487 content::RenderViewHost* rvh = single_web_contents_->GetRenderViewHost();
483 MediaFileSystemRegistry* registry = 488 MediaFileSystemRegistry* registry =
484 g_browser_process->media_file_system_registry(); 489 g_browser_process->media_file_system_registry();
485 490
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 profile_states_.push_back(state); 597 profile_states_.push_back(state);
593 } 598 }
594 } 599 }
595 600
596 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) { 601 ProfileState* MediaFileSystemRegistryTest::GetProfileState(size_t i) {
597 return profile_states_[i]; 602 return profile_states_[i];
598 } 603 }
599 604
600 MediaGalleriesPreferences* MediaFileSystemRegistryTest::GetPreferences( 605 MediaGalleriesPreferences* MediaFileSystemRegistryTest::GetPreferences(
601 Profile* profile) { 606 Profile* profile) {
602 return registry()->GetPreferences(profile); 607 MediaGalleriesPreferences* prefs = registry()->GetPreferences(profile);
608 base::RunLoop loop;
609 prefs->EnsureInitialized(loop.QuitClosure());
610 loop.Run();
611 return prefs;
603 } 612 }
604 613
605 std::string MediaFileSystemRegistryTest::AddUserGallery( 614 std::string MediaFileSystemRegistryTest::AddUserGallery(
606 StorageInfo::Type type, 615 StorageInfo::Type type,
607 const std::string& unique_id, 616 const std::string& unique_id,
608 const base::FilePath& path) { 617 const base::FilePath& path) {
609 std::string device_id = StorageInfo::MakeDeviceId(type, unique_id); 618 std::string device_id = StorageInfo::MakeDeviceId(type, unique_id);
610 DCHECK(!StorageInfo::IsMediaDevice(device_id)); 619 DCHECK(!StorageInfo::IsMediaDevice(device_id));
611 620
612 for (size_t i = 0; i < profile_states_.size(); ++i) { 621 for (size_t i = 0; i < profile_states_.size(); ++i) {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_PICTURES, &path)); 1030 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_PICTURES, &path));
1022 profile_state->AddNameForAllCompare(path.BaseName().LossyDisplayName()); 1031 profile_state->AddNameForAllCompare(path.BaseName().LossyDisplayName());
1023 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_VIDEOS, &path)); 1032 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_VIDEOS, &path));
1024 profile_state->AddNameForAllCompare(path.BaseName().LossyDisplayName()); 1033 profile_state->AddNameForAllCompare(path.BaseName().LossyDisplayName());
1025 1034
1026 profile_state->CheckGalleries("names-dir", one_expectation, auto_galleries); 1035 profile_state->CheckGalleries("names-dir", one_expectation, auto_galleries);
1027 } else { 1036 } else {
1028 profile_state->CheckGalleries("names", one_expectation, one_expectation); 1037 profile_state->CheckGalleries("names", one_expectation, one_expectation);
1029 } 1038 }
1030 } 1039 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698