| 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/cros/mock_mount_library.h" | |
| 6 | |
| 7 #include "base/message_loop.h" | |
| 8 #include "base/string_util.h" | |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 | |
| 12 namespace chromeos { | |
| 13 | |
| 14 using content::BrowserThread; | |
| 15 using testing::_; | |
| 16 using testing::AnyNumber; | |
| 17 using testing::Invoke; | |
| 18 using testing::ReturnRef; | |
| 19 | |
| 20 const char* kTestSystemPath = "/this/system/path"; | |
| 21 const char* kTestSystemPathPrefix = "/this/system"; | |
| 22 const char* kTestDevicePath = "/this/device/path"; | |
| 23 const char* kTestMountPath = "/media/foofoo"; | |
| 24 const char* kTestFilePath = "/this/file/path"; | |
| 25 const char* kTestDeviceLabel = "A label"; | |
| 26 const char* kTestDriveLabel = "Another label"; | |
| 27 const char* kTestParentPath = "/this/is/my/parent"; | |
| 28 | |
| 29 void MockMountLibrary::AddObserverInternal(MountLibrary::Observer* observer) { | |
| 30 observers_.AddObserver(observer); | |
| 31 } | |
| 32 | |
| 33 void MockMountLibrary::RemoveObserverInternal( | |
| 34 MountLibrary::Observer* observer) { | |
| 35 observers_.RemoveObserver(observer); | |
| 36 } | |
| 37 | |
| 38 MockMountLibrary::MockMountLibrary() { | |
| 39 ON_CALL(*this, AddObserver(_)) | |
| 40 .WillByDefault(Invoke(this, &MockMountLibrary::AddObserverInternal)); | |
| 41 ON_CALL(*this, RemoveObserver(_)) | |
| 42 .WillByDefault(Invoke(this, &MockMountLibrary::RemoveObserverInternal)); | |
| 43 ON_CALL(*this, disks()) | |
| 44 .WillByDefault(Invoke(this, &MockMountLibrary::disksInternal)); | |
| 45 } | |
| 46 | |
| 47 MockMountLibrary::~MockMountLibrary() { | |
| 48 | |
| 49 } | |
| 50 | |
| 51 void MockMountLibrary::FireDeviceInsertEvents() { | |
| 52 | |
| 53 scoped_ptr<MountLibrary::Disk> disk1(new MountLibrary::Disk( | |
| 54 std::string(kTestDevicePath), | |
| 55 std::string(), | |
| 56 std::string(kTestSystemPath), | |
| 57 std::string(kTestFilePath), | |
| 58 std::string(), | |
| 59 std::string(kTestDriveLabel), | |
| 60 std::string(kTestParentPath), | |
| 61 std::string(kTestSystemPathPrefix), | |
| 62 FLASH, | |
| 63 4294967295U, | |
| 64 false, | |
| 65 false, | |
| 66 true, | |
| 67 false, | |
| 68 false)); | |
| 69 | |
| 70 disks_.clear(); | |
| 71 disks_.insert(std::pair<std::string, MountLibrary::Disk*>( | |
| 72 std::string(kTestDevicePath), disk1.get())); | |
| 73 | |
| 74 // Device Added | |
| 75 chromeos::MountLibraryEventType evt; | |
| 76 evt = chromeos::MOUNT_DEVICE_ADDED; | |
| 77 UpdateDeviceChanged(evt, kTestSystemPath); | |
| 78 | |
| 79 // Disk Added | |
| 80 evt = chromeos::MOUNT_DISK_ADDED; | |
| 81 UpdateDiskChanged(evt, disk1.get()); | |
| 82 | |
| 83 // Disk Changed | |
| 84 scoped_ptr<MountLibrary::Disk> disk2(new MountLibrary::Disk( | |
| 85 std::string(kTestDevicePath), | |
| 86 std::string(kTestMountPath), | |
| 87 std::string(kTestSystemPath), | |
| 88 std::string(kTestFilePath), | |
| 89 std::string(kTestDeviceLabel), | |
| 90 std::string(kTestDriveLabel), | |
| 91 std::string(kTestParentPath), | |
| 92 std::string(kTestSystemPathPrefix), | |
| 93 FLASH, | |
| 94 1073741824, | |
| 95 false, | |
| 96 false, | |
| 97 true, | |
| 98 false, | |
| 99 false)); | |
| 100 disks_.clear(); | |
| 101 disks_.insert(std::pair<std::string, MountLibrary::Disk*>( | |
| 102 std::string(kTestDevicePath), disk2.get())); | |
| 103 evt = chromeos::MOUNT_DISK_CHANGED; | |
| 104 UpdateDiskChanged(evt, disk2.get()); | |
| 105 } | |
| 106 | |
| 107 void MockMountLibrary::FireDeviceRemoveEvents() { | |
| 108 scoped_ptr<MountLibrary::Disk> disk(new MountLibrary::Disk( | |
| 109 std::string(kTestDevicePath), | |
| 110 std::string(kTestMountPath), | |
| 111 std::string(kTestSystemPath), | |
| 112 std::string(kTestFilePath), | |
| 113 std::string(kTestDeviceLabel), | |
| 114 std::string(kTestDriveLabel), | |
| 115 std::string(kTestParentPath), | |
| 116 std::string(kTestSystemPathPrefix), | |
| 117 FLASH, | |
| 118 1073741824, | |
| 119 false, | |
| 120 false, | |
| 121 true, | |
| 122 false, | |
| 123 false)); | |
| 124 disks_.clear(); | |
| 125 disks_.insert(std::pair<std::string, MountLibrary::Disk*>( | |
| 126 std::string(kTestDevicePath), disk.get())); | |
| 127 UpdateDiskChanged(chromeos::MOUNT_DISK_REMOVED, disk.get()); | |
| 128 } | |
| 129 | |
| 130 void MockMountLibrary::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 MockMountLibrary::UpdateDiskChanged(MountLibraryEventType evt, | |
| 152 const MountLibrary::Disk* disk) { | |
| 153 // Make sure we run on UI thread. | |
| 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 155 | |
| 156 FOR_EACH_OBSERVER(Observer, observers_, DiskChanged(evt, disk)); | |
| 157 } | |
| 158 | |
| 159 | |
| 160 void MockMountLibrary::UpdateDeviceChanged(MountLibraryEventType evt, | |
| 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(evt, path)); | |
| 166 } | |
| 167 | |
| 168 } // namespace chromeos | |
| OLD | NEW |