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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/disks/mock_disk_mount_manager.cc
diff --git a/chrome/browser/chromeos/disks/mock_disk_mount_manager.cc b/chrome/browser/chromeos/disks/mock_disk_mount_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1a7a99f8223adba75ecdde063dabd01b3a5d9df8
--- /dev/null
+++ b/chrome/browser/chromeos/disks/mock_disk_mount_manager.cc
@@ -0,0 +1,171 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/disks/mock_disk_mount_manager.h"
+
+#include "base/message_loop.h"
+#include "base/string_util.h"
+#include "content/public/browser/browser_thread.h"
+
+using content::BrowserThread;
+using testing::_;
+using testing::AnyNumber;
+using testing::Invoke;
+using testing::ReturnRef;
+
+namespace chromeos {
+
+namespace {
+
+const char* kTestSystemPath = "/this/system/path";
+const char* kTestSystemPathPrefix = "/this/system";
+const char* kTestDevicePath = "/this/device/path";
+const char* kTestMountPath = "/media/foofoo";
+const char* kTestFilePath = "/this/file/path";
+const char* kTestDeviceLabel = "A label";
+const char* kTestDriveLabel = "Another label";
+const char* kTestParentPath = "/this/is/my/parent";
+
+} // namespace
+
+void MockDiskMountManager::AddObserverInternal(
+ DiskMountManager::Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void MockDiskMountManager::RemoveObserverInternal(
+ DiskMountManager::Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+MockDiskMountManager::MockDiskMountManager() {
+ ON_CALL(*this, AddObserver(_))
+ .WillByDefault(Invoke(this, &MockDiskMountManager::AddObserverInternal));
+ ON_CALL(*this, RemoveObserver(_))
+ .WillByDefault(Invoke(this,
+ &MockDiskMountManager::RemoveObserverInternal));
+ ON_CALL(*this, disks())
+ .WillByDefault(Invoke(this, &MockDiskMountManager::disksInternal));
+}
+
+MockDiskMountManager::~MockDiskMountManager() {
+}
+
+void MockDiskMountManager::NotifyDeviceInsertEvents() {
+ scoped_ptr<DiskMountManager::Disk> disk1(new DiskMountManager::Disk(
+ std::string(kTestDevicePath),
+ std::string(),
+ std::string(kTestSystemPath),
+ std::string(kTestFilePath),
+ std::string(),
+ std::string(kTestDriveLabel),
+ std::string(kTestParentPath),
+ std::string(kTestSystemPathPrefix),
+ FLASH,
+ 4294967295U,
+ false, // is_parent
+ false, // is_read_only
+ true, // has_media
+ false, // on_boot_device
+ false)); // is_hidden
+
+ disks_.clear();
+ disks_.insert(std::pair<std::string, DiskMountManager::Disk*>(
+ std::string(kTestDevicePath), disk1.get()));
+
+ // Device Added
+ chromeos::DiskMountManagerEventType event;
+ event = chromeos::MOUNT_DEVICE_ADDED;
+ NotifyDeviceChanged(event, kTestSystemPath);
+
+ // Disk Added
+ event = chromeos::MOUNT_DISK_ADDED;
+ NotifyDiskChanged(event, disk1.get());
+
+ // Disk Changed
+ scoped_ptr<DiskMountManager::Disk> disk2(new DiskMountManager::Disk(
+ std::string(kTestDevicePath),
+ std::string(kTestMountPath),
+ std::string(kTestSystemPath),
+ std::string(kTestFilePath),
+ std::string(kTestDeviceLabel),
+ std::string(kTestDriveLabel),
+ std::string(kTestParentPath),
+ std::string(kTestSystemPathPrefix),
+ FLASH,
+ 1073741824,
+ false, // is_parent
+ false, // is_read_only
+ true, // has_media
+ false, // on_boot_device
+ false)); // is_hidden
+ disks_.clear();
+ disks_.insert(std::pair<std::string, DiskMountManager::Disk*>(
+ std::string(kTestDevicePath), disk2.get()));
+ event = chromeos::MOUNT_DISK_CHANGED;
+ NotifyDiskChanged(event, disk2.get());
+}
+
+void MockDiskMountManager::NotifyDeviceRemoveEvents() {
+ scoped_ptr<DiskMountManager::Disk> disk(new DiskMountManager::Disk(
+ std::string(kTestDevicePath),
+ std::string(kTestMountPath),
+ std::string(kTestSystemPath),
+ std::string(kTestFilePath),
+ std::string(kTestDeviceLabel),
+ std::string(kTestDriveLabel),
+ std::string(kTestParentPath),
+ std::string(kTestSystemPathPrefix),
+ FLASH,
+ 1073741824,
+ false, // is_parent
+ false, // is_read_only
+ true, // has_media
+ false, // on_boot_device
+ false)); // is_hidden
+ disks_.clear();
+ disks_.insert(std::pair<std::string, DiskMountManager::Disk*>(
+ std::string(kTestDevicePath), disk.get()));
+ NotifyDiskChanged(chromeos::MOUNT_DISK_REMOVED, disk.get());
+}
+
+void MockDiskMountManager::SetupDefaultReplies() {
+ EXPECT_CALL(*this, AddObserver(_))
+ .Times(AnyNumber());
+ EXPECT_CALL(*this, RemoveObserver(_))
+ .Times(AnyNumber());
+ EXPECT_CALL(*this, disks())
+ .WillRepeatedly(ReturnRef(disks_));
+ EXPECT_CALL(*this, RequestMountInfoRefresh())
+ .Times(AnyNumber());
+ EXPECT_CALL(*this, MountPath(_, _))
+ .Times(AnyNumber());
+ EXPECT_CALL(*this, UnmountPath(_))
+ .Times(AnyNumber());
+ EXPECT_CALL(*this, FormatUnmountedDevice(_))
+ .Times(AnyNumber());
+ EXPECT_CALL(*this, FormatMountedDevice(_))
+ .Times(AnyNumber());
+ EXPECT_CALL(*this, UnmountDeviceRecursive(_, _, _))
+ .Times(AnyNumber());
+}
+
+void MockDiskMountManager::NotifyDiskChanged(DiskMountManagerEventType event,
+ const DiskMountManager::Disk* disk)
+{
+ // Make sure we run on UI thread.
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ FOR_EACH_OBSERVER(Observer, observers_, DiskChanged(event, disk));
+}
+
+void MockDiskMountManager::NotifyDeviceChanged(DiskMountManagerEventType event,
+ const std::string& path) {
+ // Make sure we run on UI thread.
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ FOR_EACH_OBSERVER(Observer, observers_, DeviceChanged(event, path));
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698