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 chrome::test::TestStorageMonitor::RemoveSingleton(); |
| 67 monitor_ = new chrome::test::TestStorageMonitor; |
| 68 TestingBrowserProcess::GetGlobal()->SetStorageMonitor(monitor_); |
| 69 |
65 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 70 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
66 file_thread_.Start(); | 71 file_thread_.Start(); |
67 } | 72 } |
68 | 73 |
69 virtual void TearDown() { | 74 virtual void TearDown() OVERRIDE { |
70 WaitForFileThread(); | 75 WaitForFileThread(); |
71 } | 76 } |
72 | 77 |
73 static void PostQuitToUIThread() { | 78 static void PostQuitToUIThread() { |
74 BrowserThread::PostTask(BrowserThread::UI, | 79 BrowserThread::PostTask(BrowserThread::UI, |
75 FROM_HERE, | 80 FROM_HERE, |
76 base::MessageLoop::QuitClosure()); | 81 base::MessageLoop::QuitClosure()); |
77 } | 82 } |
78 | 83 |
79 static void WaitForFileThread() { | 84 static void WaitForFileThread() { |
80 BrowserThread::PostTask(BrowserThread::FILE, | 85 BrowserThread::PostTask(BrowserThread::FILE, |
81 FROM_HERE, | 86 FROM_HERE, |
82 base::Bind(&PostQuitToUIThread)); | 87 base::Bind(&PostQuitToUIThread)); |
83 base::MessageLoop::current()->Run(); | 88 base::MessageLoop::current()->Run(); |
84 } | 89 } |
85 | 90 |
86 base::MessageLoop message_loop_; | 91 base::MessageLoop message_loop_; |
87 | 92 |
88 private: | 93 private: |
89 chrome::test::TestStorageMonitor monitor_; | 94 // Weak pointer to TestingBrowserProcess-owned storage monitor. |
| 95 chrome::test::TestStorageMonitor* monitor_; |
90 content::TestBrowserThread ui_thread_; | 96 content::TestBrowserThread ui_thread_; |
91 content::TestBrowserThread file_thread_; | 97 content::TestBrowserThread file_thread_; |
92 base::ScopedTempDir scoped_temp_dir_; | 98 base::ScopedTempDir scoped_temp_dir_; |
93 }; | 99 }; |
94 | 100 |
95 // Test to verify that HasDcim() function returns true for the given media | 101 // Test to verify that HasDcim() function returns true for the given media |
96 // device mount point. | 102 // device mount point. |
97 TEST_F(MediaStorageUtilTest, MediaDeviceAttached) { | 103 TEST_F(MediaStorageUtilTest, MediaDeviceAttached) { |
98 // Create a dummy mount point with DCIM Directory. | 104 // Create a dummy mount point with DCIM Directory. |
99 base::FilePath mount_point(CreateMountPoint(true)); | 105 base::FilePath mount_point(CreateMountPoint(true)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 event.Reset(); | 153 event.Reset(); |
148 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 154 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
149 base::Bind(&MediaStorageUtil::FilterAttachedDevices, | 155 base::Bind(&MediaStorageUtil::FilterAttachedDevices, |
150 base::Unretained(&devices), signal_event)); | 156 base::Unretained(&devices), signal_event)); |
151 event.Wait(); | 157 event.Wait(); |
152 | 158 |
153 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); | 159 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); |
154 } | 160 } |
155 | 161 |
156 } // namespace chrome | 162 } // namespace chrome |
OLD | NEW |