| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/media_gallery/media_device_notifications_utils.h" | |
| 6 | |
| 7 #include "base/file_path.h" | |
| 8 #include "base/file_util.h" | |
| 9 #include "base/message_loop.h" | |
| 10 #include "base/scoped_temp_dir.h" | |
| 11 #include "content/public/test/test_browser_thread.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace chrome { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 #if defined(OS_WIN) | |
| 19 const wchar_t kDCIMDirName[] = L"DCIM"; | |
| 20 #else | |
| 21 const char kDCIMDirName[] = "DCIM"; | |
| 22 #endif | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 using content::BrowserThread; | |
| 27 | |
| 28 class MediaDeviceNotificationUtilsTest : public testing::Test { | |
| 29 public: | |
| 30 MediaDeviceNotificationUtilsTest() | |
| 31 : ui_thread_(BrowserThread::UI, &message_loop_), | |
| 32 file_thread_(BrowserThread::FILE) { } | |
| 33 virtual ~MediaDeviceNotificationUtilsTest() { } | |
| 34 | |
| 35 // Verify mounted device type. | |
| 36 void checkDeviceType(const FilePath::StringType& mount_point, | |
| 37 bool expected_val) { | |
| 38 if (expected_val) | |
| 39 EXPECT_TRUE(IsMediaDevice(mount_point)); | |
| 40 else | |
| 41 EXPECT_FALSE(IsMediaDevice(mount_point)); | |
| 42 } | |
| 43 | |
| 44 protected: | |
| 45 // Create mount point for the test device. | |
| 46 FilePath CreateMountPoint(bool create_dcim_dir) { | |
| 47 FilePath path(scoped_temp_dir_.path()); | |
| 48 if (create_dcim_dir) | |
| 49 path = path.Append(kDCIMDirName); | |
| 50 if (!file_util::CreateDirectory(path)) | |
| 51 return FilePath(); | |
| 52 return scoped_temp_dir_.path(); | |
| 53 } | |
| 54 | |
| 55 virtual void SetUp() OVERRIDE { | |
| 56 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | |
| 57 file_thread_.Start(); | |
| 58 } | |
| 59 | |
| 60 virtual void TearDown() { | |
| 61 WaitForFileThread(); | |
| 62 } | |
| 63 | |
| 64 static void PostQuitToUIThread() { | |
| 65 BrowserThread::PostTask(BrowserThread::UI, | |
| 66 FROM_HERE, | |
| 67 MessageLoop::QuitClosure()); | |
| 68 } | |
| 69 | |
| 70 static void WaitForFileThread() { | |
| 71 BrowserThread::PostTask(BrowserThread::FILE, | |
| 72 FROM_HERE, | |
| 73 base::Bind(&PostQuitToUIThread)); | |
| 74 MessageLoop::current()->Run(); | |
| 75 } | |
| 76 | |
| 77 MessageLoop message_loop_; | |
| 78 | |
| 79 private: | |
| 80 content::TestBrowserThread ui_thread_; | |
| 81 content::TestBrowserThread file_thread_; | |
| 82 ScopedTempDir scoped_temp_dir_; | |
| 83 }; | |
| 84 | |
| 85 // Test to verify that IsMediaDevice() function returns true for the given | |
| 86 // media device mount point. | |
| 87 TEST_F(MediaDeviceNotificationUtilsTest, MediaDeviceAttached) { | |
| 88 // Create a dummy mount point with DCIM Directory. | |
| 89 FilePath mount_point(CreateMountPoint(true)); | |
| 90 BrowserThread::PostTask( | |
| 91 BrowserThread::FILE, FROM_HERE, | |
| 92 base::Bind(&MediaDeviceNotificationUtilsTest::checkDeviceType, | |
| 93 base::Unretained(this), mount_point.value(), true)); | |
| 94 message_loop_.RunAllPending(); | |
| 95 } | |
| 96 | |
| 97 // Test to verify that IsMediaDevice() function returns false for a given | |
| 98 // non-media device mount point. | |
| 99 TEST_F(MediaDeviceNotificationUtilsTest, NonMediaDeviceAttached) { | |
| 100 // Create a dummy mount point without DCIM Directory. | |
| 101 FilePath mount_point(CreateMountPoint(false)); | |
| 102 BrowserThread::PostTask( | |
| 103 BrowserThread::FILE, FROM_HERE, | |
| 104 base::Bind(&MediaDeviceNotificationUtilsTest::checkDeviceType, | |
| 105 base::Unretained(this), mount_point.value(), false)); | |
| 106 message_loop_.RunAllPending(); | |
| 107 } | |
| 108 | |
| 109 } // namespace chrome | |
| OLD | NEW |