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

Unified Diff: chrome/browser/storage_monitor/media_storage_util_unittest.cc

Issue 12544005: Consolidate storage_monitor/MediaDeviceNotificationsUtils into MediaStorageUtil. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix mac apply patch Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/storage_monitor/media_storage_util_unittest.cc
diff --git a/chrome/browser/storage_monitor/media_storage_util_unittest.cc b/chrome/browser/storage_monitor/media_storage_util_unittest.cc
index f5d8ebaff6126ce7a24c349c124abcddcc24d36d..df1b21dc0313c8370779e817fba08e3fd00a08e9 100644
--- a/chrome/browser/storage_monitor/media_storage_util_unittest.cc
+++ b/chrome/browser/storage_monitor/media_storage_util_unittest.cc
@@ -4,10 +4,13 @@
#include <string>
+#include "base/file_util.h"
+#include "base/files/scoped_temp_dir.h"
#include "base/message_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/storage_monitor/media_storage_util.h"
+#include "chrome/browser/storage_monitor/removable_device_constants.h"
#include "chrome/browser/storage_monitor/storage_monitor.h"
#include "chrome/browser/storage_monitor/test_storage_monitor.h"
#include "content/public/browser/browser_thread.h"
@@ -25,18 +28,96 @@ const char kImageCaptureDeviceId[] = "ic:xyz";
} // namespace
+using content::BrowserThread;
+
class MediaStorageUtilTest : public testing::Test {
public:
+ MediaStorageUtilTest()
+ : ui_thread_(BrowserThread::UI, &message_loop_),
+ file_thread_(BrowserThread::FILE) {}
+ virtual ~MediaStorageUtilTest() { }
+
+ // Verify mounted device type.
+ void CheckDeviceType(const base::FilePath::StringType& mount_point,
+ bool expected_val) {
+ if (expected_val)
+ EXPECT_TRUE(MediaStorageUtil::HasDcim(mount_point));
+ else
+ EXPECT_FALSE(MediaStorageUtil::HasDcim(mount_point));
+ }
+
void ProcessAttach(const std::string& id,
const string16& name,
const base::FilePath::StringType& location) {
monitor_.receiver()->ProcessAttach(StorageInfo(id, name, location));
}
+ protected:
+ // Create mount point for the test device.
+ base::FilePath CreateMountPoint(bool create_dcim_dir) {
+ base::FilePath path(scoped_temp_dir_.path());
+ if (create_dcim_dir)
+ path = path.Append(kDCIMDirectoryName);
+ if (!file_util::CreateDirectory(path))
+ return base::FilePath();
+ return scoped_temp_dir_.path();
+ }
+
+ virtual void SetUp() OVERRIDE {
+ ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
+ file_thread_.Start();
+ }
+
+ virtual void TearDown() {
+ WaitForFileThread();
+ }
+
+ static void PostQuitToUIThread() {
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ MessageLoop::QuitClosure());
+ }
+
+ static void WaitForFileThread() {
+ BrowserThread::PostTask(BrowserThread::FILE,
+ FROM_HERE,
+ base::Bind(&PostQuitToUIThread));
+ MessageLoop::current()->Run();
+ }
+
+ MessageLoop message_loop_;
+
private:
chrome::test::TestStorageMonitor monitor_;
+ content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread file_thread_;
+ base::ScopedTempDir scoped_temp_dir_;
};
+// Test to verify that HasDcim() function returns true for the given media
+// device mount point.
+TEST_F(MediaStorageUtilTest, MediaDeviceAttached) {
+ // Create a dummy mount point with DCIM Directory.
+ base::FilePath mount_point(CreateMountPoint(true));
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&MediaStorageUtilTest::CheckDeviceType,
+ base::Unretained(this), mount_point.value(), true));
+ message_loop_.RunUntilIdle();
+}
+
+// Test to verify that HasDcim() function returns false for a given non-media
+// device mount point.
+TEST_F(MediaStorageUtilTest, NonMediaDeviceAttached) {
+ // Create a dummy mount point without DCIM Directory.
+ base::FilePath mount_point(CreateMountPoint(false));
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&MediaStorageUtilTest::CheckDeviceType,
+ base::Unretained(this), mount_point.value(), false));
+ message_loop_.RunUntilIdle();
+}
+
// Test to verify |MediaStorageUtil::MakeDeviceId| functionality using a sample
// mtp device unique id.
TEST_F(MediaStorageUtilTest, MakeMtpDeviceId) {
@@ -74,16 +155,18 @@ TEST_F(MediaStorageUtilTest, CanCreateFileSystemForImageCapture) {
}
TEST_F(MediaStorageUtilTest, DetectDeviceFiltered) {
- MessageLoop loop;
- content::TestBrowserThread file_thread(content::BrowserThread::FILE, &loop);
-
MediaStorageUtil::DeviceIdSet devices;
devices.insert(kImageCaptureDeviceId);
base::WaitableEvent event(true, false);
- MediaStorageUtil::FilterAttachedDevices(&devices,
- base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event)));
- loop.RunUntilIdle();
+ base::Closure signal_event =
+ base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event));
+
+ // We need signal_event to be executed on the FILE thread, as the test thread
+ // is blocked. Therefore, we invoke FilterAttachedDevices on the FILE thread.
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&MediaStorageUtil::FilterAttachedDevices,
+ base::Unretained(&devices), signal_event));
event.Wait();
EXPECT_FALSE(devices.find(kImageCaptureDeviceId) != devices.end());
@@ -91,9 +174,9 @@ TEST_F(MediaStorageUtilTest, DetectDeviceFiltered) {
FILE_PATH_LITERAL("/location"));
devices.insert(kImageCaptureDeviceId);
event.Reset();
- MediaStorageUtil::FilterAttachedDevices(&devices,
- base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event)));
- loop.RunUntilIdle();
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&MediaStorageUtil::FilterAttachedDevices,
+ base::Unretained(&devices), signal_event));
event.Wait();
EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end());
« no previous file with comments | « chrome/browser/storage_monitor/media_storage_util.cc ('k') | chrome/browser/storage_monitor/storage_monitor_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698