| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/file_manager/volume_manager.h" | 5 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 TEST_F(VolumeManagerTest, OnDiskEvent_Removed) { | 378 TEST_F(VolumeManagerTest, OnDiskEvent_Removed) { |
| 379 LoggingObserver observer; | 379 LoggingObserver observer; |
| 380 volume_manager()->AddObserver(&observer); | 380 volume_manager()->AddObserver(&observer); |
| 381 | 381 |
| 382 const chromeos::disks::DiskMountManager::Disk kMountedDisk( | 382 const chromeos::disks::DiskMountManager::Disk kMountedDisk( |
| 383 "device1", "mount_path", "", "", "", "", "", "", "", "", "", "", | 383 "device1", "mount_path", "", "", "", "", "", "", "", "", "", "", |
| 384 chromeos::DEVICE_TYPE_UNKNOWN, 0, false, false, false, false, false); | 384 chromeos::DEVICE_TYPE_UNKNOWN, 0, false, false, false, false, false); |
| 385 volume_manager()->OnDiskEvent( | 385 volume_manager()->OnDiskEvent( |
| 386 chromeos::disks::DiskMountManager::DISK_REMOVED, &kMountedDisk); | 386 chromeos::disks::DiskMountManager::DISK_REMOVED, &kMountedDisk); |
| 387 | 387 |
| 388 ASSERT_EQ(1U, observer.events().size()); | 388 ASSERT_EQ(2U, observer.events().size()); |
| 389 const LoggingObserver::Event& event = observer.events()[0]; | 389 const LoggingObserver::Event& event = observer.events()[0]; |
| 390 EXPECT_EQ(LoggingObserver::Event::DISK_REMOVED, event.type); | 390 EXPECT_EQ(LoggingObserver::Event::DISK_REMOVED, event.type); |
| 391 EXPECT_EQ("device1", event.device_path); | 391 EXPECT_EQ("device1", event.device_path); |
| 392 | 392 |
| 393 // Since the Disk has non-empty mount_path, it's regarded as hard unplugging. |
| 394 EXPECT_EQ(LoggingObserver::Event::HARD_UNPLUGGED, |
| 395 observer.events()[1].type); |
| 396 |
| 393 ASSERT_EQ(1U, disk_mount_manager_->unmount_requests().size()); | 397 ASSERT_EQ(1U, disk_mount_manager_->unmount_requests().size()); |
| 394 const FakeDiskMountManager::UnmountRequest& unmount_request = | 398 const FakeDiskMountManager::UnmountRequest& unmount_request = |
| 395 disk_mount_manager_->unmount_requests()[0]; | 399 disk_mount_manager_->unmount_requests()[0]; |
| 396 EXPECT_EQ("mount_path", unmount_request.mount_path); | 400 EXPECT_EQ("mount_path", unmount_request.mount_path); |
| 397 EXPECT_EQ(chromeos::UNMOUNT_OPTIONS_LAZY, unmount_request.options); | 401 EXPECT_EQ(chromeos::UNMOUNT_OPTIONS_LAZY, unmount_request.options); |
| 398 | 402 |
| 399 volume_manager()->RemoveObserver(&observer); | 403 volume_manager()->RemoveObserver(&observer); |
| 400 } | 404 } |
| 401 | 405 |
| 402 TEST_F(VolumeManagerTest, OnDiskEvent_RemovedNotMounted) { | 406 TEST_F(VolumeManagerTest, OnDiskEvent_RemovedNotMounted) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 TEST_F(VolumeManagerTest, OnMountEvent_Remounting) { | 521 TEST_F(VolumeManagerTest, OnMountEvent_Remounting) { |
| 518 scoped_ptr<chromeos::disks::DiskMountManager::Disk> disk( | 522 scoped_ptr<chromeos::disks::DiskMountManager::Disk> disk( |
| 519 new chromeos::disks::DiskMountManager::Disk( | 523 new chromeos::disks::DiskMountManager::Disk( |
| 520 "device1", "", "", "", "", "", "", "", "", "", "uuid1", "", | 524 "device1", "", "", "", "", "", "", "", "", "", "uuid1", "", |
| 521 chromeos::DEVICE_TYPE_UNKNOWN, 0, | 525 chromeos::DEVICE_TYPE_UNKNOWN, 0, |
| 522 false, false, false, false, false)); | 526 false, false, false, false, false)); |
| 523 disk_mount_manager_->AddDiskForTest(disk.release()); | 527 disk_mount_manager_->AddDiskForTest(disk.release()); |
| 524 disk_mount_manager_->MountPath( | 528 disk_mount_manager_->MountPath( |
| 525 "device1", "", "", chromeos::MOUNT_TYPE_DEVICE); | 529 "device1", "", "", chromeos::MOUNT_TYPE_DEVICE); |
| 526 | 530 |
| 531 const chromeos::disks::DiskMountManager::MountPointInfo kMountPoint( |
| 532 "device1", |
| 533 "mount1", |
| 534 chromeos::MOUNT_TYPE_DEVICE, |
| 535 chromeos::disks::MOUNT_CONDITION_NONE); |
| 536 |
| 537 volume_manager()->OnMountEvent( |
| 538 chromeos::disks::DiskMountManager::MOUNTING, |
| 539 chromeos::MOUNT_ERROR_NONE, |
| 540 kMountPoint); |
| 541 |
| 542 LoggingObserver observer; |
| 543 |
| 527 // Emulate system suspend and then resume. | 544 // Emulate system suspend and then resume. |
| 528 { | 545 { |
| 529 power_manager_client_->SendSuspendImminent(); | 546 power_manager_client_->SendSuspendImminent(); |
| 530 power_manager_client_->SendSuspendDone(); | 547 power_manager_client_->SendSuspendDone(); |
| 531 | 548 |
| 532 // After resume, the device is unmounted and then mounted. | 549 // After resume, the device is unmounted and then mounted. |
| 533 disk_mount_manager_->UnmountPath( | 550 volume_manager()->OnMountEvent( |
| 534 "device1", chromeos::UNMOUNT_OPTIONS_NONE, | 551 chromeos::disks::DiskMountManager::UNMOUNTING, |
| 535 chromeos::disks::DiskMountManager::UnmountPathCallback()); | 552 chromeos::MOUNT_ERROR_NONE, |
| 536 disk_mount_manager_->MountPath( | 553 kMountPoint); |
| 537 "device1", "", "", chromeos::MOUNT_TYPE_DEVICE); | 554 |
| 555 // Observe what happened for the mount event. |
| 556 volume_manager()->AddObserver(&observer); |
| 557 |
| 558 volume_manager()->OnMountEvent( |
| 559 chromeos::disks::DiskMountManager::MOUNTING, |
| 560 chromeos::MOUNT_ERROR_NONE, |
| 561 kMountPoint); |
| 538 } | 562 } |
| 539 | 563 |
| 540 LoggingObserver observer; | |
| 541 volume_manager()->AddObserver(&observer); | |
| 542 | |
| 543 const chromeos::disks::DiskMountManager::MountPointInfo kMountPoint( | |
| 544 "device1", | |
| 545 "mount1", | |
| 546 chromeos::MOUNT_TYPE_DEVICE, | |
| 547 chromeos::disks::MOUNT_CONDITION_NONE); | |
| 548 | |
| 549 volume_manager()->OnMountEvent(chromeos::disks::DiskMountManager::MOUNTING, | |
| 550 chromeos::MOUNT_ERROR_NONE, | |
| 551 kMountPoint); | |
| 552 | |
| 553 ASSERT_EQ(1U, observer.events().size()); | 564 ASSERT_EQ(1U, observer.events().size()); |
| 554 const LoggingObserver::Event& event = observer.events()[0]; | 565 const LoggingObserver::Event& event = observer.events()[0]; |
| 555 EXPECT_EQ(LoggingObserver::Event::VOLUME_MOUNTED, event.type); | 566 EXPECT_EQ(LoggingObserver::Event::VOLUME_MOUNTED, event.type); |
| 556 EXPECT_EQ("device1", event.device_path); | 567 EXPECT_EQ("device1", event.device_path); |
| 557 EXPECT_EQ(chromeos::MOUNT_ERROR_NONE, event.mount_error); | 568 EXPECT_EQ(chromeos::MOUNT_ERROR_NONE, event.mount_error); |
| 558 EXPECT_TRUE(event.is_remounting); | 569 EXPECT_TRUE(event.is_remounting); |
| 559 | 570 |
| 560 volume_manager()->RemoveObserver(&observer); | 571 volume_manager()->RemoveObserver(&observer); |
| 561 } | 572 } |
| 562 | 573 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 // Detach | 935 // Detach |
| 925 volume_manager()->OnRemovableStorageDetached(info); | 936 volume_manager()->OnRemovableStorageDetached(info); |
| 926 ASSERT_EQ(2u, observer.events().size()); | 937 ASSERT_EQ(2u, observer.events().size()); |
| 927 EXPECT_EQ(LoggingObserver::Event::VOLUME_UNMOUNTED, | 938 EXPECT_EQ(LoggingObserver::Event::VOLUME_UNMOUNTED, |
| 928 observer.events()[1].type); | 939 observer.events()[1].type); |
| 929 | 940 |
| 930 EXPECT_FALSE(volume_manager()->FindVolumeInfoById("mtp:model", &volume_info)); | 941 EXPECT_FALSE(volume_manager()->FindVolumeInfoById("mtp:model", &volume_info)); |
| 931 } | 942 } |
| 932 | 943 |
| 933 } // namespace file_manager | 944 } // namespace file_manager |
| OLD | NEW |