Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/mock_disk_mount_manager.h" | |
| 6 | |
| 7 #include "base/message_loop.h" | |
| 8 #include "base/string_util.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 | |
| 11 using content::BrowserThread; | |
| 12 using testing::_; | |
| 13 using testing::AnyNumber; | |
| 14 using testing::Invoke; | |
| 15 using testing::ReturnRef; | |
| 16 | |
| 17 namespace chromeos { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 const char* kTestSystemPath = "/this/system/path"; | |
| 22 const char* kTestSystemPathPrefix = "/this/system"; | |
| 23 const char* kTestDevicePath = "/this/device/path"; | |
| 24 const char* kTestMountPath = "/media/foofoo"; | |
| 25 const char* kTestFilePath = "/this/file/path"; | |
| 26 const char* kTestDeviceLabel = "A label"; | |
| 27 const char* kTestDriveLabel = "Another label"; | |
| 28 const char* kTestParentPath = "/this/is/my/parent"; | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 void MockDiskMountManager::AddObserverInternal( | |
| 33 DiskMountManager::Observer* observer) { | |
| 34 observers_.AddObserver(observer); | |
| 35 } | |
| 36 | |
| 37 void MockDiskMountManager::RemoveObserverInternal( | |
| 38 DiskMountManager::Observer* observer) { | |
| 39 observers_.RemoveObserver(observer); | |
| 40 } | |
| 41 | |
| 42 MockDiskMountManager::MockDiskMountManager() { | |
| 43 ON_CALL(*this, AddObserver(_)) | |
| 44 .WillByDefault(Invoke(this, &MockDiskMountManager::AddObserverInternal)); | |
| 45 ON_CALL(*this, RemoveObserver(_)) | |
| 46 .WillByDefault(Invoke(this, | |
| 47 &MockDiskMountManager::RemoveObserverInternal)); | |
| 48 ON_CALL(*this, disks()) | |
| 49 .WillByDefault(Invoke(this, &MockDiskMountManager::disksInternal)); | |
| 50 } | |
| 51 | |
| 52 MockDiskMountManager::~MockDiskMountManager() { | |
| 53 } | |
| 54 | |
| 55 void MockDiskMountManager::FireDeviceInsertEvents() { | |
| 56 scoped_ptr<DiskMountManager::Disk> disk1(new DiskMountManager::Disk( | |
| 57 std::string(kTestDevicePath), | |
| 58 std::string(), | |
| 59 std::string(kTestSystemPath), | |
| 60 std::string(kTestFilePath), | |
| 61 std::string(), | |
| 62 std::string(kTestDriveLabel), | |
| 63 std::string(kTestParentPath), | |
| 64 std::string(kTestSystemPathPrefix), | |
| 65 FLASH, | |
| 66 4294967295U, | |
| 67 false, | |
| 68 false, | |
| 69 true, | |
| 70 false, | |
| 71 false)); | |
|
satorux1
2011/11/11 00:43:55
The booleans are unreadable. Would be nice to add
hashimoto
2011/11/11 08:00:53
Done.
| |
| 72 | |
| 73 disks_.clear(); | |
| 74 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>( | |
| 75 std::string(kTestDevicePath), disk1.get())); | |
| 76 | |
| 77 // Device Added | |
| 78 chromeos::DiskMountManagerEventType evt; | |
| 79 evt = chromeos::MOUNT_DEVICE_ADDED; | |
| 80 UpdateDeviceChanged(evt, kTestSystemPath); | |
| 81 | |
| 82 // Disk Added | |
| 83 evt = chromeos::MOUNT_DISK_ADDED; | |
| 84 UpdateDiskChanged(evt, disk1.get()); | |
| 85 | |
| 86 // Disk Changed | |
| 87 scoped_ptr<DiskMountManager::Disk> disk2(new DiskMountManager::Disk( | |
| 88 std::string(kTestDevicePath), | |
| 89 std::string(kTestMountPath), | |
| 90 std::string(kTestSystemPath), | |
| 91 std::string(kTestFilePath), | |
| 92 std::string(kTestDeviceLabel), | |
| 93 std::string(kTestDriveLabel), | |
| 94 std::string(kTestParentPath), | |
| 95 std::string(kTestSystemPathPrefix), | |
| 96 FLASH, | |
| 97 1073741824, | |
| 98 false, | |
| 99 false, | |
| 100 true, | |
| 101 false, | |
| 102 false)); | |
|
satorux1
2011/11/11 00:43:55
ditto.
hashimoto
2011/11/11 08:00:53
Done.
| |
| 103 disks_.clear(); | |
| 104 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>( | |
| 105 std::string(kTestDevicePath), disk2.get())); | |
| 106 evt = chromeos::MOUNT_DISK_CHANGED; | |
| 107 UpdateDiskChanged(evt, disk2.get()); | |
| 108 } | |
| 109 | |
| 110 void MockDiskMountManager::FireDeviceRemoveEvents() { | |
| 111 scoped_ptr<DiskMountManager::Disk> disk(new DiskMountManager::Disk( | |
| 112 std::string(kTestDevicePath), | |
| 113 std::string(kTestMountPath), | |
| 114 std::string(kTestSystemPath), | |
| 115 std::string(kTestFilePath), | |
| 116 std::string(kTestDeviceLabel), | |
| 117 std::string(kTestDriveLabel), | |
| 118 std::string(kTestParentPath), | |
| 119 std::string(kTestSystemPathPrefix), | |
| 120 FLASH, | |
| 121 1073741824, | |
| 122 false, | |
| 123 false, | |
| 124 true, | |
| 125 false, | |
| 126 false)); | |
| 127 disks_.clear(); | |
| 128 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>( | |
| 129 std::string(kTestDevicePath), disk.get())); | |
| 130 UpdateDiskChanged(chromeos::MOUNT_DISK_REMOVED, disk.get()); | |
| 131 } | |
| 132 | |
| 133 void MockDiskMountManager::SetupDefaultReplies() { | |
| 134 EXPECT_CALL(*this, AddObserver(_)) | |
| 135 .Times(AnyNumber()); | |
| 136 EXPECT_CALL(*this, RemoveObserver(_)) | |
| 137 .Times(AnyNumber()); | |
| 138 EXPECT_CALL(*this, disks()) | |
| 139 .WillRepeatedly(ReturnRef(disks_)); | |
| 140 EXPECT_CALL(*this, RequestMountInfoRefresh()) | |
| 141 .Times(AnyNumber()); | |
| 142 EXPECT_CALL(*this, MountPath(_, _)) | |
| 143 .Times(AnyNumber()); | |
| 144 EXPECT_CALL(*this, UnmountPath(_)) | |
| 145 .Times(AnyNumber()); | |
| 146 EXPECT_CALL(*this, FormatUnmountedDevice(_)) | |
| 147 .Times(AnyNumber()); | |
| 148 EXPECT_CALL(*this, FormatMountedDevice(_)) | |
| 149 .Times(AnyNumber()); | |
| 150 EXPECT_CALL(*this, UnmountDeviceRecursive(_, _, _)) | |
| 151 .Times(AnyNumber()); | |
| 152 } | |
| 153 | |
| 154 void MockDiskMountManager::UpdateDiskChanged(DiskMountManagerEventType evt, | |
| 155 const DiskMountManager::Disk* disk) | |
| 156 { | |
| 157 // Make sure we run on UI thread. | |
| 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 159 | |
| 160 FOR_EACH_OBSERVER(Observer, observers_, DiskChanged(evt, disk)); | |
| 161 } | |
| 162 | |
| 163 void MockDiskMountManager::UpdateDeviceChanged(DiskMountManagerEventType evt, | |
| 164 const std::string& path) { | |
| 165 // Make sure we run on UI thread. | |
| 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 167 | |
| 168 FOR_EACH_OBSERVER(Observer, observers_, DeviceChanged(evt, path)); | |
| 169 } | |
| 170 | |
| 171 } // namespace chromeos | |
| OLD | NEW |