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

Unified Diff: chrome/browser/media_gallery/mac/mtp_device_delegate_impl_mac_unittest.mm

Issue 11416089: [Media Galleries] Filesystem interface for Mac PTP/MTP devices using ImageCaptureCore (part 3) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Use single enumerator Created 8 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media_gallery/mac/mtp_device_delegate_impl_mac_unittest.mm
diff --git a/chrome/browser/media_gallery/mac/mtp_device_delegate_impl_mac_unittest.mm b/chrome/browser/media_gallery/mac/mtp_device_delegate_impl_mac_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..c92e8355f594ea99b0700862ec35d39f32b5a58e
--- /dev/null
+++ b/chrome/browser/media_gallery/mac/mtp_device_delegate_impl_mac_unittest.mm
@@ -0,0 +1,200 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <Foundation/Foundation.h>
+#import <ImageCaptureCore/ImageCaptureCore.h>
+
+#include "base/mac/foundation_util.h"
+#include "base/memory/scoped_nsobject.h"
+#include "base/message_loop.h"
+#include "base/sys_string_conversions.h"
+#include "base/system_monitor/system_monitor.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "chrome/browser/media_gallery/mac/mtp_device_delegate_impl_mac.h"
+#include "chrome/browser/system_monitor/image_capture_device_manager.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/test/test_browser_thread.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/fileapi/file_system_file_util.h"
+
+namespace {
+
+const char kDeviceId[] = "id";
+const char kTestFileContents[] = "test";
+
+} // namespace
+
+@interface MockMTPICCameraDevice : ICCameraDevice {
+ @private
+ scoped_nsobject<NSMutableArray> allMediaFiles_;
+}
+
+- (void)addMediaFile:(ICCameraFile*)file;
+
+@end
+
+@implementation MockMTPICCameraDevice
+
+- (NSString*)mountPoint {
+ return @"mountPoint";
+}
+
+- (NSString*)name {
+ return @"name";
+}
+
+- (NSString*)UUIDString {
+ return base::SysUTF8ToNSString(kDeviceId);
+}
+
+- (ICDeviceType)type {
+ return ICDeviceTypeCamera;
+}
+
+- (void)requestOpenSession {
+}
+
+- (void)requestCloseSession {
+}
+
+- (NSArray*)mediaFiles {
+ return allMediaFiles_;
+}
+
+- (void)addMediaFile:(ICCameraFile*)file {
+ if (!allMediaFiles_.get())
+ allMediaFiles_.reset([NSMutableArray arrayWithCapacity:1]);
sail 2012/12/26 21:30:43 should retain. actually, just doing .reset([[NSMut
Greg Billock 2013/01/03 22:41:32 Done.
+ [allMediaFiles_ addObject:file];
+}
+
+- (void)requestDownloadFile:(ICCameraFile*)file
+ options:(NSDictionary*)options
+ downloadDelegate:(id<ICCameraDeviceDownloadDelegate>)downloadDelegate
+ didDownloadSelector:(SEL)selector
+ contextInfo:(void*)contextInfo {
+ FilePath saveDir(base::SysNSStringToUTF8(
+ [[options objectForKey:ICDownloadsDirectoryURL] path]));
+ std::string saveAsFilename =
+ base::SysNSStringToUTF8([options objectForKey:ICSaveAsFilename]);
+ // It appears that the ImageCapture library adds an extension to the requested
+ // filename. Do that here to require a rename.
+ saveAsFilename += ".jpg";
+ FilePath toBeSaved = saveDir.Append(saveAsFilename);
+ ASSERT_EQ(static_cast<int>(strlen(kTestFileContents)),
+ file_util::WriteFile(toBeSaved, kTestFileContents,
+ strlen(kTestFileContents)));
+
+ NSMutableDictionary* returnOptions =
+ [NSMutableDictionary dictionaryWithDictionary:options];
+ [returnOptions setObject:base::SysUTF8ToNSString(saveAsFilename)
+ forKey:ICSavedFilename];
+
+ [downloadDelegate didDownloadFile:file
+ error:nil
+ options:returnOptions
+ contextInfo:contextInfo];
+}
+
+@end
+
+@interface MockMTPICCameraFile : ICCameraFile {
+ @private
+ scoped_nsobject<NSString> name_;
+ scoped_nsobject<NSDate> date_;
+}
+
+- (id)init:(NSString*)name;
+
+@end
+
+@implementation MockMTPICCameraFile
+
+- (id)init:(NSString*)name {
+ if ((self = [super init])) {
+ name_.reset([NSString stringWithString:name]);
+ date_.reset([[NSDate dateWithNaturalLanguageString:@"12/12/12"] retain]);
+ }
+ return self;
+}
+
+- (NSString*)name {
+ return name_.get();
+}
+
+- (NSString*)UTI {
+ return base::mac::CFToNSCast(kUTTypeImage);
+}
+
+- (NSDate*)modificationDate {
+ return date_.get();
+}
+
+- (NSDate*)creationDate {
+ return date_.get();
+}
+
+- (off_t)fileSize {
+ return 1000;
+}
+
+@end
+
+class MTPDeviceDelegateImplMacTest : public testing::Test {
+ public:
+ virtual void SetUp() OVERRIDE {
+ base::SystemMonitor::AllocateSystemIOPorts();
+ system_monitor_.reset(new base::SystemMonitor());
+ ui_thread_.reset(new content::TestBrowserThread(
+ content::BrowserThread::UI, &message_loop_));
+
+ camera_ = [MockMTPICCameraDevice alloc];
+ id<ICDeviceBrowserDelegate> delegate = manager_.device_browser();
+ [delegate deviceBrowser:nil didAddDevice:camera_ moreComing:NO];
+
+ base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
+ task_runner_ = pool->GetSequencedTaskRunner(
+ pool->GetNamedSequenceToken("token-name"));
+ delegate_ = new chrome::MTPDeviceDelegateImplMac(
+ "/ic:id", task_runner_.get());
+ }
+
+ virtual void TearDown() OVERRIDE {
+ id<ICDeviceBrowserDelegate> delegate = manager_.device_browser();
+ [delegate deviceBrowser:nil didRemoveDevice:camera_ moreGoing:NO];
+
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&chrome::MTPDeviceDelegateImplMac::
+ CancelPendingTasksAndDeleteDelegate,
+ base::Unretained(delegate_)));
+ }
+
+ protected:
+ MessageLoopForUI message_loop_;
+ scoped_ptr<content::TestBrowserThread> ui_thread_;
+ scoped_ptr<base::SystemMonitor> system_monitor_;
+ chrome::ImageCaptureDeviceManager manager_;
+ ICCameraDevice* camera_;
sail 2012/12/26 21:30:43 needs to be initialized in constructor, same with
Greg Billock 2013/01/03 22:41:32 Done.
+ scoped_refptr<base::SequencedTaskRunner> task_runner_;
+
+ // This object needs special deletion inside the above |task_runner_|.
+ chrome::MTPDeviceDelegateImplMac* delegate_;
+};
+
+TEST_F(MTPDeviceDelegateImplMacTest, TestGetRootFileInfo) {
+ base::PlatformFileInfo info;
+ // Making a fresh delegate should have a single file entry for the synthetic
+ // root directory, with the name equal to the device id string.
+ EXPECT_EQ(base::PLATFORM_FILE_OK,
+ delegate_->GetFileInfo(FilePath("/ic:id"), &info));
+ EXPECT_TRUE(info.is_directory);
+ EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
+ delegate_->GetFileInfo(FilePath("/nonexistent"), &info));
+
+ // Signal the delegate that no files are coming.
+ delegate_->NoMoreItems();
+
+ scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> enumerator =
+ delegate_->CreateFileEnumerator(FilePath("/ic:id"), true);
+ EXPECT_TRUE(enumerator->Next().empty());
+}

Powered by Google App Engine
This is Rietveld 408576698