| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "chromeos/dbus/mock_cros_disks_client.h" | 7 #include "chromeos/dbus/mock_cros_disks_client.h" |
| 8 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 8 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
| 9 #include "chromeos/disks/disk_mount_manager.h" | 9 #include "chromeos/disks/disk_mount_manager.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // Cros disks will respond asynchronoulsy, so let's drain the message loop. | 324 // Cros disks will respond asynchronoulsy, so let's drain the message loop. |
| 325 message_loop_.RunUntilIdle(); | 325 message_loop_.RunUntilIdle(); |
| 326 | 326 |
| 327 // The device mount should be gone. | 327 // The device mount should be gone. |
| 328 EXPECT_FALSE(HasMountPoint("/device/mount_path")); | 328 EXPECT_FALSE(HasMountPoint("/device/mount_path")); |
| 329 } | 329 } |
| 330 | 330 |
| 331 // Tests the case where there are two format requests for the same device. | 331 // Tests the case where there are two format requests for the same device. |
| 332 TEST_F(DiskMountManagerTest, Format_ConcurrentFormatCalls) { | 332 TEST_F(DiskMountManagerTest, Format_ConcurrentFormatCalls) { |
| 333 // Set up cros disks client mocks. | 333 // Set up cros disks client mocks. |
| 334 // Only the first format request should be processed (for the other one there | 334 // Only the first format request should be processed (the second unmount |
| 335 // should be an error before device unmount is attempted). | 335 // request fails because the device is already unmounted at that point). |
| 336 // CrosDisksClient will report that the format process for the first request | 336 // CrosDisksClient will report that the format process for the first request |
| 337 // is successfully started. | 337 // is successfully started. |
| 338 EXPECT_CALL(*mock_cros_disks_client_, | 338 EXPECT_CALL(*mock_cros_disks_client_, |
| 339 Unmount("/device/mount_path", chromeos::UNMOUNT_OPTIONS_NONE, | 339 Unmount("/device/mount_path", chromeos::UNMOUNT_OPTIONS_NONE, |
| 340 _, _)) | 340 _, _)) |
| 341 .WillOnce(MockUnmountPath(true)); | 341 .WillOnce(MockUnmountPath(true)) |
| 342 .WillOnce(MockUnmountPath(false)); |
| 342 | 343 |
| 343 EXPECT_CALL(*mock_cros_disks_client_, | 344 EXPECT_CALL(*mock_cros_disks_client_, |
| 344 FormatDevice("/device/source_path", "vfat", _, _)) | 345 FormatDevice("/device/source_path", "vfat", _, _)) |
| 345 .WillOnce(MockFormatDevice(true)); | 346 .WillOnce(MockFormatDevice(true)); |
| 346 | 347 |
| 347 // Set up expectations for observer mock. | 348 // Set up expectations for observer mock. |
| 348 // The observer should get two FORMAT_STARTED events, one for each format | 349 // The observer should get two FORMAT_STARTED events, one for each format |
| 349 // request, but with different error codes (the formatting will be started | 350 // request, but with different error codes (the formatting will be started |
| 350 // only for the first request). | 351 // only for the first request). |
| 351 // There should alos be one UNMOUNTING event, since the device should get | 352 // There should be only one UNMOUNTING event. The result of the second one |
| 352 // unmounted for the first request. | 353 // should not be reported as the mount point will go away after the first |
| 354 // request. |
| 353 // | 355 // |
| 354 // Note that in this test the format completion signal will not be simulated, | 356 // Note that in this test the format completion signal will not be simulated, |
| 355 // so the observer should not get FORMAT_COMPLETED signal. | 357 // so the observer should not get FORMAT_COMPLETED signal. |
| 356 { | 358 { |
| 357 InSequence s; | 359 InSequence s; |
| 358 | 360 |
| 359 EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_STARTED, | |
| 360 chromeos::FORMAT_ERROR_UNKNOWN, | |
| 361 "/device/source_path")) | |
| 362 .Times(1); | |
| 363 | |
| 364 EXPECT_CALL(observer_, | 361 EXPECT_CALL(observer_, |
| 365 OnMountEvent(DiskMountManager::UNMOUNTING, | 362 OnMountEvent(DiskMountManager::UNMOUNTING, |
| 366 chromeos::MOUNT_ERROR_NONE, | 363 chromeos::MOUNT_ERROR_NONE, |
| 367 Field(&DiskMountManager::MountPointInfo::mount_path, | 364 Field(&DiskMountManager::MountPointInfo::mount_path, |
| 368 "/device/mount_path"))) | 365 "/device/mount_path"))) |
| 369 .Times(1); | 366 .Times(1); |
| 370 | 367 |
| 371 EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_STARTED, | 368 EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_STARTED, |
| 369 chromeos::FORMAT_ERROR_UNKNOWN, |
| 370 "/device/source_path")) |
| 371 .Times(1); |
| 372 |
| 373 EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_STARTED, |
| 372 chromeos::FORMAT_ERROR_NONE, | 374 chromeos::FORMAT_ERROR_NONE, |
| 373 "/device/source_path")) | 375 "/device/source_path")) |
| 374 .Times(1); | 376 .Times(1); |
| 375 } | 377 } |
| 376 | 378 |
| 377 // Start the test. | 379 // Start the test. |
| 378 DiskMountManager::GetInstance()->FormatMountedDevice("/device/mount_path"); | 380 DiskMountManager::GetInstance()->FormatMountedDevice("/device/mount_path"); |
| 379 DiskMountManager::GetInstance()->FormatMountedDevice("/device/mount_path"); | 381 DiskMountManager::GetInstance()->FormatMountedDevice("/device/mount_path"); |
| 380 | 382 |
| 381 // Cros disks will respond asynchronoulsy, so let's drain the message loop. | 383 // Cros disks will respond asynchronoulsy, so let's drain the message loop. |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 // Wait for Unmount and FormatDevice calls to end. | 618 // Wait for Unmount and FormatDevice calls to end. |
| 617 message_loop_.RunUntilIdle(); | 619 message_loop_.RunUntilIdle(); |
| 618 | 620 |
| 619 // Simulate cros_disks reporting success. | 621 // Simulate cros_disks reporting success. |
| 620 mock_cros_disks_client_->SendMountEvent( | 622 mock_cros_disks_client_->SendMountEvent( |
| 621 chromeos::CROS_DISKS_FORMATTING_FINISHED, "/device/source_path"); | 623 chromeos::CROS_DISKS_FORMATTING_FINISHED, "/device/source_path"); |
| 622 } | 624 } |
| 623 | 625 |
| 624 } // namespace | 626 } // namespace |
| 625 | 627 |
| OLD | NEW |