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

Side by Side Diff: chrome/browser/extensions/api/media_galleries/media_galleries_apitest.cc

Issue 23513059: Media Galleries API Picasa: End-to-end browsertest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 #include "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/safe_numerics.h" 9 #include "base/safe_numerics.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/apps/app_browsertest_util.h" 12 #include "chrome/browser/apps/app_browsertest_util.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/extensions/extension_system.h" 14 #include "chrome/browser/extensions/extension_system.h"
15 #include "chrome/browser/media_galleries/media_file_system_registry.h" 15 #include "chrome/browser/media_galleries/media_file_system_registry.h"
16 #include "chrome/browser/media_galleries/media_galleries_preferences.h" 16 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
17 #include "chrome/browser/media_galleries/media_galleries_test_util.h" 17 #include "chrome/browser/media_galleries/media_galleries_test_util.h"
18 #include "chrome/browser/storage_monitor/storage_info.h" 18 #include "chrome/browser/storage_monitor/storage_info.h"
19 #include "chrome/browser/storage_monitor/storage_monitor.h" 19 #include "chrome/browser/storage_monitor/storage_monitor.h"
20 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
21 #include "content/public/test/test_utils.h" 21 #include "content/public/test/test_utils.h"
22 22
23 #if defined(OS_WIN) || defined(OS_MACOSX)
24 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h"
25 #include "chrome/common/media_galleries/picasa_test_util.h"
26 #include "chrome/common/media_galleries/picasa_types.h"
27 #include "chrome/common/media_galleries/pmp_test_util.h"
28 #endif
29
23 using extensions::PlatformAppBrowserTest; 30 using extensions::PlatformAppBrowserTest;
24 31
25 namespace { 32 namespace {
26 33
27 // Dummy device properties. 34 // Dummy device properties.
28 const char kDeviceId[] = "testDeviceId"; 35 const char kDeviceId[] = "testDeviceId";
29 const char kDeviceName[] = "foobar"; 36 const char kDeviceName[] = "foobar";
30 #if defined(FILE_PATH_USES_DRIVE_LETTERS) 37 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
31 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("C:\\qux"); 38 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("C:\\qux");
32 #else 39 #else
33 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("/qux"); 40 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("/qux");
34 #endif 41 #endif
35 42
36 } // namespace
37
38 // This function is to ensure at least one (fake) media gallery exists for 43 // This function is to ensure at least one (fake) media gallery exists for
39 // testing platforms with no default media galleries, such as CHROMEOS. 44 // testing platforms with no default media galleries, such as CHROMEOS.
40 void MakeFakeMediaGalleryForTest(Profile* profile, const base::FilePath& path) { 45 void MakeFakeMediaGalleryForTest(Profile* profile, const base::FilePath& path) {
41 base::RunLoop runloop;
42 MediaGalleriesPreferences* preferences = 46 MediaGalleriesPreferences* preferences =
43 g_browser_process->media_file_system_registry()->GetPreferences(profile); 47 g_browser_process->media_file_system_registry()->GetPreferences(profile);
48 base::RunLoop runloop;
44 preferences->EnsureInitialized(runloop.QuitClosure()); 49 preferences->EnsureInitialized(runloop.QuitClosure());
45 runloop.Run(); 50 runloop.Run();
46 51
47 MediaGalleryPrefInfo gallery_info; 52 MediaGalleryPrefInfo gallery_info;
48 ASSERT_FALSE(preferences->LookUpGalleryByPath(path, &gallery_info)); 53 ASSERT_FALSE(preferences->LookUpGalleryByPath(path, &gallery_info));
49 preferences->AddGallery(gallery_info.device_id, 54 preferences->AddGallery(gallery_info.device_id,
50 gallery_info.path, 55 gallery_info.path,
51 false /* user_added */, 56 false /* user_added */,
52 gallery_info.volume_label, 57 gallery_info.volume_label,
53 gallery_info.vendor_name, 58 gallery_info.vendor_name,
54 gallery_info.model_name, 59 gallery_info.model_name,
55 gallery_info.total_size_in_bytes, 60 gallery_info.total_size_in_bytes,
56 gallery_info.last_attach_time); 61 gallery_info.last_attach_time);
57 62
58 content::RunAllPendingInMessageLoop(); 63 content::RunAllPendingInMessageLoop();
59 } 64 }
60 65
66 } // namespace
67
61 class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { 68 class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest {
62 protected: 69 protected:
63 MediaGalleriesPlatformAppBrowserTest() : test_jpg_size_(0) {} 70 MediaGalleriesPlatformAppBrowserTest() : test_jpg_size_(0) {}
64 virtual ~MediaGalleriesPlatformAppBrowserTest() {} 71 virtual ~MediaGalleriesPlatformAppBrowserTest() {}
65 72
66 virtual void SetUpOnMainThread() OVERRIDE { 73 virtual void SetUpOnMainThread() OVERRIDE {
67 PlatformAppBrowserTest::SetUpOnMainThread(); 74 PlatformAppBrowserTest::SetUpOnMainThread();
68 ensure_media_directories_exist_.reset(new EnsureMediaDirectoriesExists); 75 ensure_media_directories_exist_.reset(new EnsureMediaDirectoriesExists);
69 PopulatePicturesDirectoryTestData(); 76 PopulatePicturesDirectoryTestData();
70 } 77 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // Invalid file, should not show up as a FileEntry in JS at all. 133 // Invalid file, should not show up as a FileEntry in JS at all.
127 ASSERT_TRUE(base::CopyFile(test_data_path.AppendASCII("test.txt"), 134 ASSERT_TRUE(base::CopyFile(test_data_path.AppendASCII("test.txt"),
128 write_path.AppendASCII("test.txt"))); 135 write_path.AppendASCII("test.txt")));
129 136
130 int64 file_size; 137 int64 file_size;
131 ASSERT_TRUE(file_util::GetFileSize(test_data_path.AppendASCII("test.jpg"), 138 ASSERT_TRUE(file_util::GetFileSize(test_data_path.AppendASCII("test.jpg"),
132 &file_size)); 139 &file_size));
133 test_jpg_size_ = base::checked_numeric_cast<int>(file_size); 140 test_jpg_size_ = base::checked_numeric_cast<int>(file_size);
134 } 141 }
135 142
143 #if defined(OS_WIN) || defined(OS_MACOSX)
144 void PopulatePicasaTestData() {
145 // Create Picasa metadata database directories.
146 base::FilePath metadata_root;
147 #if defined(OS_WIN)
148 metadata_root = ensure_media_directories_exist_->GetFakeLocalAppDataPath();
149 #elif defined(OS_MACOSX)
150 metadata_root = ensure_media_directories_exist_->GetLocalAppDataPath();
151 #endif
152
153 metadata_root = metadata_root.AppendASCII("Google").AppendASCII("Picasa2");
154
155 base::FilePath picasa_database_path =
156 metadata_root.path().AppendASCII(picasa::kPicasaDatabaseDirName);
157 base::FilePath picasa_temp_dir_path =
158 metadata_root.path().AppendASCII(picasa::kPicasaTempDirName);
159 ASSERT_TRUE(file_util::CreateDirectory(picasa_database_path));
160 ASSERT_TRUE(file_util::CreateDirectory(picasa_temp_dir_path));
161
162 // Create fake folder directories.
163 base::ScopedTempDir folders_root;
164 ASSERT_TRUE(folders_root.CreateUniqueTempDir());
165 base::FilePath fake_folder_1 = folders_root.path().AppendASCII("folder1");
166 base::FilePath fake_folder_2 = folders_root.path().AppendASCII("folder2");
167 ASSERT_TRUE(file_util::CreateDirectory(fake_folder_1));
168 ASSERT_TRUE(file_util::CreateDirectory(fake_folder_2));
169
170 // Write folder and album contents.
171 picasa::WriteTestAlbumTable(
172 picasa_database_path, fake_folder_1, fake_folder_2);
173 picasa::WriteTestAlbumsImagesIndex(fake_folder_1, fake_folder_2);
174
175 base::FilePath test_data_path =
176 test_data_dir_.AppendASCII("api_test").AppendASCII("media_galleries")
177 .AppendASCII("common");
178 ASSERT_TRUE(base::CopyFile(
179 test_data_path.AppendASCII("test.jpg"),
180 fake_folder_1.AppendASCII("InBoth.jpg")));
181 ASSERT_TRUE(base::CopyFile(
182 test_data_path.AppendASCII("test.jpg"),
183 fake_folder_1.AppendASCII("InSecondAlbumOnly.jpg")));
184 ASSERT_TRUE(base::CopyFile(
185 test_data_path.AppendASCII("test.jpg"),
186 fake_folder_2.AppendASCII("InFirstAlbumOnly.jpg")));
187 }
188 #endif
189
136 int num_galleries() const { 190 int num_galleries() const {
137 return ensure_media_directories_exist_->num_galleries(); 191 return ensure_media_directories_exist_->num_galleries();
138 } 192 }
139 193
140 int test_jpg_size() const { return test_jpg_size_; } 194 int test_jpg_size() const { return test_jpg_size_; }
141 195
142 private: 196 private:
143 std::string device_id_; 197 std::string device_id_;
144 int test_jpg_size_; 198 int test_jpg_size_;
145 scoped_ptr<EnsureMediaDirectoriesExists> ensure_media_directories_exist_; 199 scoped_ptr<EnsureMediaDirectoriesExists> ensure_media_directories_exist_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 ASSERT_TRUE(RunMediaGalleriesTestWithArg("access_attached", custom_args)) 254 ASSERT_TRUE(RunMediaGalleriesTestWithArg("access_attached", custom_args))
201 << message_; 255 << message_;
202 256
203 DetachFakeDevice(); 257 DetachFakeDevice();
204 } 258 }
205 259
206 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, 260 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
207 GetFilesystemMetadata) { 261 GetFilesystemMetadata) {
208 ASSERT_TRUE(RunMediaGalleriesTest("metadata")) << message_; 262 ASSERT_TRUE(RunMediaGalleriesTest("metadata")) << message_;
209 } 263 }
264
265 #if defined(OS_WIN) || defined(OS_MACOSX)
266 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, Picasa) {
267 PopulatePicasaTestData();
268 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/picasa"))
269 << message_;
270 }
271 #endif // defined(OS_WIN) || defined(OS_MACOSX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698