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

Side by Side Diff: chrome/browser/chromeos/disks/mock_disk_mount_manager.cc

Issue 8499007: Add CrosDisksClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix to please clang Created 9 years, 1 month 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/disks/mock_disk_mount_manager.h"
6
7 #include "base/message_loop.h"
8 #include "base/string_util.h"
9 #include "content/public/browser/browser_thread.h"
10
11 using content::BrowserThread;
12 using testing::_;
13 using testing::AnyNumber;
14 using testing::Invoke;
15 using testing::ReturnRef;
16
17 namespace chromeos {
18
19 namespace {
20
21 const char* kTestSystemPath = "/this/system/path";
22 const char* kTestSystemPathPrefix = "/this/system";
23 const char* kTestDevicePath = "/this/device/path";
24 const char* kTestMountPath = "/media/foofoo";
25 const char* kTestFilePath = "/this/file/path";
26 const char* kTestDeviceLabel = "A label";
27 const char* kTestDriveLabel = "Another label";
28 const char* kTestParentPath = "/this/is/my/parent";
29
30 } // namespace
31
32 void MockDiskMountManager::AddObserverInternal(
33 DiskMountManager::Observer* observer) {
34 observers_.AddObserver(observer);
35 }
36
37 void MockDiskMountManager::RemoveObserverInternal(
38 DiskMountManager::Observer* observer) {
39 observers_.RemoveObserver(observer);
40 }
41
42 MockDiskMountManager::MockDiskMountManager() {
43 ON_CALL(*this, AddObserver(_))
44 .WillByDefault(Invoke(this, &MockDiskMountManager::AddObserverInternal));
45 ON_CALL(*this, RemoveObserver(_))
46 .WillByDefault(Invoke(this,
47 &MockDiskMountManager::RemoveObserverInternal));
48 ON_CALL(*this, disks())
49 .WillByDefault(Invoke(this, &MockDiskMountManager::disksInternal));
50 }
51
52 MockDiskMountManager::~MockDiskMountManager() {
53 }
54
55 void MockDiskMountManager::NotifyDeviceInsertEvents() {
56 scoped_ptr<DiskMountManager::Disk> disk1(new DiskMountManager::Disk(
57 std::string(kTestDevicePath),
58 std::string(),
59 std::string(kTestSystemPath),
60 std::string(kTestFilePath),
61 std::string(),
62 std::string(kTestDriveLabel),
63 std::string(kTestParentPath),
64 std::string(kTestSystemPathPrefix),
65 FLASH,
66 4294967295U,
67 false, // is_parent
68 false, // is_read_only
69 true, // has_media
70 false, // on_boot_device
71 false)); // is_hidden
72
73 disks_.clear();
74 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>(
75 std::string(kTestDevicePath), disk1.get()));
76
77 // Device Added
78 chromeos::DiskMountManagerEventType event;
79 event = chromeos::MOUNT_DEVICE_ADDED;
80 NotifyDeviceChanged(event, kTestSystemPath);
81
82 // Disk Added
83 event = chromeos::MOUNT_DISK_ADDED;
84 NotifyDiskChanged(event, disk1.get());
85
86 // Disk Changed
87 scoped_ptr<DiskMountManager::Disk> disk2(new DiskMountManager::Disk(
88 std::string(kTestDevicePath),
89 std::string(kTestMountPath),
90 std::string(kTestSystemPath),
91 std::string(kTestFilePath),
92 std::string(kTestDeviceLabel),
93 std::string(kTestDriveLabel),
94 std::string(kTestParentPath),
95 std::string(kTestSystemPathPrefix),
96 FLASH,
97 1073741824,
98 false, // is_parent
99 false, // is_read_only
100 true, // has_media
101 false, // on_boot_device
102 false)); // is_hidden
103 disks_.clear();
104 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>(
105 std::string(kTestDevicePath), disk2.get()));
106 event = chromeos::MOUNT_DISK_CHANGED;
107 NotifyDiskChanged(event, disk2.get());
108 }
109
110 void MockDiskMountManager::NotifyDeviceRemoveEvents() {
111 scoped_ptr<DiskMountManager::Disk> disk(new DiskMountManager::Disk(
112 std::string(kTestDevicePath),
113 std::string(kTestMountPath),
114 std::string(kTestSystemPath),
115 std::string(kTestFilePath),
116 std::string(kTestDeviceLabel),
117 std::string(kTestDriveLabel),
118 std::string(kTestParentPath),
119 std::string(kTestSystemPathPrefix),
120 FLASH,
121 1073741824,
122 false, // is_parent
123 false, // is_read_only
124 true, // has_media
125 false, // on_boot_device
126 false)); // is_hidden
127 disks_.clear();
128 disks_.insert(std::pair<std::string, DiskMountManager::Disk*>(
129 std::string(kTestDevicePath), disk.get()));
130 NotifyDiskChanged(chromeos::MOUNT_DISK_REMOVED, disk.get());
131 }
132
133 void MockDiskMountManager::SetupDefaultReplies() {
134 EXPECT_CALL(*this, AddObserver(_))
135 .Times(AnyNumber());
136 EXPECT_CALL(*this, RemoveObserver(_))
137 .Times(AnyNumber());
138 EXPECT_CALL(*this, disks())
139 .WillRepeatedly(ReturnRef(disks_));
140 EXPECT_CALL(*this, RequestMountInfoRefresh())
141 .Times(AnyNumber());
142 EXPECT_CALL(*this, MountPath(_, _))
143 .Times(AnyNumber());
144 EXPECT_CALL(*this, UnmountPath(_))
145 .Times(AnyNumber());
146 EXPECT_CALL(*this, FormatUnmountedDevice(_))
147 .Times(AnyNumber());
148 EXPECT_CALL(*this, FormatMountedDevice(_))
149 .Times(AnyNumber());
150 EXPECT_CALL(*this, UnmountDeviceRecursive(_, _, _))
151 .Times(AnyNumber());
152 }
153
154 void MockDiskMountManager::NotifyDiskChanged(DiskMountManagerEventType event,
155 const DiskMountManager::Disk* disk)
156 {
157 // Make sure we run on UI thread.
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
159
160 FOR_EACH_OBSERVER(Observer, observers_, DiskChanged(event, disk));
161 }
162
163 void MockDiskMountManager::NotifyDeviceChanged(DiskMountManagerEventType event,
164 const std::string& path) {
165 // Make sure we run on UI thread.
166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
167
168 FOR_EACH_OBSERVER(Observer, observers_, DeviceChanged(event, path));
169 }
170
171 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698