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

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: another chromeos fix 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..6b86a118fef0e0b0c989526d8cbc8bb4e23381e9 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) { }
Greg Billock 2013/03/06 21:48:27 No space between braces
+ virtual ~MediaStorageUtilTest() { }
+
+ // Verify mounted device type.
+ void checkDeviceType(const base::FilePath::StringType& mount_point,
Greg Billock 2013/03/06 21:48:27 Capitalize
+ 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 IsMediaDevice() 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 IsMediaDevice() 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) {

Powered by Google App Engine
This is Rietveld 408576698