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