| 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 // chromeos::RemovableDeviceNotificationsCros unit tests. | 5 // chromeos::RemovableDeviceNotificationsCros unit tests. |
| 6 | 6 |
| 7 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos.
h" | 7 #include "chrome/browser/system_monitor/removable_device_notifications_chromeos.
h" |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/system_monitor/system_monitor.h" | |
| 15 #include "base/test/mock_devices_changed_observer.h" | |
| 16 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/system_monitor/media_storage_util.h" | 15 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 18 #include "chrome/browser/system_monitor/removable_device_constants.h" | 16 #include "chrome/browser/system_monitor/removable_device_constants.h" |
| 19 #include "chromeos/disks/mock_disk_mount_manager.h" | 17 #include "chromeos/disks/mock_disk_mount_manager.h" |
| 20 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 20 |
| 23 namespace chromeos { | 21 namespace chromeos { |
| 24 | 22 |
| 25 namespace { | 23 namespace { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Create a directory named |dir| relative to the test directory. | 83 // Create a directory named |dir| relative to the test directory. |
| 86 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" | 84 // Set |with_dcim_dir| to true if the created directory will have a "DCIM" |
| 87 // subdirectory. | 85 // subdirectory. |
| 88 // Returns the full path to the created directory on success, or an empty | 86 // Returns the full path to the created directory on success, or an empty |
| 89 // path on failure. | 87 // path on failure. |
| 90 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir); | 88 FilePath CreateMountPoint(const std::string& dir, bool with_dcim_dir); |
| 91 | 89 |
| 92 static void PostQuitToUIThread(); | 90 static void PostQuitToUIThread(); |
| 93 static void WaitForFileThread(); | 91 static void WaitForFileThread(); |
| 94 | 92 |
| 95 base::MockDevicesChangedObserver& observer() { | 93 MockStorageObserver& observer() { |
| 96 return *mock_devices_changed_observer_; | 94 return *mock_storage_observer_; |
| 97 } | 95 } |
| 98 | 96 |
| 99 private: | 97 private: |
| 100 // The message loops and threads to run tests on. | 98 // The message loops and threads to run tests on. |
| 101 MessageLoop ui_loop_; | 99 MessageLoop ui_loop_; |
| 102 content::TestBrowserThread ui_thread_; | 100 content::TestBrowserThread ui_thread_; |
| 103 content::TestBrowserThread file_thread_; | 101 content::TestBrowserThread file_thread_; |
| 104 | 102 |
| 105 // Temporary directory for created test data. | 103 // Temporary directory for created test data. |
| 106 base::ScopedTempDir scoped_temp_dir_; | 104 base::ScopedTempDir scoped_temp_dir_; |
| 107 | 105 |
| 108 // Objects that talks with RemovableDeviceNotificationsCros. | 106 // Objects that talks with RemovableDeviceNotificationsCros. |
| 109 base::SystemMonitor system_monitor_; | 107 scoped_ptr<MockStorageObserver> mock_storage_observer_; |
| 110 scoped_ptr<base::MockDevicesChangedObserver> mock_devices_changed_observer_; | |
| 111 // Owned by DiskMountManager. | 108 // Owned by DiskMountManager. |
| 112 disks::MockDiskMountManager* disk_mount_manager_mock_; | 109 disks::MockDiskMountManager* disk_mount_manager_mock_; |
| 113 | 110 |
| 114 scoped_refptr<RemovableDeviceNotificationsCros> notifications_; | 111 scoped_refptr<RemovableDeviceNotificationsCros> notifications_; |
| 115 | 112 |
| 116 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsCrosTest); | 113 DISALLOW_COPY_AND_ASSIGN(RemovableDeviceNotificationsCrosTest); |
| 117 }; | 114 }; |
| 118 | 115 |
| 119 RemovableDeviceNotificationsCrosTest::RemovableDeviceNotificationsCrosTest() | 116 RemovableDeviceNotificationsCrosTest::RemovableDeviceNotificationsCrosTest() |
| 120 : ui_thread_(BrowserThread::UI, &ui_loop_), | 117 : ui_thread_(BrowserThread::UI, &ui_loop_), |
| 121 file_thread_(BrowserThread::FILE) { | 118 file_thread_(BrowserThread::FILE) { |
| 122 } | 119 } |
| 123 | 120 |
| 124 RemovableDeviceNotificationsCrosTest::~RemovableDeviceNotificationsCrosTest() { | 121 RemovableDeviceNotificationsCrosTest::~RemovableDeviceNotificationsCrosTest() { |
| 125 } | 122 } |
| 126 | 123 |
| 127 void RemovableDeviceNotificationsCrosTest::SetUp() { | 124 void RemovableDeviceNotificationsCrosTest::SetUp() { |
| 128 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 125 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 129 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 126 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
| 130 file_thread_.Start(); | 127 file_thread_.Start(); |
| 131 mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver); | 128 mock_storage_observer_.reset(new MockStorageObserver); |
| 132 system_monitor_.AddDevicesChangedObserver( | 129 notifications_->AddRemovableStorageObserver( |
| 133 mock_devices_changed_observer_.get()); | 130 mock_storage_observer_.get()); |
| 134 | 131 |
| 135 disk_mount_manager_mock_ = new disks::MockDiskMountManager(); | 132 disk_mount_manager_mock_ = new disks::MockDiskMountManager(); |
| 136 DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); | 133 DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); |
| 137 disk_mount_manager_mock_->SetupDefaultReplies(); | 134 disk_mount_manager_mock_->SetupDefaultReplies(); |
| 138 | 135 |
| 139 // Initialize the test subject. | 136 // Initialize the test subject. |
| 140 notifications_ = new RemovableDeviceNotificationsCros(); | 137 notifications_ = new RemovableDeviceNotificationsCros(); |
| 141 } | 138 } |
| 142 | 139 |
| 143 void RemovableDeviceNotificationsCrosTest::TearDown() { | 140 void RemovableDeviceNotificationsCrosTest::TearDown() { |
| 144 notifications_ = NULL; | 141 notifications_ = NULL; |
| 145 disk_mount_manager_mock_ = NULL; | 142 disk_mount_manager_mock_ = NULL; |
| 146 DiskMountManager::Shutdown(); | 143 DiskMountManager::Shutdown(); |
| 147 system_monitor_.RemoveDevicesChangedObserver( | 144 notifications_->RemoveRemovableStorageObserver( |
| 148 mock_devices_changed_observer_.get()); | 145 mock_storage_observer_.get()); |
| 149 WaitForFileThread(); | 146 WaitForFileThread(); |
| 150 } | 147 } |
| 151 | 148 |
| 152 void RemovableDeviceNotificationsCrosTest::MountDevice( | 149 void RemovableDeviceNotificationsCrosTest::MountDevice( |
| 153 MountError error_code, | 150 MountError error_code, |
| 154 const DiskMountManager::MountPointInfo& mount_info, | 151 const DiskMountManager::MountPointInfo& mount_info, |
| 155 const std::string& unique_id, | 152 const std::string& unique_id, |
| 156 const std::string& device_label, | 153 const std::string& device_label, |
| 157 const std::string& vendor_name, | 154 const std::string& vendor_name, |
| 158 const std::string& product_name, | 155 const std::string& product_name, |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 EXPECT_EQ(kDevice1SizeInBytes, GetDeviceStorageSize(mount_path1.value())); | 382 EXPECT_EQ(kDevice1SizeInBytes, GetDeviceStorageSize(mount_path1.value())); |
| 386 EXPECT_CALL(observer(), | 383 EXPECT_CALL(observer(), |
| 387 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) | 384 OnRemovableStorageDetached(GetDCIMDeviceId(kUniqueId1))) |
| 388 .InSequence(mock_sequence); | 385 .InSequence(mock_sequence); |
| 389 UnmountDevice(MOUNT_ERROR_NONE, mount_info); | 386 UnmountDevice(MOUNT_ERROR_NONE, mount_info); |
| 390 } | 387 } |
| 391 | 388 |
| 392 } // namespace | 389 } // namespace |
| 393 | 390 |
| 394 } // namespace chrome | 391 } // namespace chrome |
| OLD | NEW |