Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chromeos / disks / disk_mount_manager_unittest.cc
index 83def45..674ee7a 100644 (file)
@@ -4,8 +4,8 @@
 
 #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"
@@ -14,7 +14,6 @@ using chromeos::disks::DiskMountManager;
 using chromeos::CrosDisksClient;
 using chromeos::DBusThreadManager;
 using chromeos::FakeCrosDisksClient;
-using chromeos::FakeDBusThreadManager;
 using testing::_;
 using testing::Field;
 using testing::InSequence;
@@ -41,6 +40,7 @@ struct TestDiskInfo {
   bool is_read_only;
   bool has_media;
   bool on_boot_device;
+  bool on_removable_device;
   bool is_hidden;
 };
 
@@ -73,6 +73,7 @@ const TestDiskInfo kTestDisks[] = {
     false,  // is read only
     true,  // has media
     false,  // is on boot device
+    true,  // is on removable device
     false  // is hidden
   },
 };
@@ -121,10 +122,9 @@ class DiskMountManagerTest : public testing::Test {
   // 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();
 
@@ -171,6 +171,7 @@ class DiskMountManagerTest : public testing::Test {
                                    disk.is_read_only,
                                    disk.has_media,
                                    disk.on_boot_device,
+                                   disk.on_removable_device,
                                    disk.is_hidden)));
   }
 
@@ -205,7 +206,7 @@ class DiskMountManagerTest : public testing::Test {
 // 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);
@@ -214,7 +215,7 @@ TEST_F(DiskMountManagerTest, Format_NotMounted) {
 
 // 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);
@@ -241,7 +242,7 @@ TEST_F(DiskMountManagerTest, Format_FailToUnmount) {
                            "/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);
@@ -259,7 +260,7 @@ TEST_F(DiskMountManagerTest, Format_FailToUnmount) {
             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"));
@@ -269,7 +270,7 @@ TEST_F(DiskMountManagerTest, Format_FailToUnmount) {
 // 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.
@@ -285,13 +286,13 @@ TEST_F(DiskMountManagerTest, Format_FormatFailsToStart) {
                            "/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");
 
@@ -303,11 +304,10 @@ TEST_F(DiskMountManagerTest, Format_FormatFailsToStart) {
             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"));
@@ -321,9 +321,9 @@ TEST_F(DiskMountManagerTest, Format_ConcurrentFormatCalls) {
   // 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.
@@ -340,7 +340,7 @@ TEST_F(DiskMountManagerTest, Format_ConcurrentFormatCalls) {
                            "/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);
@@ -366,11 +366,11 @@ TEST_F(DiskMountManagerTest, Format_ConcurrentFormatCalls) {
             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"));
@@ -378,13 +378,13 @@ TEST_F(DiskMountManagerTest, Format_ConcurrentFormatCalls) {
 
 // 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;
@@ -410,7 +410,7 @@ TEST_F(DiskMountManagerTest, Format_FormatFails) {
   // 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());
@@ -418,76 +418,25 @@ TEST_F(DiskMountManagerTest, Format_FormatFails) {
             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
@@ -516,7 +465,7 @@ TEST_F(DiskMountManagerTest, Format_FormatSuccess) {
   // 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());
@@ -524,24 +473,23 @@ TEST_F(DiskMountManagerTest, Format_FormatSuccess) {
             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.
@@ -577,7 +525,7 @@ TEST_F(DiskMountManagerTest, Format_ConsecutiveFormatCalls) {
   // 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());
@@ -585,18 +533,17 @@ TEST_F(DiskMountManagerTest, Format_ConsecutiveFormatCalls) {
             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(
@@ -610,7 +557,7 @@ TEST_F(DiskMountManagerTest, Format_ConsecutiveFormatCalls) {
   // 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());
@@ -618,15 +565,14 @@ TEST_F(DiskMountManagerTest, Format_ConsecutiveFormatCalls) {
             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