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