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

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

Issue 372853003: Cut reference from MountedDiskMonitor to DiskMountManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix more test Created 6 years, 5 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/mounted_disk_monitor.h" 5 #include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/stl_util.h"
11 #include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h"
12 #include "chromeos/dbus/fake_power_manager_client.h" 10 #include "chromeos/dbus/fake_power_manager_client.h"
13 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
14 12
15 namespace file_manager { 13 namespace file_manager {
16 namespace { 14 namespace {
17 15
18 // Creates a fake disk with |device_path| and |fs_uuid|. 16 // Creates a fake disk with |device_path| and |fs_uuid|.
19 scoped_ptr<chromeos::disks::DiskMountManager::Disk> CreateDisk( 17 scoped_ptr<chromeos::disks::DiskMountManager::Disk> CreateDisk(
20 const std::string& device_path, 18 const std::string& device_path,
21 const std::string& fs_uuid) { 19 const std::string& fs_uuid) {
22 return make_scoped_ptr( 20 return make_scoped_ptr(
23 new chromeos::disks::DiskMountManager::Disk( 21 new chromeos::disks::DiskMountManager::Disk(
24 device_path, "", "", "", "", "", "", "", "", "", fs_uuid, "", 22 device_path, "", "", "", "", "", "", "", "", "", fs_uuid, "",
25 chromeos::DEVICE_TYPE_USB, 0, false, false, false, false, false)); 23 chromeos::DEVICE_TYPE_USB, 0, false, false, false, false, false));
26 } 24 }
27 25
28 } // namespace 26 } // namespace
29 27
30 class MountedDiskMonitorTest : public testing::Test { 28 class MountedDiskMonitorTest : public testing::Test {
31 protected: 29 protected:
32 MountedDiskMonitorTest() {
33 }
34
35 virtual ~MountedDiskMonitorTest() {
36 }
37
38 virtual void SetUp() OVERRIDE { 30 virtual void SetUp() OVERRIDE {
39 power_manager_client_.reset(new chromeos::FakePowerManagerClient); 31 power_manager_client_.reset(new chromeos::FakePowerManagerClient);
40 disk_mount_manager_.reset(new FakeDiskMountManager);
41 mounted_disk_monitor_.reset(new MountedDiskMonitor( 32 mounted_disk_monitor_.reset(new MountedDiskMonitor(
42 power_manager_client_.get(), 33 power_manager_client_.get()));
43 disk_mount_manager_.get()));
44 mounted_disk_monitor_->set_resuming_time_span_for_testing( 34 mounted_disk_monitor_->set_resuming_time_span_for_testing(
45 base::TimeDelta::FromSeconds(0)); 35 base::TimeDelta::FromSeconds(0));
46 } 36 }
47 37
48 base::MessageLoop message_loop_; 38 base::MessageLoop message_loop_;
49 scoped_ptr<chromeos::FakePowerManagerClient> power_manager_client_; 39 scoped_ptr<chromeos::FakePowerManagerClient> power_manager_client_;
50 scoped_ptr<FakeDiskMountManager> disk_mount_manager_;
51 scoped_ptr<MountedDiskMonitor> mounted_disk_monitor_; 40 scoped_ptr<MountedDiskMonitor> mounted_disk_monitor_;
52 }; 41 };
53 42
54 // Makes sure that just mounting and unmounting repeatedly doesn't affect to 43 // Makes sure that just mounting and unmounting repeatedly doesn't affect to
55 // "remounting" state. 44 // "remounting" state.
56 TEST_F(MountedDiskMonitorTest, WithoutSuspend) { 45 TEST_F(MountedDiskMonitorTest, WithoutSuspend) {
57 scoped_ptr<chromeos::disks::DiskMountManager::Disk> disk( 46 scoped_ptr<chromeos::disks::DiskMountManager::Disk> disk(
58 CreateDisk("removable_device1", "uuid1")); 47 CreateDisk("removable_device1", "uuid1"));
59 48
60 chromeos::disks::DiskMountManager::Disk* disk_ptr = disk.get();
61
62 const chromeos::disks::DiskMountManager::MountPointInfo kMountPoint( 49 const chromeos::disks::DiskMountManager::MountPointInfo kMountPoint(
63 "removable_device1", "/tmp/removable_device1", 50 "removable_device1", "/tmp/removable_device1",
64 chromeos::MOUNT_TYPE_DEVICE, chromeos::disks::MOUNT_CONDITION_NONE); 51 chromeos::MOUNT_TYPE_DEVICE, chromeos::disks::MOUNT_CONDITION_NONE);
65 52
66 ASSERT_TRUE(disk_mount_manager_->AddDiskForTest(disk.release()));
67
68 // First, the disk is not remounting. 53 // First, the disk is not remounting.
69 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk_ptr)); 54 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk));
70 55
71 // Simple mounting and unmounting doesn't affect remounting state. 56 // Simple mounting and unmounting doesn't affect remounting state.
72 mounted_disk_monitor_->OnMountEvent( 57 mounted_disk_monitor_->OnMountEvent(
73 chromeos::disks::DiskMountManager::MOUNTING, 58 chromeos::disks::DiskMountManager::MOUNTING,
74 chromeos::MOUNT_ERROR_NONE, 59 chromeos::MOUNT_ERROR_NONE,
75 kMountPoint); 60 kMountPoint,
76 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk_ptr)); 61 disk.get());
62 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk));
77 63
78 mounted_disk_monitor_->OnMountEvent( 64 mounted_disk_monitor_->OnMountEvent(
79 chromeos::disks::DiskMountManager::UNMOUNTING, 65 chromeos::disks::DiskMountManager::UNMOUNTING,
80 chromeos::MOUNT_ERROR_NONE, 66 chromeos::MOUNT_ERROR_NONE,
81 kMountPoint); 67 kMountPoint,
82 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk_ptr)); 68 disk.get());
69 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk));
83 70
84 // Mounting again also should not affect remounting state. 71 // Mounting again also should not affect remounting state.
85 mounted_disk_monitor_->OnMountEvent( 72 mounted_disk_monitor_->OnMountEvent(
86 chromeos::disks::DiskMountManager::MOUNTING, 73 chromeos::disks::DiskMountManager::MOUNTING,
87 chromeos::MOUNT_ERROR_NONE, 74 chromeos::MOUNT_ERROR_NONE,
88 kMountPoint); 75 kMountPoint,
89 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk_ptr)); 76 disk.get());
77 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk));
90 } 78 }
91 79
92 // Makes sure that the unmounting after system resuming triggers the 80 // Makes sure that the unmounting after system resuming triggers the
93 // "remounting" state, then after some period, the state is reset. 81 // "remounting" state, then after some period, the state is reset.
94 TEST_F(MountedDiskMonitorTest, SuspendAndResume) { 82 TEST_F(MountedDiskMonitorTest, SuspendAndResume) {
95 scoped_ptr<chromeos::disks::DiskMountManager::Disk> disk1( 83 scoped_ptr<chromeos::disks::DiskMountManager::Disk> disk1(
96 CreateDisk("removable_device1", "uuid1")); 84 CreateDisk("removable_device1", "uuid1"));
97 scoped_ptr<chromeos::disks::DiskMountManager::Disk> disk2( 85 scoped_ptr<chromeos::disks::DiskMountManager::Disk> disk2(
98 CreateDisk("removable_device2", "uuid2")); 86 CreateDisk("removable_device2", "uuid2"));
99 87
100 chromeos::disks::DiskMountManager::Disk* disk1_ptr = disk1.get();
101 chromeos::disks::DiskMountManager::Disk* disk2_ptr = disk2.get();
102
103 const chromeos::disks::DiskMountManager::MountPointInfo kMountPoint1( 88 const chromeos::disks::DiskMountManager::MountPointInfo kMountPoint1(
104 "removable_device1", "/tmp/removable_device1", 89 "removable_device1", "/tmp/removable_device1",
105 chromeos::MOUNT_TYPE_DEVICE, chromeos::disks::MOUNT_CONDITION_NONE); 90 chromeos::MOUNT_TYPE_DEVICE, chromeos::disks::MOUNT_CONDITION_NONE);
106 const chromeos::disks::DiskMountManager::MountPointInfo kMountPoint2( 91 const chromeos::disks::DiskMountManager::MountPointInfo kMountPoint2(
107 "removable_device2", "/tmp/removable_device2", 92 "removable_device2", "/tmp/removable_device2",
108 chromeos::MOUNT_TYPE_DEVICE, chromeos::disks::MOUNT_CONDITION_NONE); 93 chromeos::MOUNT_TYPE_DEVICE, chromeos::disks::MOUNT_CONDITION_NONE);
109 94
110 ASSERT_TRUE(disk_mount_manager_->AddDiskForTest(disk1.release()));
111 ASSERT_TRUE(disk_mount_manager_->AddDiskForTest(disk2.release()));
112
113 // Mount |disk1|. 95 // Mount |disk1|.
114 mounted_disk_monitor_->OnMountEvent( 96 mounted_disk_monitor_->OnMountEvent(
115 chromeos::disks::DiskMountManager::MOUNTING, 97 chromeos::disks::DiskMountManager::MOUNTING,
116 chromeos::MOUNT_ERROR_NONE, 98 chromeos::MOUNT_ERROR_NONE,
117 kMountPoint1); 99 kMountPoint1,
118 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk1_ptr)); 100 disk1.get());
101 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk1));
119 102
120 // Pseudo system suspend and resume. 103 // Pseudo system suspend and resume.
121 mounted_disk_monitor_->SuspendImminent(); 104 mounted_disk_monitor_->SuspendImminent();
122 mounted_disk_monitor_->SuspendDone(base::TimeDelta::FromSeconds(0)); 105 mounted_disk_monitor_->SuspendDone(base::TimeDelta::FromSeconds(0));
123 106
124 // On system resume, we expect unmount and then mount immediately. 107 // On system resume, we expect unmount and then mount immediately.
125 // During the phase, we expect the disk is remounting. 108 // During the phase, we expect the disk is remounting.
126 mounted_disk_monitor_->OnMountEvent( 109 mounted_disk_monitor_->OnMountEvent(
127 chromeos::disks::DiskMountManager::UNMOUNTING, 110 chromeos::disks::DiskMountManager::UNMOUNTING,
128 chromeos::MOUNT_ERROR_NONE, 111 chromeos::MOUNT_ERROR_NONE,
129 kMountPoint1); 112 kMountPoint1,
130 EXPECT_TRUE(mounted_disk_monitor_->DiskIsRemounting(*disk1_ptr)); 113 disk1.get());
114 EXPECT_TRUE(mounted_disk_monitor_->DiskIsRemounting(*disk1));
131 115
132 mounted_disk_monitor_->OnMountEvent( 116 mounted_disk_monitor_->OnMountEvent(
133 chromeos::disks::DiskMountManager::MOUNTING, 117 chromeos::disks::DiskMountManager::MOUNTING,
134 chromeos::MOUNT_ERROR_NONE, 118 chromeos::MOUNT_ERROR_NONE,
135 kMountPoint1); 119 kMountPoint1,
136 EXPECT_TRUE(mounted_disk_monitor_->DiskIsRemounting(*disk1_ptr)); 120 disk1.get());
121 EXPECT_TRUE(mounted_disk_monitor_->DiskIsRemounting(*disk1));
137 122
138 // New disk should not be "remounting." 123 // New disk should not be "remounting."
139 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk2_ptr)); 124 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk2));
140 mounted_disk_monitor_->OnMountEvent( 125 mounted_disk_monitor_->OnMountEvent(
141 chromeos::disks::DiskMountManager::MOUNTING, 126 chromeos::disks::DiskMountManager::MOUNTING,
142 chromeos::MOUNT_ERROR_NONE, 127 chromeos::MOUNT_ERROR_NONE,
143 kMountPoint2); 128 kMountPoint2,
144 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk2_ptr)); 129 disk2.get());
130 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk2));
145 131
146 // After certain period, remounting state should be cleared. 132 // After certain period, remounting state should be cleared.
147 base::RunLoop().RunUntilIdle(); // Emulate time passage. 133 base::RunLoop().RunUntilIdle(); // Emulate time passage.
148 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk1_ptr)); 134 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk1));
149 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk2_ptr)); 135 EXPECT_FALSE(mounted_disk_monitor_->DiskIsRemounting(*disk2));
150 } 136 }
151 137
152 } // namespace file_manager 138 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/mounted_disk_monitor.cc ('k') | chrome/browser/chromeos/file_manager/volume_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698