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

Side by Side Diff: chrome/browser/chromeos/dbus/mock_cros_disks_client.cc

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

Powered by Google App Engine
This is Rietveld 408576698