| Index: chrome/browser/chromeos/dbus/mock_cros_disks_client.cc
|
| diff --git a/chrome/browser/chromeos/dbus/mock_cros_disks_client.cc b/chrome/browser/chromeos/dbus/mock_cros_disks_client.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1ce79959a44dec09c19345b4a8fef6f832f5b31e
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/dbus/mock_cros_disks_client.cc
|
| @@ -0,0 +1,166 @@
|
| +// 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/dbus/mock_cros_disks_client.h"
|
| +
|
| +#include "base/message_loop.h"
|
| +#include "base/string_util.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +
|
| +namespace chromeos {
|
| +
|
| +using content::BrowserThread;
|
| +using testing::_;
|
| +using testing::AnyNumber;
|
| +using testing::Invoke;
|
| +using testing::ReturnRef;
|
| +
|
| +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";
|
| +
|
| +void MockCrosDisksClient::AddObserverInternal(
|
| + CrosDisksClient::Observer* observer) {
|
| + observers_.AddObserver(observer);
|
| +}
|
| +
|
| +void MockCrosDisksClient::RemoveObserverInternal(
|
| + CrosDisksClient::Observer* observer) {
|
| + observers_.RemoveObserver(observer);
|
| +}
|
| +
|
| +MockCrosDisksClient::MockCrosDisksClient() {
|
| + ON_CALL(*this, AddObserver(_))
|
| + .WillByDefault(Invoke(this, &MockCrosDisksClient::AddObserverInternal));
|
| + ON_CALL(*this, RemoveObserver(_))
|
| + .WillByDefault(Invoke(this,
|
| + &MockCrosDisksClient::RemoveObserverInternal));
|
| + ON_CALL(*this, disks())
|
| + .WillByDefault(Invoke(this, &MockCrosDisksClient::disksInternal));
|
| +}
|
| +
|
| +MockCrosDisksClient::~MockCrosDisksClient() {
|
| +}
|
| +
|
| +void MockCrosDisksClient::FireDeviceInsertEvents() {
|
| + scoped_ptr<CrosDisksClient::Disk> disk1(new CrosDisksClient::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,
|
| + false,
|
| + true,
|
| + false,
|
| + false));
|
| +
|
| + disks_.clear();
|
| + disks_.insert(std::pair<std::string, CrosDisksClient::Disk*>(
|
| + std::string(kTestDevicePath), disk1.get()));
|
| +
|
| + // Device Added
|
| + chromeos::CrosDisksClientEventType evt;
|
| + evt = chromeos::MOUNT_DEVICE_ADDED;
|
| + UpdateDeviceChanged(evt, kTestSystemPath);
|
| +
|
| + // Disk Added
|
| + evt = chromeos::MOUNT_DISK_ADDED;
|
| + UpdateDiskChanged(evt, disk1.get());
|
| +
|
| + // Disk Changed
|
| + scoped_ptr<CrosDisksClient::Disk> disk2(new CrosDisksClient::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,
|
| + false,
|
| + true,
|
| + false,
|
| + false));
|
| + disks_.clear();
|
| + disks_.insert(std::pair<std::string, CrosDisksClient::Disk*>(
|
| + std::string(kTestDevicePath), disk2.get()));
|
| + evt = chromeos::MOUNT_DISK_CHANGED;
|
| + UpdateDiskChanged(evt, disk2.get());
|
| +}
|
| +
|
| +void MockCrosDisksClient::FireDeviceRemoveEvents() {
|
| + scoped_ptr<CrosDisksClient::Disk> disk(new CrosDisksClient::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,
|
| + false,
|
| + true,
|
| + false,
|
| + false));
|
| + disks_.clear();
|
| + disks_.insert(std::pair<std::string, CrosDisksClient::Disk*>(
|
| + std::string(kTestDevicePath), disk.get()));
|
| + UpdateDiskChanged(chromeos::MOUNT_DISK_REMOVED, disk.get());
|
| +}
|
| +
|
| +void MockCrosDisksClient::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 MockCrosDisksClient::UpdateDiskChanged(CrosDisksClientEventType evt,
|
| + const CrosDisksClient::Disk* disk) {
|
| + // Make sure we run on UI thread.
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| +
|
| + FOR_EACH_OBSERVER(Observer, observers_, DiskChanged(evt, disk));
|
| +}
|
| +
|
| +void MockCrosDisksClient::UpdateDeviceChanged(CrosDisksClientEventType evt,
|
| + const std::string& path) {
|
| + // Make sure we run on UI thread.
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| +
|
| + FOR_EACH_OBSERVER(Observer, observers_, DeviceChanged(evt, path));
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|