OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 using content::BrowserThread; | 26 using content::BrowserThread; |
27 | 27 |
28 namespace storage_monitor { | 28 namespace storage_monitor { |
29 | 29 |
30 class MediaStorageUtilTest : public testing::Test { | 30 class MediaStorageUtilTest : public testing::Test { |
31 public: | 31 public: |
32 MediaStorageUtilTest() | 32 MediaStorageUtilTest() |
33 : thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD) {} | 33 : thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD) {} |
34 virtual ~MediaStorageUtilTest() {} | 34 ~MediaStorageUtilTest() override {} |
35 | 35 |
36 // Verify mounted device type. | 36 // Verify mounted device type. |
37 void CheckDCIMDeviceType(const base::FilePath& mount_point) { | 37 void CheckDCIMDeviceType(const base::FilePath& mount_point) { |
38 EXPECT_TRUE(MediaStorageUtil::HasDcim(mount_point)); | 38 EXPECT_TRUE(MediaStorageUtil::HasDcim(mount_point)); |
39 } | 39 } |
40 | 40 |
41 void CheckNonDCIMDeviceType(const base::FilePath& mount_point) { | 41 void CheckNonDCIMDeviceType(const base::FilePath& mount_point) { |
42 EXPECT_FALSE(MediaStorageUtil::HasDcim(mount_point)); | 42 EXPECT_FALSE(MediaStorageUtil::HasDcim(mount_point)); |
43 } | 43 } |
44 | 44 |
45 void ProcessAttach(const std::string& id, | 45 void ProcessAttach(const std::string& id, |
46 const base::FilePath::StringType& location) { | 46 const base::FilePath::StringType& location) { |
47 StorageInfo info(id, location, base::string16(), base::string16(), | 47 StorageInfo info(id, location, base::string16(), base::string16(), |
48 base::string16(), 0); | 48 base::string16(), 0); |
49 monitor_->receiver()->ProcessAttach(info); | 49 monitor_->receiver()->ProcessAttach(info); |
50 } | 50 } |
51 | 51 |
52 protected: | 52 protected: |
53 // Create mount point for the test device. | 53 // Create mount point for the test device. |
54 base::FilePath CreateMountPoint(bool create_dcim_dir) { | 54 base::FilePath CreateMountPoint(bool create_dcim_dir) { |
55 base::FilePath path(scoped_temp_dir_.path()); | 55 base::FilePath path(scoped_temp_dir_.path()); |
56 if (create_dcim_dir) | 56 if (create_dcim_dir) |
57 path = path.Append(kDCIMDirectoryName); | 57 path = path.Append(kDCIMDirectoryName); |
58 if (!base::CreateDirectory(path)) | 58 if (!base::CreateDirectory(path)) |
59 return base::FilePath(); | 59 return base::FilePath(); |
60 return scoped_temp_dir_.path(); | 60 return scoped_temp_dir_.path(); |
61 } | 61 } |
62 | 62 |
63 virtual void SetUp() override { | 63 void SetUp() override { |
64 monitor_ = TestStorageMonitor::CreateAndInstall(); | 64 monitor_ = TestStorageMonitor::CreateAndInstall(); |
65 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 65 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
66 } | 66 } |
67 | 67 |
68 virtual void TearDown() override { | 68 void TearDown() override { |
69 WaitForFileThread(); | 69 WaitForFileThread(); |
70 TestStorageMonitor::Destroy(); | 70 TestStorageMonitor::Destroy(); |
71 } | 71 } |
72 | 72 |
73 static void PostQuitToUIThread() { | 73 static void PostQuitToUIThread() { |
74 BrowserThread::PostTask(BrowserThread::UI, | 74 BrowserThread::PostTask(BrowserThread::UI, |
75 FROM_HERE, | 75 FROM_HERE, |
76 base::MessageLoop::QuitClosure()); | 76 base::MessageLoop::QuitClosure()); |
77 } | 77 } |
78 | 78 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 event.Reset(); | 147 event.Reset(); |
148 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 148 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
149 base::Bind(&MediaStorageUtil::FilterAttachedDevices, | 149 base::Bind(&MediaStorageUtil::FilterAttachedDevices, |
150 base::Unretained(&devices), signal_event)); | 150 base::Unretained(&devices), signal_event)); |
151 event.Wait(); | 151 event.Wait(); |
152 | 152 |
153 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); | 153 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); |
154 } | 154 } |
155 | 155 |
156 } // namespace storage_monitor | 156 } // namespace storage_monitor |
OLD | NEW |