Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(622)

Side by Side Diff: chrome/browser/storage_monitor/storage_monitor_linux_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // StorageMonitorLinux unit tests. 5 // StorageMonitorLinux unit tests.
6 6
7 #include "chrome/browser/storage_monitor/storage_monitor_linux.h" 7 #include "chrome/browser/storage_monitor/storage_monitor_linux.h"
8 8
9 #include <mntent.h> 9 #include <mntent.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 115 }
116 if (device == kInvalidDevice) { 116 if (device == kInvalidDevice) {
117 return StorageInfo::MakeDeviceId(StorageInfo::FIXED_MASS_STORAGE, 117 return StorageInfo::MakeDeviceId(StorageInfo::FIXED_MASS_STORAGE,
118 kInvalidDevice); 118 kInvalidDevice);
119 } 119 }
120 return std::string(); 120 return std::string();
121 } 121 }
122 122
123 class TestStorageMonitorLinux : public StorageMonitorLinux { 123 class TestStorageMonitorLinux : public StorageMonitorLinux {
124 public: 124 public:
125 TestStorageMonitorLinux(const base::FilePath& path, MessageLoop* message_loop) 125 TestStorageMonitorLinux(const base::FilePath& path,
126 base::MessageLoop* message_loop)
126 : StorageMonitorLinux(path), 127 : StorageMonitorLinux(path),
127 message_loop_(message_loop) { 128 message_loop_(message_loop) {
128 SetMediaTransferProtocolManagerForTest( 129 SetMediaTransferProtocolManagerForTest(
129 new TestMediaTransferProtocolManagerLinux()); 130 new TestMediaTransferProtocolManagerLinux());
130 SetGetDeviceInfoCallbackForTest(base::Bind(&GetDeviceInfo)); 131 SetGetDeviceInfoCallbackForTest(base::Bind(&GetDeviceInfo));
131 } 132 }
132 virtual ~TestStorageMonitorLinux() {} 133 virtual ~TestStorageMonitorLinux() {}
133 134
134 private: 135 private:
135 virtual void UpdateMtab( 136 virtual void UpdateMtab(
136 const MtabWatcherLinux::MountPointDeviceMap& new_mtab) OVERRIDE { 137 const MtabWatcherLinux::MountPointDeviceMap& new_mtab) OVERRIDE {
137 StorageMonitorLinux::UpdateMtab(new_mtab); 138 StorageMonitorLinux::UpdateMtab(new_mtab);
138 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 139 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
139 } 140 }
140 141
141 MessageLoop* message_loop_; 142 base::MessageLoop* message_loop_;
142 143
143 DISALLOW_COPY_AND_ASSIGN(TestStorageMonitorLinux); 144 DISALLOW_COPY_AND_ASSIGN(TestStorageMonitorLinux);
144 }; 145 };
145 146
146 class StorageMonitorLinuxTest : public testing::Test { 147 class StorageMonitorLinuxTest : public testing::Test {
147 public: 148 public:
148 struct MtabTestData { 149 struct MtabTestData {
149 MtabTestData(const std::string& mount_device, 150 MtabTestData(const std::string& mount_device,
150 const std::string& mount_point, 151 const std::string& mount_point,
151 const std::string& mount_type) 152 const std::string& mount_type)
152 : mount_device(mount_device), 153 : mount_device(mount_device),
153 mount_point(mount_point), 154 mount_point(mount_point),
154 mount_type(mount_type) { 155 mount_type(mount_type) {
155 } 156 }
156 157
157 const std::string mount_device; 158 const std::string mount_device;
158 const std::string mount_point; 159 const std::string mount_point;
159 const std::string mount_type; 160 const std::string mount_type;
160 }; 161 };
161 162
162 StorageMonitorLinuxTest() 163 StorageMonitorLinuxTest()
163 : message_loop_(MessageLoop::TYPE_IO), 164 : message_loop_(base::MessageLoop::TYPE_IO),
164 ui_thread_(content::BrowserThread::UI, &message_loop_), 165 ui_thread_(content::BrowserThread::UI, &message_loop_),
165 file_thread_(content::BrowserThread::FILE, &message_loop_) { 166 file_thread_(content::BrowserThread::FILE, &message_loop_) {
166 } 167 }
167 virtual ~StorageMonitorLinuxTest() {} 168 virtual ~StorageMonitorLinuxTest() {}
168 169
169 protected: 170 protected:
170 virtual void SetUp() OVERRIDE { 171 virtual void SetUp() OVERRIDE {
171 // Create and set up a temp dir with files for the test. 172 // Create and set up a temp dir with files for the test.
172 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); 173 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
173 base::FilePath test_dir = scoped_temp_dir_.path().AppendASCII("test_etc"); 174 base::FilePath test_dir = scoped_temp_dir_.path().AppendASCII("test_etc");
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 for (size_t i = 0; i < data_size; ++i) { 298 for (size_t i = 0; i < data_size; ++i) {
298 entry.mnt_fsname = const_cast<char*>(data[i].mount_device.c_str()); 299 entry.mnt_fsname = const_cast<char*>(data[i].mount_device.c_str());
299 entry.mnt_dir = const_cast<char*>(data[i].mount_point.c_str()); 300 entry.mnt_dir = const_cast<char*>(data[i].mount_point.c_str());
300 entry.mnt_type = const_cast<char*>(data[i].mount_type.c_str()); 301 entry.mnt_type = const_cast<char*>(data[i].mount_type.c_str());
301 ASSERT_EQ(0, addmntent(file, &entry)); 302 ASSERT_EQ(0, addmntent(file, &entry));
302 } 303 }
303 ASSERT_EQ(1, endmntent(file)); 304 ASSERT_EQ(1, endmntent(file));
304 } 305 }
305 306
306 // The message loop and file thread to run tests on. 307 // The message loop and file thread to run tests on.
307 MessageLoop message_loop_; 308 base::MessageLoop message_loop_;
308 content::TestBrowserThread ui_thread_; 309 content::TestBrowserThread ui_thread_;
309 content::TestBrowserThread file_thread_; 310 content::TestBrowserThread file_thread_;
310 311
311 scoped_ptr<MockRemovableStorageObserver> mock_storage_observer_; 312 scoped_ptr<MockRemovableStorageObserver> mock_storage_observer_;
312 313
313 // Temporary directory for created test data. 314 // Temporary directory for created test data.
314 base::ScopedTempDir scoped_temp_dir_; 315 base::ScopedTempDir scoped_temp_dir_;
315 // Path to the test mtab file. 316 // Path to the test mtab file.
316 base::FilePath mtab_file_; 317 base::FilePath mtab_file_;
317 318
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 GetStorageSize(test_path_a)); 684 GetStorageSize(test_path_a));
684 EXPECT_EQ(GetDevicePartitionSize(kDeviceNoDCIM), 685 EXPECT_EQ(GetDevicePartitionSize(kDeviceNoDCIM),
685 GetStorageSize(test_path_b)); 686 GetStorageSize(test_path_b));
686 EXPECT_EQ(GetDevicePartitionSize(kInvalidPath), 687 EXPECT_EQ(GetDevicePartitionSize(kInvalidPath),
687 GetStorageSize(base::FilePath(kInvalidPath))); 688 GetStorageSize(base::FilePath(kInvalidPath)));
688 } 689 }
689 690
690 } // namespace 691 } // namespace
691 692
692 } // namespace chrome 693 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698