Chromium Code Reviews| 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 "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "chrome/browser/extensions/extension_prefs.h" | 12 #include "chrome/browser/extensions/extension_prefs.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_system.h" | 14 #include "chrome/browser/extensions/extension_system.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/extensions/extension_manifest_constants.h" | 18 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 #if defined(OS_MACOSX) | |
| 22 #include "base/mac/foundation_util.h" | |
| 23 #include "chrome/browser/media_galleries/fileapi/itunes_finder_mac.h" | |
| 24 #include "chrome/browser/policy/preferences_mock_mac.h" | |
| 25 #endif | |
| 26 | |
| 21 namespace chrome { | 27 namespace chrome { |
| 22 | 28 |
| 23 scoped_refptr<extensions::Extension> AddMediaGalleriesApp( | 29 scoped_refptr<extensions::Extension> AddMediaGalleriesApp( |
| 24 const std::string& name, | 30 const std::string& name, |
| 25 const std::vector<std::string>& media_galleries_permissions, | 31 const std::vector<std::string>& media_galleries_permissions, |
| 26 Profile* profile) { | 32 Profile* profile) { |
| 27 scoped_ptr<DictionaryValue> manifest(new DictionaryValue); | 33 scoped_ptr<DictionaryValue> manifest(new DictionaryValue); |
| 28 manifest->SetString(extension_manifest_keys::kName, name); | 34 manifest->SetString(extension_manifest_keys::kName, name); |
| 29 manifest->SetString(extension_manifest_keys::kVersion, "0.1"); | 35 manifest->SetString(extension_manifest_keys::kVersion, "0.1"); |
| 30 manifest->SetInteger(extension_manifest_keys::kManifestVersion, 2); | 36 manifest->SetInteger(extension_manifest_keys::kManifestVersion, 2); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 | 74 |
| 69 return extension; | 75 return extension; |
| 70 } | 76 } |
| 71 | 77 |
| 72 EnsureMediaDirectoriesExists::EnsureMediaDirectoriesExists() | 78 EnsureMediaDirectoriesExists::EnsureMediaDirectoriesExists() |
| 73 : num_galleries_(0) { | 79 : num_galleries_(0) { |
| 74 Init(); | 80 Init(); |
| 75 } | 81 } |
| 76 | 82 |
| 77 EnsureMediaDirectoriesExists::~EnsureMediaDirectoriesExists() { | 83 EnsureMediaDirectoriesExists::~EnsureMediaDirectoriesExists() { |
| 84 #if defined(OS_MACOSX) | |
| 85 // Free the MockPreferences object. | |
| 86 itunes::ITunesFinderMac::SetMacPreferencesForTesting(NULL); | |
| 87 #endif | |
| 78 } | 88 } |
| 79 | 89 |
| 80 void EnsureMediaDirectoriesExists::Init() { | 90 void EnsureMediaDirectoriesExists::Init() { |
| 81 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 91 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 82 return; | 92 return; |
| 83 #else | 93 #else |
| 84 | 94 |
| 85 ASSERT_TRUE(fake_dir_.CreateUniqueTempDir()); | 95 ASSERT_TRUE(fake_dir_.CreateUniqueTempDir()); |
| 86 | 96 |
| 87 #if defined(OS_WIN) || defined(OS_MACOSX) | 97 #if defined(OS_WIN) |
| 88 // This is to make sure the tests don't think iTunes is installed (unless | 98 // This is to make sure the tests don't think iTunes is installed (unless |
| 89 // we control it specifically). | 99 // we control it specifically). |
| 90 appdir_override_.reset(new base::ScopedPathOverride( | 100 appdir_override_.reset(new base::ScopedPathOverride( |
| 91 base::DIR_APP_DATA, fake_dir_.path().AppendASCII("itunes"))); | 101 base::DIR_APP_DATA, fake_dir_.path().AppendASCII("itunes"))); |
| 102 #elif defined(OS_MACOSX) | |
| 103 MockPreferences* prefs = new MockPreferences; | |
| 104 NSString* path = base::mac::FilePathToNSString( | |
| 105 fake_dir_.path().AppendASCII("itunes")); | |
| 106 CFArrayRef array = CFArrayCreate(NULL, (const void **)(&path), 1, | |
| 107 &kCFTypeArrayCallBacks); | |
|
Lei Zhang
2013/08/13 20:02:34
I have no idea if this is right. Care to ask someo
| |
| 108 prefs->AddTestItem(CFSTR("iTunesRecentDatabasePaths"), array, false); | |
|
Lei Zhang
2013/08/13 20:02:34
Can we make "iTunesRecentDatabasePaths" a const?
| |
| 109 itunes::ITunesFinderMac::SetMacPreferencesForTesting(prefs); | |
| 92 #endif | 110 #endif |
| 93 | 111 |
| 94 music_override_.reset(new base::ScopedPathOverride( | 112 music_override_.reset(new base::ScopedPathOverride( |
| 95 chrome::DIR_USER_MUSIC, fake_dir_.path().AppendASCII("music"))); | 113 chrome::DIR_USER_MUSIC, fake_dir_.path().AppendASCII("music"))); |
| 96 pictures_override_.reset(new base::ScopedPathOverride( | 114 pictures_override_.reset(new base::ScopedPathOverride( |
| 97 chrome::DIR_USER_PICTURES, fake_dir_.path().AppendASCII("pictures"))); | 115 chrome::DIR_USER_PICTURES, fake_dir_.path().AppendASCII("pictures"))); |
| 98 video_override_.reset(new base::ScopedPathOverride( | 116 video_override_.reset(new base::ScopedPathOverride( |
| 99 chrome::DIR_USER_VIDEOS, fake_dir_.path().AppendASCII("videos"))); | 117 chrome::DIR_USER_VIDEOS, fake_dir_.path().AppendASCII("videos"))); |
| 100 num_galleries_ = 3; | 118 num_galleries_ = 3; |
| 101 #endif | 119 #endif |
| 102 } | 120 } |
| 103 | 121 |
| 104 } // namespace chrome | 122 } // namespace chrome |
| OLD | NEW |