OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/file_manager/device_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/device_event_router.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 device_event_router->OnDeviceAdded("/device/test"); | 133 device_event_router->OnDeviceAdded("/device/test"); |
134 base::RunLoop().RunUntilIdle(); | 134 base::RunLoop().RunUntilIdle(); |
135 device_event_router->OnDiskAdded(disk, true); | 135 device_event_router->OnDiskAdded(disk, true); |
136 device_event_router->OnVolumeMounted( | 136 device_event_router->OnVolumeMounted( |
137 chromeos::MOUNT_ERROR_NONE, volumeInfo, false); | 137 chromeos::MOUNT_ERROR_NONE, volumeInfo, false); |
138 device_event_router->OnVolumeUnmounted(chromeos::MOUNT_ERROR_NONE, | 138 device_event_router->OnVolumeUnmounted(chromeos::MOUNT_ERROR_NONE, |
139 volumeInfo); | 139 volumeInfo); |
140 device_event_router->OnDiskRemoved(disk_unmounted); | 140 device_event_router->OnDiskRemoved(disk_unmounted); |
141 device_event_router->OnDeviceRemoved("/device/test"); | 141 device_event_router->OnDeviceRemoved("/device/test"); |
142 ASSERT_EQ(2u, device_event_router->events.size()); | 142 ASSERT_EQ(2u, device_event_router->events.size()); |
143 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_ADDED, | 143 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_SCAN_STARTED, |
144 device_event_router->events[0].type); | 144 device_event_router->events[0].type); |
145 EXPECT_EQ("/device/test", device_event_router->events[0].device_path); | 145 EXPECT_EQ("/device/test", device_event_router->events[0].device_path); |
146 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_REMOVED, | 146 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_REMOVED, |
147 device_event_router->events[1].type); | 147 device_event_router->events[1].type); |
148 EXPECT_EQ("/device/test", device_event_router->events[1].device_path); | 148 EXPECT_EQ("/device/test", device_event_router->events[1].device_path); |
149 } | 149 } |
150 | 150 |
151 TEST_F(DeviceEventRouterTest, DeviceScanCancelled) { | 151 TEST_F(DeviceEventRouterTest, DeviceScanCancelled) { |
152 const Disk disk = CreateTestDisk("/device/test", "/mount/path1"); | 152 const Disk disk = CreateTestDisk("/device/test", "/mount/path1"); |
153 const Disk disk_unmounted = CreateTestDisk("/device/test", ""); | 153 const Disk disk_unmounted = CreateTestDisk("/device/test", ""); |
154 const VolumeInfo volumeInfo = | 154 const VolumeInfo volumeInfo = |
155 CreateTestVolumeInfo("/device/test", "/mount/path1"); | 155 CreateTestVolumeInfo("/device/test", "/mount/path1"); |
156 device_event_router->OnDeviceAdded("/device/test"); | 156 device_event_router->OnDeviceAdded("/device/test"); |
157 base::RunLoop().RunUntilIdle(); | 157 base::RunLoop().RunUntilIdle(); |
158 device_event_router->OnDiskAdded(disk, false); | 158 device_event_router->OnDiskAdded(disk, false); |
159 device_event_router->OnDiskRemoved(disk_unmounted); | 159 device_event_router->OnDiskRemoved(disk_unmounted); |
160 device_event_router->OnDeviceRemoved("/device/test"); | 160 device_event_router->OnDeviceRemoved("/device/test"); |
161 ASSERT_EQ(3u, device_event_router->events.size()); | 161 ASSERT_EQ(3u, device_event_router->events.size()); |
162 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_ADDED, | 162 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_SCAN_STARTED, |
163 device_event_router->events[0].type); | 163 device_event_router->events[0].type); |
164 EXPECT_EQ("/device/test", device_event_router->events[0].device_path); | 164 EXPECT_EQ("/device/test", device_event_router->events[0].device_path); |
165 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_SCAN_CANCELED, | 165 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_SCAN_CANCELLED, |
166 device_event_router->events[1].type); | 166 device_event_router->events[1].type); |
167 EXPECT_EQ("/device/test", device_event_router->events[1].device_path); | 167 EXPECT_EQ("/device/test", device_event_router->events[1].device_path); |
168 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_REMOVED, | 168 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_REMOVED, |
169 device_event_router->events[2].type); | 169 device_event_router->events[2].type); |
170 EXPECT_EQ("/device/test", device_event_router->events[2].device_path); | 170 EXPECT_EQ("/device/test", device_event_router->events[2].device_path); |
171 } | 171 } |
172 | 172 |
173 TEST_F(DeviceEventRouterTest, HardUnplugged) { | 173 TEST_F(DeviceEventRouterTest, HardUnplugged) { |
174 const Disk disk1 = CreateTestDisk("/device/test", "/mount/path1"); | 174 const Disk disk1 = CreateTestDisk("/device/test", "/mount/path1"); |
175 const Disk disk2 = CreateTestDisk("/device/test", "/mount/path2"); | 175 const Disk disk2 = CreateTestDisk("/device/test", "/mount/path2"); |
176 device_event_router->OnDeviceAdded("/device/test"); | 176 device_event_router->OnDeviceAdded("/device/test"); |
177 device_event_router->OnDiskAdded(disk1, true); | 177 device_event_router->OnDiskAdded(disk1, true); |
178 device_event_router->OnDiskAdded(disk2, true); | 178 device_event_router->OnDiskAdded(disk2, true); |
179 device_event_router->OnDiskRemoved(disk1); | 179 device_event_router->OnDiskRemoved(disk1); |
180 device_event_router->OnDiskRemoved(disk2); | 180 device_event_router->OnDiskRemoved(disk2); |
181 device_event_router->OnDeviceRemoved(kTestDevicePath); | 181 device_event_router->OnDeviceRemoved(kTestDevicePath); |
182 base::RunLoop().RunUntilIdle(); | 182 base::RunLoop().RunUntilIdle(); |
183 ASSERT_EQ(2u, device_event_router->events.size()); | 183 ASSERT_EQ(2u, device_event_router->events.size()); |
184 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_HARD_UNPLUGGED, | 184 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_HARD_UNPLUGGED, |
185 device_event_router->events[0].type); | 185 device_event_router->events[0].type); |
186 EXPECT_EQ("/device/test", device_event_router->events[0].device_path); | 186 EXPECT_EQ("/device/test", device_event_router->events[0].device_path); |
187 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_REMOVED, | 187 EXPECT_EQ(file_browser_private::DEVICE_EVENT_TYPE_REMOVED, |
188 device_event_router->events[1].type); | 188 device_event_router->events[1].type); |
189 EXPECT_EQ("/device/test", device_event_router->events[1].device_path); | 189 EXPECT_EQ("/device/test", device_event_router->events[1].device_path); |
190 } | 190 } |
191 | 191 |
192 } // namespace file_manager | 192 } // namespace file_manager |
OLD | NEW |