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 #if defined(OS_WIN) |
| 8 #include <windows.h> |
| 9 #endif |
| 10 |
7 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
8 #include "base/file_util.h" | 12 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
10 #include "base/path_service.h" | 14 #include "base/path_service.h" |
11 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
12 #include "chrome/browser/extensions/extension_prefs.h" | 16 #include "chrome/browser/extensions/extension_prefs.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
| 19 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" |
15 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
18 #include "extensions/common/manifest_constants.h" | 23 #include "extensions/common/manifest_constants.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
20 | 25 |
| 26 #if defined(OS_WIN) |
| 27 #include "base/test/test_reg_util_win.h" |
| 28 #include "base/win/registry.h" |
| 29 #endif |
| 30 |
21 scoped_refptr<extensions::Extension> AddMediaGalleriesApp( | 31 scoped_refptr<extensions::Extension> AddMediaGalleriesApp( |
22 const std::string& name, | 32 const std::string& name, |
23 const std::vector<std::string>& media_galleries_permissions, | 33 const std::vector<std::string>& media_galleries_permissions, |
24 Profile* profile) { | 34 Profile* profile) { |
25 scoped_ptr<DictionaryValue> manifest(new DictionaryValue); | 35 scoped_ptr<DictionaryValue> manifest(new DictionaryValue); |
26 manifest->SetString(extensions::manifest_keys::kName, name); | 36 manifest->SetString(extensions::manifest_keys::kName, name); |
27 manifest->SetString(extensions::manifest_keys::kVersion, "0.1"); | 37 manifest->SetString(extensions::manifest_keys::kVersion, "0.1"); |
28 manifest->SetInteger(extensions::manifest_keys::kManifestVersion, 2); | 38 manifest->SetInteger(extensions::manifest_keys::kManifestVersion, 2); |
29 ListValue* background_script_list = new ListValue; | 39 ListValue* background_script_list = new ListValue; |
30 background_script_list->Append(Value::CreateStringValue("background.js")); | 40 background_script_list->Append(Value::CreateStringValue("background.js")); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 base::FilePath EnsureMediaDirectoriesExists::GetFakeAppDataPath() const { | 88 base::FilePath EnsureMediaDirectoriesExists::GetFakeAppDataPath() const { |
79 DCHECK(fake_dir_.IsValid()); | 89 DCHECK(fake_dir_.IsValid()); |
80 return fake_dir_.path().AppendASCII("appdata"); | 90 return fake_dir_.path().AppendASCII("appdata"); |
81 } | 91 } |
82 | 92 |
83 #if defined(OS_WIN) | 93 #if defined(OS_WIN) |
84 base::FilePath EnsureMediaDirectoriesExists::GetFakeLocalAppDataPath() const { | 94 base::FilePath EnsureMediaDirectoriesExists::GetFakeLocalAppDataPath() const { |
85 DCHECK(fake_dir_.IsValid()); | 95 DCHECK(fake_dir_.IsValid()); |
86 return fake_dir_.path().AppendASCII("localappdata"); | 96 return fake_dir_.path().AppendASCII("localappdata"); |
87 } | 97 } |
| 98 |
| 99 void EnsureMediaDirectoriesExists::WriteCustomPicasaAppDataPathToRegistry( |
| 100 const base::FilePath& path) { |
| 101 base::win::RegKey key(HKEY_CURRENT_USER, picasa::kPicasaRegistryPath, |
| 102 KEY_SET_VALUE); |
| 103 key.WriteValue(picasa::kPicasaRegistryAppDataKey, path.value().c_str()); |
| 104 } |
88 #endif | 105 #endif |
89 | 106 |
90 #if defined(OS_WIN) || defined(OS_MACOSX) | 107 #if defined(OS_WIN) || defined(OS_MACOSX) |
91 base::FilePath | 108 base::FilePath |
92 EnsureMediaDirectoriesExists::GetFakePicasaFoldersRootPath() const { | 109 EnsureMediaDirectoriesExists::GetFakePicasaFoldersRootPath() const { |
93 DCHECK(fake_dir_.IsValid()); | 110 DCHECK(fake_dir_.IsValid()); |
94 return fake_dir_.path().AppendASCII("picasa_folders"); | 111 return fake_dir_.path().AppendASCII("picasa_folders"); |
95 } | 112 } |
96 #endif | 113 #endif |
97 | 114 |
98 void EnsureMediaDirectoriesExists::Init() { | 115 void EnsureMediaDirectoriesExists::Init() { |
99 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 116 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
100 return; | 117 return; |
101 #else | 118 #else |
102 | 119 |
103 ASSERT_TRUE(fake_dir_.CreateUniqueTempDir()); | 120 ASSERT_TRUE(fake_dir_.CreateUniqueTempDir()); |
104 | 121 |
105 #if defined(OS_WIN) || defined(OS_MACOSX) | 122 #if defined(OS_WIN) || defined(OS_MACOSX) |
106 // This is to control whether or not tests think iTunes and Picasa are | 123 // This is to control whether or not tests think iTunes and Picasa are |
107 // installed. | 124 // installed. |
108 app_data_override_.reset(new base::ScopedPathOverride( | 125 app_data_override_.reset(new base::ScopedPathOverride( |
109 base::DIR_APP_DATA, GetFakeAppDataPath())); | 126 base::DIR_APP_DATA, GetFakeAppDataPath())); |
110 #if defined(OS_WIN) | 127 #if defined(OS_WIN) |
111 // Picasa on Windows is in the DIR_LOCAL_APP_DATA directory. | 128 // Picasa on Windows is by default in the DIR_LOCAL_APP_DATA directory. |
112 local_app_data_override_.reset(new base::ScopedPathOverride( | 129 local_app_data_override_.reset(new base::ScopedPathOverride( |
113 base::DIR_LOCAL_APP_DATA, GetFakeLocalAppDataPath())); | 130 base::DIR_LOCAL_APP_DATA, GetFakeLocalAppDataPath())); |
| 131 // Picasa also looks in the registry for an alternate path. |
| 132 registry_override_.OverrideRegistry(HKEY_CURRENT_USER, L"hkcu_picasa"); |
114 #endif | 133 #endif |
115 #endif | 134 #endif |
116 | 135 |
117 music_override_.reset(new base::ScopedPathOverride( | 136 music_override_.reset(new base::ScopedPathOverride( |
118 chrome::DIR_USER_MUSIC, fake_dir_.path().AppendASCII("music"))); | 137 chrome::DIR_USER_MUSIC, fake_dir_.path().AppendASCII("music"))); |
119 pictures_override_.reset(new base::ScopedPathOverride( | 138 pictures_override_.reset(new base::ScopedPathOverride( |
120 chrome::DIR_USER_PICTURES, fake_dir_.path().AppendASCII("pictures"))); | 139 chrome::DIR_USER_PICTURES, fake_dir_.path().AppendASCII("pictures"))); |
121 video_override_.reset(new base::ScopedPathOverride( | 140 video_override_.reset(new base::ScopedPathOverride( |
122 chrome::DIR_USER_VIDEOS, fake_dir_.path().AppendASCII("videos"))); | 141 chrome::DIR_USER_VIDEOS, fake_dir_.path().AppendASCII("videos"))); |
123 num_galleries_ = 3; | 142 num_galleries_ = 3; |
124 #endif | 143 #endif |
125 } | 144 } |
OLD | NEW |