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/message_loop.h" | 9 #include "base/message_loop/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 "chrome/test/base/testing_browser_process.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace chrome { | |
22 | |
23 namespace { | 21 namespace { |
24 | 22 |
25 const char kImageCaptureDeviceId[] = "ic:xyz"; | 23 const char kImageCaptureDeviceId[] = "ic:xyz"; |
26 | 24 |
27 } // namespace | 25 } // namespace |
28 | 26 |
29 using content::BrowserThread; | 27 using content::BrowserThread; |
30 | 28 |
31 class MediaStorageUtilTest : public testing::Test { | 29 class MediaStorageUtilTest : public testing::Test { |
32 public: | 30 public: |
(...skipping 23 matching lines...) Expand all Loading... |
56 base::FilePath CreateMountPoint(bool create_dcim_dir) { | 54 base::FilePath CreateMountPoint(bool create_dcim_dir) { |
57 base::FilePath path(scoped_temp_dir_.path()); | 55 base::FilePath path(scoped_temp_dir_.path()); |
58 if (create_dcim_dir) | 56 if (create_dcim_dir) |
59 path = path.Append(kDCIMDirectoryName); | 57 path = path.Append(kDCIMDirectoryName); |
60 if (!file_util::CreateDirectory(path)) | 58 if (!file_util::CreateDirectory(path)) |
61 return base::FilePath(); | 59 return base::FilePath(); |
62 return scoped_temp_dir_.path(); | 60 return scoped_temp_dir_.path(); |
63 } | 61 } |
64 | 62 |
65 virtual void SetUp() OVERRIDE { | 63 virtual void SetUp() OVERRIDE { |
66 monitor_ = chrome::test::TestStorageMonitor::CreateAndInstall(); | 64 monitor_ = TestStorageMonitor::CreateAndInstall(); |
67 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 65 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
68 file_thread_.Start(); | 66 file_thread_.Start(); |
69 } | 67 } |
70 | 68 |
71 virtual void TearDown() OVERRIDE { | 69 virtual void TearDown() OVERRIDE { |
72 WaitForFileThread(); | 70 WaitForFileThread(); |
73 chrome::test::TestStorageMonitor::RemoveSingleton(); | 71 TestStorageMonitor::RemoveSingleton(); |
74 } | 72 } |
75 | 73 |
76 static void PostQuitToUIThread() { | 74 static void PostQuitToUIThread() { |
77 BrowserThread::PostTask(BrowserThread::UI, | 75 BrowserThread::PostTask(BrowserThread::UI, |
78 FROM_HERE, | 76 FROM_HERE, |
79 base::MessageLoop::QuitClosure()); | 77 base::MessageLoop::QuitClosure()); |
80 } | 78 } |
81 | 79 |
82 static void WaitForFileThread() { | 80 static void WaitForFileThread() { |
83 BrowserThread::PostTask(BrowserThread::FILE, | 81 BrowserThread::PostTask(BrowserThread::FILE, |
84 FROM_HERE, | 82 FROM_HERE, |
85 base::Bind(&PostQuitToUIThread)); | 83 base::Bind(&PostQuitToUIThread)); |
86 base::MessageLoop::current()->Run(); | 84 base::MessageLoop::current()->Run(); |
87 } | 85 } |
88 | 86 |
89 base::MessageLoop message_loop_; | 87 base::MessageLoop message_loop_; |
90 | 88 |
91 private: | 89 private: |
92 chrome::test::TestStorageMonitor* monitor_; | 90 TestStorageMonitor* monitor_; |
93 content::TestBrowserThread ui_thread_; | 91 content::TestBrowserThread ui_thread_; |
94 content::TestBrowserThread file_thread_; | 92 content::TestBrowserThread file_thread_; |
95 base::ScopedTempDir scoped_temp_dir_; | 93 base::ScopedTempDir scoped_temp_dir_; |
96 }; | 94 }; |
97 | 95 |
98 // Test to verify that HasDcim() function returns true for the given media | 96 // Test to verify that HasDcim() function returns true for the given media |
99 // device mount point. | 97 // device mount point. |
100 TEST_F(MediaStorageUtilTest, MediaDeviceAttached) { | 98 TEST_F(MediaStorageUtilTest, MediaDeviceAttached) { |
101 // Create a dummy mount point with DCIM Directory. | 99 // Create a dummy mount point with DCIM Directory. |
102 base::FilePath mount_point(CreateMountPoint(true)); | 100 base::FilePath mount_point(CreateMountPoint(true)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 FILE_PATH_LITERAL("/location")); | 146 FILE_PATH_LITERAL("/location")); |
149 devices.insert(kImageCaptureDeviceId); | 147 devices.insert(kImageCaptureDeviceId); |
150 event.Reset(); | 148 event.Reset(); |
151 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 149 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
152 base::Bind(&MediaStorageUtil::FilterAttachedDevices, | 150 base::Bind(&MediaStorageUtil::FilterAttachedDevices, |
153 base::Unretained(&devices), signal_event)); | 151 base::Unretained(&devices), signal_event)); |
154 event.Wait(); | 152 event.Wait(); |
155 | 153 |
156 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); | 154 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); |
157 } | 155 } |
158 | |
159 } // namespace chrome | |
OLD | NEW |