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

Side by Side Diff: chrome/browser/storage_monitor/image_capture_device_manager_unittest.mm

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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 #import <Foundation/Foundation.h> 5 #import <Foundation/Foundation.h>
6 #import <ImageCaptureCore/ImageCaptureCore.h> 6 #import <ImageCaptureCore/ImageCaptureCore.h>
7 7
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/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 @end 208 @end
209 209
210 class TestCameraListener 210 class TestCameraListener
211 : public ImageCaptureDeviceListener, 211 : public ImageCaptureDeviceListener,
212 public base::SupportsWeakPtr<TestCameraListener> { 212 public base::SupportsWeakPtr<TestCameraListener> {
213 public: 213 public:
214 TestCameraListener() 214 TestCameraListener()
215 : completed_(false), 215 : completed_(false),
216 removed_(false), 216 removed_(false),
217 last_error_(base::PLATFORM_FILE_ERROR_INVALID_URL) {} 217 last_error_(base::File::FILE_ERROR_INVALID_URL) {}
218 virtual ~TestCameraListener() {} 218 virtual ~TestCameraListener() {}
219 219
220 virtual void ItemAdded(const std::string& name, 220 virtual void ItemAdded(const std::string& name,
221 const base::PlatformFileInfo& info) OVERRIDE { 221 const base::File::Info& info) OVERRIDE {
222 items_.push_back(name); 222 items_.push_back(name);
223 } 223 }
224 224
225 virtual void NoMoreItems() OVERRIDE { 225 virtual void NoMoreItems() OVERRIDE {
226 completed_ = true; 226 completed_ = true;
227 } 227 }
228 228
229 virtual void DownloadedFile(const std::string& name, 229 virtual void DownloadedFile(const std::string& name,
230 base::PlatformFileError error) OVERRIDE { 230 base::File::Error error) OVERRIDE {
231 EXPECT_TRUE(content::BrowserThread::CurrentlyOn( 231 EXPECT_TRUE(content::BrowserThread::CurrentlyOn(
232 content::BrowserThread::UI)); 232 content::BrowserThread::UI));
233 downloads_.push_back(name); 233 downloads_.push_back(name);
234 last_error_ = error; 234 last_error_ = error;
235 } 235 }
236 236
237 virtual void DeviceRemoved() OVERRIDE { 237 virtual void DeviceRemoved() OVERRIDE {
238 removed_ = true; 238 removed_ = true;
239 } 239 }
240 240
241 std::vector<std::string> items() const { return items_; } 241 std::vector<std::string> items() const { return items_; }
242 std::vector<std::string> downloads() const { return downloads_; } 242 std::vector<std::string> downloads() const { return downloads_; }
243 bool completed() const { return completed_; } 243 bool completed() const { return completed_; }
244 bool removed() const { return removed_; } 244 bool removed() const { return removed_; }
245 base::PlatformFileError last_error() const { return last_error_; } 245 base::File::Error last_error() const { return last_error_; }
246 246
247 private: 247 private:
248 std::vector<std::string> items_; 248 std::vector<std::string> items_;
249 std::vector<std::string> downloads_; 249 std::vector<std::string> downloads_;
250 bool completed_; 250 bool completed_;
251 bool removed_; 251 bool removed_;
252 base::PlatformFileError last_error_; 252 base::File::Error last_error_;
253 }; 253 };
254 254
255 class ImageCaptureDeviceManagerTest : public testing::Test { 255 class ImageCaptureDeviceManagerTest : public testing::Test {
256 public: 256 public:
257 virtual void SetUp() OVERRIDE { 257 virtual void SetUp() OVERRIDE {
258 monitor_ = TestStorageMonitor::CreateAndInstall(); 258 monitor_ = TestStorageMonitor::CreateAndInstall();
259 } 259 }
260 260
261 virtual void TearDown() OVERRIDE { 261 virtual void TearDown() OVERRIDE {
262 TestStorageMonitor::RemoveSingleton(); 262 TestStorageMonitor::RemoveSingleton();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 370
371 EXPECT_EQ(0U, listener_.downloads().size()); 371 EXPECT_EQ(0U, listener_.downloads().size());
372 372
373 // Test that a nonexistent file we ask to be downloaded will 373 // Test that a nonexistent file we ask to be downloaded will
374 // return us a not-found error. 374 // return us a not-found error.
375 base::FilePath temp_file = temp_dir.path().Append("tempfile"); 375 base::FilePath temp_file = temp_dir.path().Append("tempfile");
376 [camera downloadFile:std::string("nonexistent") localPath:temp_file]; 376 [camera downloadFile:std::string("nonexistent") localPath:temp_file];
377 base::RunLoop().RunUntilIdle(); 377 base::RunLoop().RunUntilIdle();
378 ASSERT_EQ(1U, listener_.downloads().size()); 378 ASSERT_EQ(1U, listener_.downloads().size());
379 EXPECT_EQ("nonexistent", listener_.downloads()[0]); 379 EXPECT_EQ("nonexistent", listener_.downloads()[0]);
380 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, listener_.last_error()); 380 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, listener_.last_error());
381 381
382 // Test that an existing file we ask to be downloaded will end up in 382 // Test that an existing file we ask to be downloaded will end up in
383 // the location we specify. The mock system will copy testing file 383 // the location we specify. The mock system will copy testing file
384 // contents to a separate filename, mimicking the ImageCaptureCore 384 // contents to a separate filename, mimicking the ImageCaptureCore
385 // library behavior. Our code then renames the file onto the requested 385 // library behavior. Our code then renames the file onto the requested
386 // destination. 386 // destination.
387 [camera downloadFile:kTestFileName localPath:temp_file]; 387 [camera downloadFile:kTestFileName localPath:temp_file];
388 base::RunLoop().RunUntilIdle(); 388 base::RunLoop().RunUntilIdle();
389 389
390 ASSERT_EQ(2U, listener_.downloads().size()); 390 ASSERT_EQ(2U, listener_.downloads().size());
391 EXPECT_EQ(kTestFileName, listener_.downloads()[1]); 391 EXPECT_EQ(kTestFileName, listener_.downloads()[1]);
392 ASSERT_EQ(base::PLATFORM_FILE_OK, listener_.last_error()); 392 ASSERT_EQ(base::File::FILE_OK, listener_.last_error());
393 char file_contents[5]; 393 char file_contents[5];
394 ASSERT_EQ(4, base::ReadFile(temp_file, file_contents, 394 ASSERT_EQ(4, base::ReadFile(temp_file, file_contents,
395 strlen(kTestFileContents))); 395 strlen(kTestFileContents)));
396 EXPECT_EQ(kTestFileContents, 396 EXPECT_EQ(kTestFileContents,
397 std::string(file_contents, strlen(kTestFileContents))); 397 std::string(file_contents, strlen(kTestFileContents)));
398 398
399 [camera didRemoveDevice:device]; 399 [camera didRemoveDevice:device];
400 } 400 }
401 401
402 TEST_F(ImageCaptureDeviceManagerTest, TestSubdirectories) { 402 TEST_F(ImageCaptureDeviceManagerTest, TestSubdirectories) {
(...skipping 22 matching lines...) Expand all
425 base::RunLoop().RunUntilIdle(); 425 base::RunLoop().RunUntilIdle();
426 426
427 char file_contents[5]; 427 char file_contents[5];
428 ASSERT_EQ(4, base::ReadFile(temp_file, file_contents, 428 ASSERT_EQ(4, base::ReadFile(temp_file, file_contents,
429 strlen(kTestFileContents))); 429 strlen(kTestFileContents)));
430 EXPECT_EQ(kTestFileContents, 430 EXPECT_EQ(kTestFileContents,
431 std::string(file_contents, strlen(kTestFileContents))); 431 std::string(file_contents, strlen(kTestFileContents)));
432 432
433 [camera didRemoveDevice:device]; 433 [camera didRemoveDevice:device];
434 } 434 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698