OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "chrome/browser/storage_monitor/media_storage_util.h" | 12 #include "chrome/browser/storage_monitor/media_storage_util.h" |
13 #include "chrome/browser/storage_monitor/removable_device_constants.h" | 13 #include "chrome/browser/storage_monitor/removable_device_constants.h" |
14 #include "chrome/browser/storage_monitor/storage_monitor.h" | 14 #include "chrome/browser/storage_monitor/storage_monitor.h" |
15 #include "chrome/browser/storage_monitor/test_storage_monitor.h" | 15 #include "chrome/browser/storage_monitor/test_storage_monitor.h" |
| 16 #include "chrome/test/base/testing_browser_process.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace chrome { | 21 namespace chrome { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 const char kImageCaptureDeviceId[] = "ic:xyz"; | 25 const char kImageCaptureDeviceId[] = "ic:xyz"; |
25 | 26 |
(...skipping 14 matching lines...) Expand all Loading... |
40 if (expected_val) | 41 if (expected_val) |
41 EXPECT_TRUE(MediaStorageUtil::HasDcim(mount_point)); | 42 EXPECT_TRUE(MediaStorageUtil::HasDcim(mount_point)); |
42 else | 43 else |
43 EXPECT_FALSE(MediaStorageUtil::HasDcim(mount_point)); | 44 EXPECT_FALSE(MediaStorageUtil::HasDcim(mount_point)); |
44 } | 45 } |
45 | 46 |
46 void ProcessAttach(const std::string& id, | 47 void ProcessAttach(const std::string& id, |
47 const string16& name, | 48 const string16& name, |
48 const base::FilePath::StringType& location) { | 49 const base::FilePath::StringType& location) { |
49 StorageInfo info(id, name, location, string16(), string16(), string16(), 0); | 50 StorageInfo info(id, name, location, string16(), string16(), string16(), 0); |
50 monitor_.receiver()->ProcessAttach(info); | 51 monitor_->receiver()->ProcessAttach(info); |
51 } | 52 } |
52 | 53 |
53 protected: | 54 protected: |
54 // Create mount point for the test device. | 55 // Create mount point for the test device. |
55 base::FilePath CreateMountPoint(bool create_dcim_dir) { | 56 base::FilePath CreateMountPoint(bool create_dcim_dir) { |
56 base::FilePath path(scoped_temp_dir_.path()); | 57 base::FilePath path(scoped_temp_dir_.path()); |
57 if (create_dcim_dir) | 58 if (create_dcim_dir) |
58 path = path.Append(kDCIMDirectoryName); | 59 path = path.Append(kDCIMDirectoryName); |
59 if (!file_util::CreateDirectory(path)) | 60 if (!file_util::CreateDirectory(path)) |
60 return base::FilePath(); | 61 return base::FilePath(); |
61 return scoped_temp_dir_.path(); | 62 return scoped_temp_dir_.path(); |
62 } | 63 } |
63 | 64 |
64 virtual void SetUp() OVERRIDE { | 65 virtual void SetUp() OVERRIDE { |
| 66 monitor_ = chrome::test::TestStorageMonitor::CreateAndInstall(); |
65 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 67 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
66 file_thread_.Start(); | 68 file_thread_.Start(); |
67 } | 69 } |
68 | 70 |
69 virtual void TearDown() { | 71 virtual void TearDown() OVERRIDE { |
70 WaitForFileThread(); | 72 WaitForFileThread(); |
71 } | 73 } |
72 | 74 |
73 static void PostQuitToUIThread() { | 75 static void PostQuitToUIThread() { |
74 BrowserThread::PostTask(BrowserThread::UI, | 76 BrowserThread::PostTask(BrowserThread::UI, |
75 FROM_HERE, | 77 FROM_HERE, |
76 base::MessageLoop::QuitClosure()); | 78 base::MessageLoop::QuitClosure()); |
77 } | 79 } |
78 | 80 |
79 static void WaitForFileThread() { | 81 static void WaitForFileThread() { |
80 BrowserThread::PostTask(BrowserThread::FILE, | 82 BrowserThread::PostTask(BrowserThread::FILE, |
81 FROM_HERE, | 83 FROM_HERE, |
82 base::Bind(&PostQuitToUIThread)); | 84 base::Bind(&PostQuitToUIThread)); |
83 base::MessageLoop::current()->Run(); | 85 base::MessageLoop::current()->Run(); |
84 } | 86 } |
85 | 87 |
86 base::MessageLoop message_loop_; | 88 base::MessageLoop message_loop_; |
87 | 89 |
88 private: | 90 private: |
89 chrome::test::TestStorageMonitor monitor_; | 91 chrome::test::TestStorageMonitor* monitor_; |
90 content::TestBrowserThread ui_thread_; | 92 content::TestBrowserThread ui_thread_; |
91 content::TestBrowserThread file_thread_; | 93 content::TestBrowserThread file_thread_; |
92 base::ScopedTempDir scoped_temp_dir_; | 94 base::ScopedTempDir scoped_temp_dir_; |
93 }; | 95 }; |
94 | 96 |
95 // Test to verify that HasDcim() function returns true for the given media | 97 // Test to verify that HasDcim() function returns true for the given media |
96 // device mount point. | 98 // device mount point. |
97 TEST_F(MediaStorageUtilTest, MediaDeviceAttached) { | 99 TEST_F(MediaStorageUtilTest, MediaDeviceAttached) { |
98 // Create a dummy mount point with DCIM Directory. | 100 // Create a dummy mount point with DCIM Directory. |
99 base::FilePath mount_point(CreateMountPoint(true)); | 101 base::FilePath mount_point(CreateMountPoint(true)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 event.Reset(); | 149 event.Reset(); |
148 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 150 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
149 base::Bind(&MediaStorageUtil::FilterAttachedDevices, | 151 base::Bind(&MediaStorageUtil::FilterAttachedDevices, |
150 base::Unretained(&devices), signal_event)); | 152 base::Unretained(&devices), signal_event)); |
151 event.Wait(); | 153 event.Wait(); |
152 | 154 |
153 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); | 155 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); |
154 } | 156 } |
155 | 157 |
156 } // namespace chrome | 158 } // namespace chrome |
OLD | NEW |