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" | |
11 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
12 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
13 #include "base/test/scoped_task_scheduler.h" | 12 #include "base/test/scoped_task_environment.h" |
14 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
15 #include "chromeos/dbus/fake_cros_disks_client.h" | 14 #include "chromeos/dbus/fake_cros_disks_client.h" |
16 #include "chromeos/disks/disk_mount_manager.h" | 15 #include "chromeos/disks/disk_mount_manager.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
18 | 17 |
19 using base::MakeUnique; | 18 using base::MakeUnique; |
20 using base::StringPrintf; | 19 using base::StringPrintf; |
21 using chromeos::disks::DiskMountManager; | 20 using chromeos::disks::DiskMountManager; |
22 using chromeos::CrosDisksClient; | 21 using chromeos::CrosDisksClient; |
23 using chromeos::DBusThreadManager; | 22 using chromeos::DBusThreadManager; |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 | 398 |
400 // Shift operators of ostream. | 399 // Shift operators of ostream. |
401 // Needed to print values in case of EXPECT_* failure in gtest. | 400 // Needed to print values in case of EXPECT_* failure in gtest. |
402 std::ostream& operator<<(std::ostream& stream, | 401 std::ostream& operator<<(std::ostream& stream, |
403 const FormatEvent& format_event) { | 402 const FormatEvent& format_event) { |
404 return stream << format_event.DebugString(); | 403 return stream << format_event.DebugString(); |
405 } | 404 } |
406 | 405 |
407 class DiskMountManagerTest : public testing::Test { | 406 class DiskMountManagerTest : public testing::Test { |
408 public: | 407 public: |
409 DiskMountManagerTest() : scoped_task_scheduler_(&message_loop_) {} | 408 DiskMountManagerTest() = default; |
410 ~DiskMountManagerTest() override {} | 409 ~DiskMountManagerTest() override {} |
411 | 410 |
412 // Sets up test dbus tread manager and disks mount manager. | 411 // Sets up test dbus tread manager and disks mount manager. |
413 // Initializes disk mount manager disks and mount points. | 412 // Initializes disk mount manager disks and mount points. |
414 // Adds a test observer to the disk mount manager. | 413 // Adds a test observer to the disk mount manager. |
415 void SetUp() override { | 414 void SetUp() override { |
416 fake_cros_disks_client_ = new FakeCrosDisksClient; | 415 fake_cros_disks_client_ = new FakeCrosDisksClient; |
417 DBusThreadManager::GetSetterForTesting()->SetCrosDisksClient( | 416 DBusThreadManager::GetSetterForTesting()->SetCrosDisksClient( |
418 std::unique_ptr<CrosDisksClient>(fake_cros_disks_client_)); | 417 std::unique_ptr<CrosDisksClient>(fake_cros_disks_client_)); |
419 | 418 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 | 475 |
477 for (size_t i = 0; i < arraysize(kTestMountPoints); i++) | 476 for (size_t i = 0; i < arraysize(kTestMountPoints); i++) |
478 AddTestMountPoint(kTestMountPoints[i]); | 477 AddTestMountPoint(kTestMountPoints[i]); |
479 } | 478 } |
480 | 479 |
481 protected: | 480 protected: |
482 chromeos::FakeCrosDisksClient* fake_cros_disks_client_; | 481 chromeos::FakeCrosDisksClient* fake_cros_disks_client_; |
483 std::unique_ptr<MockDiskMountManagerObserver> observer_; | 482 std::unique_ptr<MockDiskMountManagerObserver> observer_; |
484 | 483 |
485 private: | 484 private: |
486 base::MessageLoopForUI message_loop_; | 485 base::test::ScopedTaskEnvironment scoped_task_environment_; |
gab
2017/05/01 19:05:03
ForUI not matched?
fdoray
2017/05/03 17:38:14
Done.
| |
487 base::test::ScopedTaskScheduler scoped_task_scheduler_; | |
488 }; | 486 }; |
489 | 487 |
490 // Tests that the observer gets notified on attempt to format non existent mount | 488 // Tests that the observer gets notified on attempt to format non existent mount |
491 // point. | 489 // point. |
492 TEST_F(DiskMountManagerTest, Format_NotMounted) { | 490 TEST_F(DiskMountManagerTest, Format_NotMounted) { |
493 DiskMountManager::GetInstance()->FormatMountedDevice("/mount/non_existent"); | 491 DiskMountManager::GetInstance()->FormatMountedDevice("/mount/non_existent"); |
494 ASSERT_EQ(1U, observer_->GetEventCount()); | 492 ASSERT_EQ(1U, observer_->GetEventCount()); |
495 EXPECT_EQ(FormatEvent(DiskMountManager::FORMAT_COMPLETED, | 493 EXPECT_EQ(FormatEvent(DiskMountManager::FORMAT_COMPLETED, |
496 chromeos::FORMAT_ERROR_UNKNOWN, "/mount/non_existent"), | 494 chromeos::FORMAT_ERROR_UNKNOWN, "/mount/non_existent"), |
497 observer_->GetFormatEvent(0)); | 495 observer_->GetFormatEvent(0)); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
933 VerifyMountEvent(observer_->GetMountEvent(1), DiskMountManager::MOUNTING, | 931 VerifyMountEvent(observer_->GetMountEvent(1), DiskMountManager::MOUNTING, |
934 chromeos::MOUNT_ERROR_NONE, kDevice1MountPath); | 932 chromeos::MOUNT_ERROR_NONE, kDevice1MountPath); |
935 // The read-write device should be remounted in read-write mode. | 933 // The read-write device should be remounted in read-write mode. |
936 EXPECT_FALSE( | 934 EXPECT_FALSE( |
937 manager->FindDiskBySourcePath(kDevice1SourcePath)->is_read_only()); | 935 manager->FindDiskBySourcePath(kDevice1SourcePath)->is_read_only()); |
938 // Remounted disk should also appear as writable to observers. | 936 // Remounted disk should also appear as writable to observers. |
939 EXPECT_FALSE(observer_->GetMountEvent(1).disk->is_read_only()); | 937 EXPECT_FALSE(observer_->GetMountEvent(1).disk->is_read_only()); |
940 } | 938 } |
941 | 939 |
942 } // namespace | 940 } // namespace |
OLD | NEW |