OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/media_gallery/media_galleries_test_util.h" |
| 6 |
| 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" |
| 10 #include "base/stringprintf.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_system.h" |
| 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 namespace chrome { |
| 20 |
| 21 scoped_refptr<extensions::Extension> AddMediaGalleriesApp( |
| 22 const std::string& name, |
| 23 const std::vector<std::string>& media_galleries_permissions, |
| 24 Profile* profile) { |
| 25 scoped_ptr<DictionaryValue> manifest(new DictionaryValue); |
| 26 manifest->SetString(extension_manifest_keys::kName, name); |
| 27 manifest->SetString(extension_manifest_keys::kVersion, "0.1"); |
| 28 manifest->SetInteger(extension_manifest_keys::kManifestVersion, 2); |
| 29 ListValue* background_script_list = new ListValue; |
| 30 background_script_list->Append(Value::CreateStringValue("background.js")); |
| 31 manifest->Set(extension_manifest_keys::kPlatformAppBackgroundScripts, |
| 32 background_script_list); |
| 33 |
| 34 ListValue* permission_detail_list = new ListValue; |
| 35 for (size_t i = 0; i < media_galleries_permissions.size(); i++) |
| 36 permission_detail_list->Append( |
| 37 Value::CreateStringValue(media_galleries_permissions[i])); |
| 38 DictionaryValue* media_galleries_permission = new DictionaryValue(); |
| 39 media_galleries_permission->Set("mediaGalleries", permission_detail_list); |
| 40 ListValue* permission_list = new ListValue; |
| 41 permission_list->Append(media_galleries_permission); |
| 42 manifest->Set(extension_manifest_keys::kPermissions, permission_list); |
| 43 |
| 44 |
| 45 FilePath path = profile->GetPath().AppendASCII(name); |
| 46 std::string errors; |
| 47 scoped_refptr<extensions::Extension> extension = |
| 48 extensions::Extension::Create(path, extensions::Extension::INTERNAL, |
| 49 *manifest.get(), |
| 50 extensions::Extension::NO_FLAGS, &errors); |
| 51 EXPECT_TRUE(extension.get() != NULL) << errors; |
| 52 EXPECT_TRUE(extensions::Extension::IdIsValid(extension->id())); |
| 53 if (!extension.get() || !extensions::Extension::IdIsValid(extension->id())) |
| 54 return NULL; |
| 55 |
| 56 ExtensionService* extension_service = |
| 57 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 58 extension_service->extension_prefs()->OnExtensionInstalled( |
| 59 extension.get(), extensions::Extension::ENABLED, |
| 60 syncer::StringOrdinal::CreateInitialOrdinal()); |
| 61 extension_service->AddExtension(extension); |
| 62 extension_service->EnableExtension(extension->id()); |
| 63 |
| 64 return extension; |
| 65 } |
| 66 |
| 67 EnsureMediaDirectoriesExists::EnsureMediaDirectoriesExists() |
| 68 : num_galleries_(0) { |
| 69 Init(); |
| 70 } |
| 71 |
| 72 void EnsureMediaDirectoriesExists::Init() { |
| 73 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 74 return; |
| 75 #else |
| 76 ASSERT_TRUE(fake_dir_.CreateUniqueTempDir()); |
| 77 |
| 78 const int kDirectoryKeys[] = { |
| 79 chrome::DIR_USER_MUSIC, |
| 80 chrome::DIR_USER_PICTURES, |
| 81 chrome::DIR_USER_VIDEOS, |
| 82 }; |
| 83 |
| 84 const char* kDirectoryNames[] = { |
| 85 "music", |
| 86 "pictures", |
| 87 "videos", |
| 88 }; |
| 89 |
| 90 for (size_t i = 0; i < arraysize(kDirectoryKeys); ++i) { |
| 91 PathService::OverrideAndCreateIfNeeded( |
| 92 kDirectoryKeys[i], fake_dir_.path().AppendASCII(kDirectoryNames[i]), |
| 93 true /*create*/); |
| 94 FilePath path; |
| 95 if (PathService::Get(kDirectoryKeys[i], &path) && |
| 96 file_util::DirectoryExists(path)) { |
| 97 ++num_galleries_; |
| 98 } |
| 99 } |
| 100 ASSERT_GT(num_galleries_, 0); |
| 101 #endif |
| 102 } |
| 103 |
| 104 } // namespace chrome |
OLD | NEW |