Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: chrome/browser/chromeos/file_manager/volume_manager_unittest.cc

Issue 490643005: Files.app: Start to use DeviceEventRouter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 20 matching lines...) Expand all
31 struct Event { 31 struct Event {
32 enum EventType { 32 enum EventType {
33 DISK_ADDED, 33 DISK_ADDED,
34 DISK_REMOVED, 34 DISK_REMOVED,
35 DEVICE_ADDED, 35 DEVICE_ADDED,
36 DEVICE_REMOVED, 36 DEVICE_REMOVED,
37 VOLUME_MOUNTED, 37 VOLUME_MOUNTED,
38 VOLUME_UNMOUNTED, 38 VOLUME_UNMOUNTED,
39 FORMAT_STARTED, 39 FORMAT_STARTED,
40 FORMAT_COMPLETED, 40 FORMAT_COMPLETED,
41 HARD_UNPLUGGED,
42 } type; 41 } type;
43 42
44 // Available on DEVICE_ADDED, DEVICE_REMOVED, VOLUME_MOUNTED, 43 // Available on DEVICE_ADDED, DEVICE_REMOVED, VOLUME_MOUNTED,
45 // VOLUME_UNMOUNTED, FORMAT_STARTED and FORMAT_COMPLETED. 44 // VOLUME_UNMOUNTED, FORMAT_STARTED and FORMAT_COMPLETED.
46 std::string device_path; 45 std::string device_path;
47 46
48 // Available on DISK_ADDED. 47 // Available on DISK_ADDED.
49 bool mounting; 48 bool mounting;
50 49
51 // Available on VOLUME_MOUNTED and VOLUME_UNMOUNTED. 50 // Available on VOLUME_MOUNTED and VOLUME_UNMOUNTED.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 107
109 virtual void OnVolumeUnmounted(chromeos::MountError error_code, 108 virtual void OnVolumeUnmounted(chromeos::MountError error_code,
110 const VolumeInfo& volume_info) OVERRIDE { 109 const VolumeInfo& volume_info) OVERRIDE {
111 Event event; 110 Event event;
112 event.type = Event::VOLUME_UNMOUNTED; 111 event.type = Event::VOLUME_UNMOUNTED;
113 event.device_path = volume_info.source_path.AsUTF8Unsafe(); 112 event.device_path = volume_info.source_path.AsUTF8Unsafe();
114 event.mount_error = error_code; 113 event.mount_error = error_code;
115 events_.push_back(event); 114 events_.push_back(event);
116 } 115 }
117 116
118 virtual void OnHardUnplugged(const std::string& device_path) OVERRIDE {
119 Event event;
120 event.type = Event::HARD_UNPLUGGED;
121 event.device_path = device_path;
122 events_.push_back(event);
123 }
124
125 virtual void OnFormatStarted( 117 virtual void OnFormatStarted(
126 const std::string& device_path, bool success) OVERRIDE { 118 const std::string& device_path, bool success) OVERRIDE {
127 Event event; 119 Event event;
128 event.type = Event::FORMAT_STARTED; 120 event.type = Event::FORMAT_STARTED;
129 event.device_path = device_path; 121 event.device_path = device_path;
130 event.success = success; 122 event.success = success;
131 events_.push_back(event); 123 events_.push_back(event);
132 } 124 }
133 125
134 virtual void OnFormatCompleted( 126 virtual void OnFormatCompleted(
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 LoggingObserver observer; 374 LoggingObserver observer;
383 volume_manager()->AddObserver(&observer); 375 volume_manager()->AddObserver(&observer);
384 376
385 const chromeos::disks::DiskMountManager::Disk kMountedDisk( 377 const chromeos::disks::DiskMountManager::Disk kMountedDisk(
386 "device1", "mount_path", "", "", "", "", "", "", "", "", "", "", 378 "device1", "mount_path", "", "", "", "", "", "", "", "", "", "",
387 chromeos::DEVICE_TYPE_UNKNOWN, 0, false, false, false, false, false, 379 chromeos::DEVICE_TYPE_UNKNOWN, 0, false, false, false, false, false,
388 false); 380 false);
389 volume_manager()->OnDiskEvent( 381 volume_manager()->OnDiskEvent(
390 chromeos::disks::DiskMountManager::DISK_REMOVED, &kMountedDisk); 382 chromeos::disks::DiskMountManager::DISK_REMOVED, &kMountedDisk);
391 383
392 ASSERT_EQ(2U, observer.events().size()); 384 ASSERT_EQ(1U, observer.events().size());
393 const LoggingObserver::Event& event = observer.events()[0]; 385 const LoggingObserver::Event& event = observer.events()[0];
394 EXPECT_EQ(LoggingObserver::Event::DISK_REMOVED, event.type); 386 EXPECT_EQ(LoggingObserver::Event::DISK_REMOVED, event.type);
395 EXPECT_EQ("device1", event.device_path); 387 EXPECT_EQ("device1", event.device_path);
396 388
397 // Since the Disk has non-empty mount_path, it's regarded as hard unplugging.
398 EXPECT_EQ(LoggingObserver::Event::HARD_UNPLUGGED,
399 observer.events()[1].type);
400
401 ASSERT_EQ(1U, disk_mount_manager_->unmount_requests().size()); 389 ASSERT_EQ(1U, disk_mount_manager_->unmount_requests().size());
402 const FakeDiskMountManager::UnmountRequest& unmount_request = 390 const FakeDiskMountManager::UnmountRequest& unmount_request =
403 disk_mount_manager_->unmount_requests()[0]; 391 disk_mount_manager_->unmount_requests()[0];
404 EXPECT_EQ("mount_path", unmount_request.mount_path); 392 EXPECT_EQ("mount_path", unmount_request.mount_path);
405 EXPECT_EQ(chromeos::UNMOUNT_OPTIONS_LAZY, unmount_request.options); 393 EXPECT_EQ(chromeos::UNMOUNT_OPTIONS_LAZY, unmount_request.options);
406 394
407 volume_manager()->RemoveObserver(&observer); 395 volume_manager()->RemoveObserver(&observer);
408 } 396 }
409 397
410 TEST_F(VolumeManagerTest, OnDiskEvent_RemovedNotMounted) { 398 TEST_F(VolumeManagerTest, OnDiskEvent_RemovedNotMounted) {
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 chromeos::MOUNT_ERROR_NONE, 819 chromeos::MOUNT_ERROR_NONE,
832 chromeos::disks::DiskMountManager::MountPointInfo( 820 chromeos::disks::DiskMountManager::MountPointInfo(
833 "/other/profile/drive/folder/3.zip", 821 "/other/profile/drive/folder/3.zip",
834 "/archive/3", 822 "/archive/3",
835 chromeos::MOUNT_TYPE_ARCHIVE, 823 chromeos::MOUNT_TYPE_ARCHIVE,
836 chromeos::disks::MOUNT_CONDITION_NONE)); 824 chromeos::disks::MOUNT_CONDITION_NONE));
837 EXPECT_FALSE(volume_manager()->FindVolumeInfoById("archive:3", &volume_info)); 825 EXPECT_FALSE(volume_manager()->FindVolumeInfoById("archive:3", &volume_info));
838 EXPECT_EQ(3u, observer.events().size()); 826 EXPECT_EQ(3u, observer.events().size());
839 } 827 }
840 828
841 TEST_F(VolumeManagerTest, HardUnplugged) {
842 volume_manager()->Initialize();
843 LoggingObserver observer;
844 volume_manager()->AddObserver(&observer);
845
846 // Disk that has a mount path is removed.
847 chromeos::disks::DiskMountManager::Disk mounted_disk(
848 "device1",
849 "/mount/path",
850 "",
851 "",
852 "",
853 "",
854 "",
855 "",
856 "",
857 "",
858 "uuid1",
859 "device1",
860 chromeos::DEVICE_TYPE_UNKNOWN,
861 0,
862 false,
863 false,
864 false,
865 false,
866 false,
867 false);
868
869 chromeos::disks::DiskMountManager::Disk unmounted_disk(
870 "device2",
871 "",
872 "",
873 "",
874 "",
875 "",
876 "",
877 "",
878 "",
879 "",
880 "uuid2",
881 "device2",
882 chromeos::DEVICE_TYPE_UNKNOWN,
883 0,
884 false,
885 false,
886 false,
887 false,
888 false,
889 false);
890
891 // Do not publish the hard_unplugged event for a disk that is already
892 // unmounted.
893 disk_mount_manager_->InvokeDiskEventForTest(
894 chromeos::disks::DiskMountManager::DISK_REMOVED, &unmounted_disk);
895 // Publish the hard_unplugged event for a disk that is currently mounted.
896 disk_mount_manager_->InvokeDiskEventForTest(
897 chromeos::disks::DiskMountManager::DISK_REMOVED, &mounted_disk);
898 // Do not publish the hard_unplugged event twice for the same disk.
899 disk_mount_manager_->InvokeDiskEventForTest(
900 chromeos::disks::DiskMountManager::DISK_REMOVED, &mounted_disk);
901
902 EXPECT_EQ(4u, observer.events().size());
903 EXPECT_EQ(LoggingObserver::Event::DISK_REMOVED, observer.events()[0].type);
904 EXPECT_EQ(LoggingObserver::Event::DISK_REMOVED, observer.events()[1].type);
905 EXPECT_EQ(LoggingObserver::Event::HARD_UNPLUGGED, observer.events()[2].type);
906 EXPECT_EQ(LoggingObserver::Event::DISK_REMOVED, observer.events()[3].type);
907 }
908
909 TEST_F(VolumeManagerTest, MTPPlugAndUnplug) { 829 TEST_F(VolumeManagerTest, MTPPlugAndUnplug) {
910 LoggingObserver observer; 830 LoggingObserver observer;
911 volume_manager()->AddObserver(&observer); 831 volume_manager()->AddObserver(&observer);
912 832
913 storage_monitor::StorageInfo info( 833 storage_monitor::StorageInfo info(
914 storage_monitor::StorageInfo::MakeDeviceId( 834 storage_monitor::StorageInfo::MakeDeviceId(
915 storage_monitor::StorageInfo::MTP_OR_PTP, "dummy-device-id"), 835 storage_monitor::StorageInfo::MTP_OR_PTP, "dummy-device-id"),
916 FILE_PATH_LITERAL("/dummy/device/location"), 836 FILE_PATH_LITERAL("/dummy/device/location"),
917 base::UTF8ToUTF16("label"), 837 base::UTF8ToUTF16("label"),
918 base::UTF8ToUTF16("vendor"), 838 base::UTF8ToUTF16("vendor"),
(...skipping 25 matching lines...) Expand all
944 // Detach 864 // Detach
945 volume_manager()->OnRemovableStorageDetached(info); 865 volume_manager()->OnRemovableStorageDetached(info);
946 ASSERT_EQ(2u, observer.events().size()); 866 ASSERT_EQ(2u, observer.events().size());
947 EXPECT_EQ(LoggingObserver::Event::VOLUME_UNMOUNTED, 867 EXPECT_EQ(LoggingObserver::Event::VOLUME_UNMOUNTED,
948 observer.events()[1].type); 868 observer.events()[1].type);
949 869
950 EXPECT_FALSE(volume_manager()->FindVolumeInfoById("mtp:model", &volume_info)); 870 EXPECT_FALSE(volume_manager()->FindVolumeInfoById("mtp:model", &volume_info));
951 } 871 }
952 872
953 } // namespace file_manager 873 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/volume_manager_observer.h ('k') | chrome/common/extensions/api/file_browser_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698