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

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
« no previous file with comments | « no previous file | chrome/browser/media_galleries/fileapi/picasa_finder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_->GetFakeAppDataPath();
151 #endif
152
153 metadata_root = metadata_root.AppendASCII("Google").AppendASCII("Picasa2");
154 base::FilePath picasa_database_path =
155 metadata_root.AppendASCII(picasa::kPicasaDatabaseDirName);
156 base::FilePath picasa_temp_dir_path =
157 metadata_root.AppendASCII(picasa::kPicasaTempDirName);
158 ASSERT_TRUE(file_util::CreateDirectory(picasa_database_path));
159 ASSERT_TRUE(file_util::CreateDirectory(picasa_temp_dir_path));
160
161 // Create fake folder directories.
162 base::FilePath folders_root =
163 ensure_media_directories_exist_->GetFakePicasaFoldersRootPath();
164 base::FilePath fake_folder_1 = folders_root.AppendASCII("folder1");
165 base::FilePath fake_folder_2 = folders_root.AppendASCII("folder2");
166 ASSERT_TRUE(file_util::CreateDirectory(fake_folder_1));
167 ASSERT_TRUE(file_util::CreateDirectory(fake_folder_2));
168
169 // Write folder and album contents.
170 picasa::WriteTestAlbumTable(
171 picasa_database_path, fake_folder_1, fake_folder_2);
172 picasa::WriteTestAlbumsImagesIndex(fake_folder_1, fake_folder_2);
173
174 base::FilePath test_data_path =
175 test_data_dir_.AppendASCII("api_test").AppendASCII("media_galleries")
176 .AppendASCII("common");
177 ASSERT_TRUE(base::CopyFile(
178 test_data_path.AppendASCII("test.jpg"),
179 fake_folder_1.AppendASCII("InBoth.jpg")));
180 ASSERT_TRUE(base::CopyFile(
181 test_data_path.AppendASCII("test.jpg"),
182 fake_folder_1.AppendASCII("InSecondAlbumOnly.jpg")));
183 ASSERT_TRUE(base::CopyFile(
184 test_data_path.AppendASCII("test.jpg"),
185 fake_folder_2.AppendASCII("InFirstAlbumOnly.jpg")));
186 }
187 #endif
188
136 int num_galleries() const { 189 int num_galleries() const {
137 return ensure_media_directories_exist_->num_galleries(); 190 return ensure_media_directories_exist_->num_galleries();
138 } 191 }
139 192
140 int test_jpg_size() const { return test_jpg_size_; } 193 int test_jpg_size() const { return test_jpg_size_; }
141 194
142 private: 195 private:
143 std::string device_id_; 196 std::string device_id_;
144 int test_jpg_size_; 197 int test_jpg_size_;
145 scoped_ptr<EnsureMediaDirectoriesExists> ensure_media_directories_exist_; 198 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)) 253 ASSERT_TRUE(RunMediaGalleriesTestWithArg("access_attached", custom_args))
201 << message_; 254 << message_;
202 255
203 DetachFakeDevice(); 256 DetachFakeDevice();
204 } 257 }
205 258
206 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, 259 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest,
207 GetFilesystemMetadata) { 260 GetFilesystemMetadata) {
208 ASSERT_TRUE(RunMediaGalleriesTest("metadata")) << message_; 261 ASSERT_TRUE(RunMediaGalleriesTest("metadata")) << message_;
209 } 262 }
263
264 #if defined(OS_WIN) || defined(OS_MACOSX)
265 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, Picasa) {
266 PopulatePicasaTestData();
267 ASSERT_TRUE(RunPlatformAppTest("api_test/media_galleries/picasa"))
268 << message_;
269 }
270 #endif // defined(OS_WIN) || defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/media_galleries/fileapi/picasa_finder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698