OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/test/scoped_task_scheduler.h" |
13 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
14 #include "chromeos/dbus/fake_cros_disks_client.h" | 15 #include "chromeos/dbus/fake_cros_disks_client.h" |
15 #include "chromeos/disks/disk_mount_manager.h" | 16 #include "chromeos/disks/disk_mount_manager.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 using base::MakeUnique; | 19 using base::MakeUnique; |
19 using base::StringPrintf; | 20 using base::StringPrintf; |
20 using chromeos::disks::DiskMountManager; | 21 using chromeos::disks::DiskMountManager; |
21 using chromeos::CrosDisksClient; | 22 using chromeos::CrosDisksClient; |
22 using chromeos::DBusThreadManager; | 23 using chromeos::DBusThreadManager; |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 399 |
399 // Shift operators of ostream. | 400 // Shift operators of ostream. |
400 // Needed to print values in case of EXPECT_* failure in gtest. | 401 // Needed to print values in case of EXPECT_* failure in gtest. |
401 std::ostream& operator<<(std::ostream& stream, | 402 std::ostream& operator<<(std::ostream& stream, |
402 const FormatEvent& format_event) { | 403 const FormatEvent& format_event) { |
403 return stream << format_event.DebugString(); | 404 return stream << format_event.DebugString(); |
404 } | 405 } |
405 | 406 |
406 class DiskMountManagerTest : public testing::Test { | 407 class DiskMountManagerTest : public testing::Test { |
407 public: | 408 public: |
408 DiskMountManagerTest() {} | 409 DiskMountManagerTest() : scoped_task_scheduler_(&message_loop_) {} |
409 ~DiskMountManagerTest() override {} | 410 ~DiskMountManagerTest() override {} |
410 | 411 |
411 // Sets up test dbus tread manager and disks mount manager. | 412 // Sets up test dbus tread manager and disks mount manager. |
412 // Initializes disk mount manager disks and mount points. | 413 // Initializes disk mount manager disks and mount points. |
413 // Adds a test observer to the disk mount manager. | 414 // Adds a test observer to the disk mount manager. |
414 void SetUp() override { | 415 void SetUp() override { |
415 fake_cros_disks_client_ = new FakeCrosDisksClient; | 416 fake_cros_disks_client_ = new FakeCrosDisksClient; |
416 DBusThreadManager::GetSetterForTesting()->SetCrosDisksClient( | 417 DBusThreadManager::GetSetterForTesting()->SetCrosDisksClient( |
417 std::unique_ptr<CrosDisksClient>(fake_cros_disks_client_)); | 418 std::unique_ptr<CrosDisksClient>(fake_cros_disks_client_)); |
418 | 419 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 for (size_t i = 0; i < arraysize(kTestDisks); i++) | 474 for (size_t i = 0; i < arraysize(kTestDisks); i++) |
474 AddTestDisk(kTestDisks[i]); | 475 AddTestDisk(kTestDisks[i]); |
475 | 476 |
476 for (size_t i = 0; i < arraysize(kTestMountPoints); i++) | 477 for (size_t i = 0; i < arraysize(kTestMountPoints); i++) |
477 AddTestMountPoint(kTestMountPoints[i]); | 478 AddTestMountPoint(kTestMountPoints[i]); |
478 } | 479 } |
479 | 480 |
480 protected: | 481 protected: |
481 chromeos::FakeCrosDisksClient* fake_cros_disks_client_; | 482 chromeos::FakeCrosDisksClient* fake_cros_disks_client_; |
482 std::unique_ptr<MockDiskMountManagerObserver> observer_; | 483 std::unique_ptr<MockDiskMountManagerObserver> observer_; |
| 484 |
| 485 private: |
483 base::MessageLoopForUI message_loop_; | 486 base::MessageLoopForUI message_loop_; |
| 487 base::test::ScopedTaskScheduler scoped_task_scheduler_; |
484 }; | 488 }; |
485 | 489 |
486 // Tests that the observer gets notified on attempt to format non existent mount | 490 // Tests that the observer gets notified on attempt to format non existent mount |
487 // point. | 491 // point. |
488 TEST_F(DiskMountManagerTest, Format_NotMounted) { | 492 TEST_F(DiskMountManagerTest, Format_NotMounted) { |
489 DiskMountManager::GetInstance()->FormatMountedDevice("/mount/non_existent"); | 493 DiskMountManager::GetInstance()->FormatMountedDevice("/mount/non_existent"); |
490 ASSERT_EQ(1U, observer_->GetEventCount()); | 494 ASSERT_EQ(1U, observer_->GetEventCount()); |
491 EXPECT_EQ(FormatEvent(DiskMountManager::FORMAT_COMPLETED, | 495 EXPECT_EQ(FormatEvent(DiskMountManager::FORMAT_COMPLETED, |
492 chromeos::FORMAT_ERROR_UNKNOWN, "/mount/non_existent"), | 496 chromeos::FORMAT_ERROR_UNKNOWN, "/mount/non_existent"), |
493 observer_->GetFormatEvent(0)); | 497 observer_->GetFormatEvent(0)); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 VerifyMountEvent(observer_->GetMountEvent(1), DiskMountManager::MOUNTING, | 933 VerifyMountEvent(observer_->GetMountEvent(1), DiskMountManager::MOUNTING, |
930 chromeos::MOUNT_ERROR_NONE, kDevice1MountPath); | 934 chromeos::MOUNT_ERROR_NONE, kDevice1MountPath); |
931 // The read-write device should be remounted in read-write mode. | 935 // The read-write device should be remounted in read-write mode. |
932 EXPECT_FALSE( | 936 EXPECT_FALSE( |
933 manager->FindDiskBySourcePath(kDevice1SourcePath)->is_read_only()); | 937 manager->FindDiskBySourcePath(kDevice1SourcePath)->is_read_only()); |
934 // Remounted disk should also appear as writable to observers. | 938 // Remounted disk should also appear as writable to observers. |
935 EXPECT_FALSE(observer_->GetMountEvent(1).disk->is_read_only()); | 939 EXPECT_FALSE(observer_->GetMountEvent(1).disk->is_read_only()); |
936 } | 940 } |
937 | 941 |
938 } // namespace | 942 } // namespace |
OLD | NEW |