#include "base/bind.h"
#include "base/message_loop/message_loop.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_cros_disks_client.h"
-#include "chromeos/dbus/fake_dbus_thread_manager.h"
#include "chromeos/disks/disk_mount_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using chromeos::CrosDisksClient;
using chromeos::DBusThreadManager;
using chromeos::FakeCrosDisksClient;
-using chromeos::FakeDBusThreadManager;
using testing::_;
using testing::Field;
using testing::InSequence;
bool is_read_only;
bool has_media;
bool on_boot_device;
+ bool on_removable_device;
bool is_hidden;
};
false, // is read only
true, // has media
false, // is on boot device
+ true, // is on removable device
false // is hidden
},
};
// Initializes disk mount manager disks and mount points.
// Adds a test observer to the disk mount manager.
virtual void SetUp() {
- FakeDBusThreadManager* fake_thread_manager = new FakeDBusThreadManager();
- DBusThreadManager::InitializeForTesting(fake_thread_manager);
-
- fake_cros_disks_client_ = fake_thread_manager->fake_cros_disks_client();
+ fake_cros_disks_client_ = new FakeCrosDisksClient;
+ DBusThreadManager::GetSetterForTesting()->SetCrosDisksClient(
+ scoped_ptr<CrosDisksClient>(fake_cros_disks_client_));
DiskMountManager::Initialize();
disk.is_read_only,
disk.has_media,
disk.on_boot_device,
+ disk.on_removable_device,
disk.is_hidden)));
}
// Tests that the observer gets notified on attempt to format non existent mount
// point.
TEST_F(DiskMountManagerTest, Format_NotMounted) {
- EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_STARTED,
+ EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_COMPLETED,
chromeos::FORMAT_ERROR_UNKNOWN,
"/mount/non_existent"))
.Times(1);
// Tests that it is not possible to format archive mount point.
TEST_F(DiskMountManagerTest, Format_Archive) {
- EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_STARTED,
+ EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_COMPLETED,
chromeos::FORMAT_ERROR_UNKNOWN,
"/archive/source_path"))
.Times(1);
"/device/mount_path")))
.Times(1);
- EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_STARTED,
+ EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_COMPLETED,
chromeos::FORMAT_ERROR_UNKNOWN,
"/device/source_path"))
.Times(1);
fake_cros_disks_client_->last_unmount_device_path());
EXPECT_EQ(chromeos::UNMOUNT_OPTIONS_NONE,
fake_cros_disks_client_->last_unmount_options());
- EXPECT_EQ(0, fake_cros_disks_client_->format_device_call_count());
+ EXPECT_EQ(0, fake_cros_disks_client_->format_call_count());
// The device mount should still be here.
EXPECT_TRUE(HasMountPoint("/device/mount_path"));
// process.
TEST_F(DiskMountManagerTest, Format_FormatFailsToStart) {
// Before formatting mounted device, the device should be unmounted.
- // In this test, unmount will succeed, but call to FormatDevice method will
+ // In this test, unmount will succeed, but call to Format method will
// fail.
// Set up expectations for observer mock.
"/device/mount_path")))
.Times(1);
- EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_STARTED,
+ EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_COMPLETED,
chromeos::FORMAT_ERROR_UNKNOWN,
"/device/source_path"))
.Times(1);
}
- fake_cros_disks_client_->MakeFormatDeviceFail();
+ fake_cros_disks_client_->MakeFormatFail();
// Start the test.
DiskMountManager::GetInstance()->FormatMountedDevice("/device/mount_path");
fake_cros_disks_client_->last_unmount_device_path());
EXPECT_EQ(chromeos::UNMOUNT_OPTIONS_NONE,
fake_cros_disks_client_->last_unmount_options());
- EXPECT_EQ(1, fake_cros_disks_client_->format_device_call_count());
+ EXPECT_EQ(1, fake_cros_disks_client_->format_call_count());
EXPECT_EQ("/device/source_path",
- fake_cros_disks_client_->last_format_device_device_path());
- EXPECT_EQ("vfat",
- fake_cros_disks_client_->last_format_device_filesystem());
+ fake_cros_disks_client_->last_format_device_path());
+ EXPECT_EQ("vfat", fake_cros_disks_client_->last_format_filesystem());
// The device mount should be gone.
EXPECT_FALSE(HasMountPoint("/device/mount_path"));
// is successfully started.
// Set up expectations for observer mock.
- // The observer should get two FORMAT_STARTED events, one for each format
- // request, but with different error codes (the formatting will be started
- // only for the first request).
+ // The observer should get a FORMAT_STARTED event for one format request and a
+ // FORMAT_COMPLETED with an error code for the other format request. The
+ // formatting will be started only for the first request.
// There should be only one UNMOUNTING event. The result of the second one
// should not be reported as the mount point will go away after the first
// request.
"/device/mount_path")))
.Times(1);
- EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_STARTED,
+ EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_COMPLETED,
chromeos::FORMAT_ERROR_UNKNOWN,
"/device/source_path"))
.Times(1);
fake_cros_disks_client_->last_unmount_device_path());
EXPECT_EQ(chromeos::UNMOUNT_OPTIONS_NONE,
fake_cros_disks_client_->last_unmount_options());
- EXPECT_EQ(1, fake_cros_disks_client_->format_device_call_count());
+ EXPECT_EQ(1, fake_cros_disks_client_->format_call_count());
EXPECT_EQ("/device/source_path",
- fake_cros_disks_client_->last_format_device_device_path());
+ fake_cros_disks_client_->last_format_device_path());
EXPECT_EQ("vfat",
- fake_cros_disks_client_->last_format_device_filesystem());
+ fake_cros_disks_client_->last_format_filesystem());
// The device mount should be gone.
EXPECT_FALSE(HasMountPoint("/device/mount_path"));
// Tests the case when the format process actually starts and fails.
TEST_F(DiskMountManagerTest, Format_FormatFails) {
- // Both unmount and format device cals are successfull in this test.
+ // Both unmount and format device cals are successful in this test.
// Set up expectations for observer mock.
// The observer should get notified that the device was unmounted and that
// formatting has started.
// After the formatting starts, the test will simulate failing
- // FORMATTING_FINISHED signal, so the observer should also be notified the
+ // FORMAT_COMPLETED signal, so the observer should also be notified the
// formatting has failed (FORMAT_COMPLETED event).
{
InSequence s;
// Start the test.
DiskMountManager::GetInstance()->FormatMountedDevice("/device/mount_path");
- // Wait for Unmount and FormatDevice calls to end.
+ // Wait for Unmount and Format calls to end.
message_loop_.RunUntilIdle();
EXPECT_EQ(1, fake_cros_disks_client_->unmount_call_count());
fake_cros_disks_client_->last_unmount_device_path());
EXPECT_EQ(chromeos::UNMOUNT_OPTIONS_NONE,
fake_cros_disks_client_->last_unmount_options());
- EXPECT_EQ(1, fake_cros_disks_client_->format_device_call_count());
+ EXPECT_EQ(1, fake_cros_disks_client_->format_call_count());
EXPECT_EQ("/device/source_path",
- fake_cros_disks_client_->last_format_device_device_path());
- EXPECT_EQ("vfat",
- fake_cros_disks_client_->last_format_device_filesystem());
+ fake_cros_disks_client_->last_format_device_path());
+ EXPECT_EQ("vfat", fake_cros_disks_client_->last_format_filesystem());
// The device should be unmounted by now.
EXPECT_FALSE(HasMountPoint("/device/mount_path"));
- // Send failing FORMATTING_FINISHED signal.
+ // Send failing FORMAT_COMPLETED signal.
// The failure is marked by ! in fromt of the path (but this should change
// soon).
- fake_cros_disks_client_->SendMountEvent(
- chromeos::CROS_DISKS_FORMATTING_FINISHED, "!/device/source_path");
-}
-
-// Tests the same case as Format_FormatFails, but the FORMATTING_FINISHED event
-// is sent with file_path of the formatted device (instead of its device path).
-TEST_F(DiskMountManagerTest, Format_FormatFailsAndReturnFilePath) {
- // Set up expectations for observer mock.
- {
- InSequence s;
-
- EXPECT_CALL(observer_,
- OnMountEvent(DiskMountManager::UNMOUNTING,
- chromeos::MOUNT_ERROR_NONE,
- Field(&DiskMountManager::MountPointInfo::mount_path,
- "/device/mount_path")))
- .Times(1);
-
- EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_STARTED,
- chromeos::FORMAT_ERROR_NONE,
- "/device/source_path"))
- .Times(1);
-
- EXPECT_CALL(observer_, OnFormatEvent(DiskMountManager::FORMAT_COMPLETED,
- chromeos::FORMAT_ERROR_UNKNOWN,
- "/device/source_path"))
- .Times(1);
- }
-
- // Start test.
- DiskMountManager::GetInstance()->FormatMountedDevice("/device/mount_path");
-
- // Wait for Unmount and FormatDevice calls to end.
- message_loop_.RunUntilIdle();
-
- EXPECT_EQ(1, fake_cros_disks_client_->unmount_call_count());
- EXPECT_EQ("/device/mount_path",
- fake_cros_disks_client_->last_unmount_device_path());
- EXPECT_EQ(chromeos::UNMOUNT_OPTIONS_NONE,
- fake_cros_disks_client_->last_unmount_options());
- EXPECT_EQ(1, fake_cros_disks_client_->format_device_call_count());
- EXPECT_EQ("/device/source_path",
- fake_cros_disks_client_->last_format_device_device_path());
- EXPECT_EQ("vfat",
- fake_cros_disks_client_->last_format_device_filesystem());
-
- // The device should be unmounted by now.
- EXPECT_FALSE(HasMountPoint("/device/mount_path"));
-
- // Send failing FORMATTING_FINISHED signal with the device's file path.
- fake_cros_disks_client_->SendMountEvent(
- chromeos::CROS_DISKS_FORMATTING_FINISHED, "!/device/file_path");
+ fake_cros_disks_client_->SendFormatCompletedEvent(
+ chromeos::FORMAT_ERROR_UNKNOWN, "/device/source_path");
}
// Tests the case when formatting completes successfully.
TEST_F(DiskMountManagerTest, Format_FormatSuccess) {
// Set up cros disks client mocks.
- // Both unmount and format device cals are successfull in this test.
+ // Both unmount and format device cals are successful in this test.
// Set up expectations for observer mock.
// The observer should receive UNMOUNTING, FORMAT_STARTED and FORMAT_COMPLETED
// Start the test.
DiskMountManager::GetInstance()->FormatMountedDevice("/device/mount_path");
- // Wait for Unmount and FormatDevice calls to end.
+ // Wait for Unmount and Format calls to end.
message_loop_.RunUntilIdle();
EXPECT_EQ(1, fake_cros_disks_client_->unmount_call_count());
fake_cros_disks_client_->last_unmount_device_path());
EXPECT_EQ(chromeos::UNMOUNT_OPTIONS_NONE,
fake_cros_disks_client_->last_unmount_options());
- EXPECT_EQ(1, fake_cros_disks_client_->format_device_call_count());
+ EXPECT_EQ(1, fake_cros_disks_client_->format_call_count());
EXPECT_EQ("/device/source_path",
- fake_cros_disks_client_->last_format_device_device_path());
- EXPECT_EQ("vfat",
- fake_cros_disks_client_->last_format_device_filesystem());
+ fake_cros_disks_client_->last_format_device_path());
+ EXPECT_EQ("vfat", fake_cros_disks_client_->last_format_filesystem());
// The device should be unmounted by now.
EXPECT_FALSE(HasMountPoint("/device/mount_path"));
// Simulate cros_disks reporting success.
- fake_cros_disks_client_->SendMountEvent(
- chromeos::CROS_DISKS_FORMATTING_FINISHED, "/device/source_path");
+ fake_cros_disks_client_->SendFormatCompletedEvent(
+ chromeos::FORMAT_ERROR_NONE, "/device/source_path");
}
// Tests that it's possible to format the device twice in a row (this may not be
// true if the list of pending formats is not properly cleared).
TEST_F(DiskMountManagerTest, Format_ConsecutiveFormatCalls) {
- // All unmount and format device cals are successfull in this test.
+ // All unmount and format device cals are successful in this test.
// Each of the should be made twice (once for each formatting task).
// Set up expectations for observer mock.
// Start the test.
DiskMountManager::GetInstance()->FormatMountedDevice("/device/mount_path");
- // Wait for Unmount and FormatDevice calls to end.
+ // Wait for Unmount and Format calls to end.
message_loop_.RunUntilIdle();
EXPECT_EQ(1, fake_cros_disks_client_->unmount_call_count());
fake_cros_disks_client_->last_unmount_device_path());
EXPECT_EQ(chromeos::UNMOUNT_OPTIONS_NONE,
fake_cros_disks_client_->last_unmount_options());
- EXPECT_EQ(1, fake_cros_disks_client_->format_device_call_count());
+ EXPECT_EQ(1, fake_cros_disks_client_->format_call_count());
EXPECT_EQ("/device/source_path",
- fake_cros_disks_client_->last_format_device_device_path());
- EXPECT_EQ("vfat",
- fake_cros_disks_client_->last_format_device_filesystem());
+ fake_cros_disks_client_->last_format_device_path());
+ EXPECT_EQ("vfat", fake_cros_disks_client_->last_format_filesystem());
// The device should be unmounted by now.
EXPECT_FALSE(HasMountPoint("/device/mount_path"));
// Simulate cros_disks reporting success.
- fake_cros_disks_client_->SendMountEvent(
- chromeos::CROS_DISKS_FORMATTING_FINISHED, "/device/source_path");
+ fake_cros_disks_client_->SendFormatCompletedEvent(
+ chromeos::FORMAT_ERROR_NONE, "/device/source_path");
// Simulate the device remounting.
fake_cros_disks_client_->SendMountCompletedEvent(
// Try formatting again.
DiskMountManager::GetInstance()->FormatMountedDevice("/device/mount_path");
- // Wait for Unmount and FormatDevice calls to end.
+ // Wait for Unmount and Format calls to end.
message_loop_.RunUntilIdle();
EXPECT_EQ(2, fake_cros_disks_client_->unmount_call_count());
fake_cros_disks_client_->last_unmount_device_path());
EXPECT_EQ(chromeos::UNMOUNT_OPTIONS_NONE,
fake_cros_disks_client_->last_unmount_options());
- EXPECT_EQ(2, fake_cros_disks_client_->format_device_call_count());
+ EXPECT_EQ(2, fake_cros_disks_client_->format_call_count());
EXPECT_EQ("/device/source_path",
- fake_cros_disks_client_->last_format_device_device_path());
- EXPECT_EQ("vfat",
- fake_cros_disks_client_->last_format_device_filesystem());
+ fake_cros_disks_client_->last_format_device_path());
+ EXPECT_EQ("vfat", fake_cros_disks_client_->last_format_filesystem());
// Simulate cros_disks reporting success.
- fake_cros_disks_client_->SendMountEvent(
- chromeos::CROS_DISKS_FORMATTING_FINISHED, "/device/source_path");
+ fake_cros_disks_client_->SendFormatCompletedEvent(
+ chromeos::FORMAT_ERROR_NONE, "/device/source_path");
}
} // namespace