| 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/disks/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 namespace disks { |
| 19 |
| 20 namespace { |
| 21 |
| 22 const char* kTestSystemPath = "/this/system/path"; |
| 23 const char* kTestSystemPathPrefix = "/this/system"; |
| 24 const char* kTestDevicePath = "/this/device/path"; |
| 25 const char* kTestMountPath = "/media/foofoo"; |
| 26 const char* kTestFilePath = "/this/file/path"; |
| 27 const char* kTestDeviceLabel = "A label"; |
| 28 const char* kTestDriveLabel = "Another label"; |
| 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::NotifyDeviceInsertEvents() { |
| 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(kTestSystemPathPrefix), |
| 64 FLASH, |
| 65 4294967295U, |
| 66 false, // is_parent |
| 67 false, // is_read_only |
| 68 true, // has_media |
| 69 false, // on_boot_device |
| 70 false)); // is_hidden |
| 71 |
| 72 disks_.clear(); |
| 73 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>( |
| 74 std::string(kTestDevicePath), disk1.get())); |
| 75 |
| 76 // Device Added |
| 77 DiskMountManagerEventType event; |
| 78 event = MOUNT_DEVICE_ADDED; |
| 79 NotifyDeviceChanged(event, kTestSystemPath); |
| 80 |
| 81 // Disk Added |
| 82 event = MOUNT_DISK_ADDED; |
| 83 NotifyDiskChanged(event, disk1.get()); |
| 84 |
| 85 // Disk Changed |
| 86 scoped_ptr<DiskMountManager::Disk> disk2(new DiskMountManager::Disk( |
| 87 std::string(kTestDevicePath), |
| 88 std::string(kTestMountPath), |
| 89 std::string(kTestSystemPath), |
| 90 std::string(kTestFilePath), |
| 91 std::string(kTestDeviceLabel), |
| 92 std::string(kTestDriveLabel), |
| 93 std::string(kTestSystemPathPrefix), |
| 94 FLASH, |
| 95 1073741824, |
| 96 false, // is_parent |
| 97 false, // is_read_only |
| 98 true, // has_media |
| 99 false, // on_boot_device |
| 100 false)); // is_hidden |
| 101 disks_.clear(); |
| 102 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>( |
| 103 std::string(kTestDevicePath), disk2.get())); |
| 104 event = MOUNT_DISK_CHANGED; |
| 105 NotifyDiskChanged(event, disk2.get()); |
| 106 } |
| 107 |
| 108 void MockDiskMountManager::NotifyDeviceRemoveEvents() { |
| 109 scoped_ptr<DiskMountManager::Disk> disk(new DiskMountManager::Disk( |
| 110 std::string(kTestDevicePath), |
| 111 std::string(kTestMountPath), |
| 112 std::string(kTestSystemPath), |
| 113 std::string(kTestFilePath), |
| 114 std::string(kTestDeviceLabel), |
| 115 std::string(kTestDriveLabel), |
| 116 std::string(kTestSystemPathPrefix), |
| 117 FLASH, |
| 118 1073741824, |
| 119 false, // is_parent |
| 120 false, // is_read_only |
| 121 true, // has_media |
| 122 false, // on_boot_device |
| 123 false)); // is_hidden |
| 124 disks_.clear(); |
| 125 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>( |
| 126 std::string(kTestDevicePath), disk.get())); |
| 127 NotifyDiskChanged(MOUNT_DISK_REMOVED, disk.get()); |
| 128 } |
| 129 |
| 130 void MockDiskMountManager::SetupDefaultReplies() { |
| 131 EXPECT_CALL(*this, AddObserver(_)) |
| 132 .Times(AnyNumber()); |
| 133 EXPECT_CALL(*this, RemoveObserver(_)) |
| 134 .Times(AnyNumber()); |
| 135 EXPECT_CALL(*this, disks()) |
| 136 .WillRepeatedly(ReturnRef(disks_)); |
| 137 EXPECT_CALL(*this, RequestMountInfoRefresh()) |
| 138 .Times(AnyNumber()); |
| 139 EXPECT_CALL(*this, MountPath(_, _)) |
| 140 .Times(AnyNumber()); |
| 141 EXPECT_CALL(*this, UnmountPath(_)) |
| 142 .Times(AnyNumber()); |
| 143 EXPECT_CALL(*this, FormatUnmountedDevice(_)) |
| 144 .Times(AnyNumber()); |
| 145 EXPECT_CALL(*this, FormatMountedDevice(_)) |
| 146 .Times(AnyNumber()); |
| 147 EXPECT_CALL(*this, UnmountDeviceRecursive(_, _, _)) |
| 148 .Times(AnyNumber()); |
| 149 } |
| 150 |
| 151 void MockDiskMountManager::NotifyDiskChanged(DiskMountManagerEventType event, |
| 152 const DiskMountManager::Disk* disk) |
| 153 { |
| 154 // Make sure we run on UI thread. |
| 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 156 |
| 157 FOR_EACH_OBSERVER(Observer, observers_, DiskChanged(event, disk)); |
| 158 } |
| 159 |
| 160 void MockDiskMountManager::NotifyDeviceChanged(DiskMountManagerEventType event, |
| 161 const std::string& path) { |
| 162 // Make sure we run on UI thread. |
| 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 164 |
| 165 FOR_EACH_OBSERVER(Observer, observers_, DeviceChanged(event, path)); |
| 166 } |
| 167 |
| 168 } // namespace disks |
| 169 } // namespace chromeos |
| OLD | NEW |