| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/storage_monitor/storage_monitor_chromeos.h" | 5 #include "components/storage_monitor/storage_monitor_chromeos.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 |
| 9 #include <memory> |
| 8 #include <utility> | 10 #include <utility> |
| 9 | 11 |
| 10 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chromeos/disks/mock_disk_mount_manager.h" | 18 #include "chromeos/disks/mock_disk_mount_manager.h" |
| 18 #include "components/storage_monitor/mock_removable_storage_observer.h" | 19 #include "components/storage_monitor/mock_removable_storage_observer.h" |
| 19 #include "components/storage_monitor/removable_device_constants.h" | 20 #include "components/storage_monitor/removable_device_constants.h" |
| 20 #include "components/storage_monitor/storage_info.h" | 21 #include "components/storage_monitor/storage_info.h" |
| 21 #include "components/storage_monitor/test_media_transfer_protocol_manager_linux.
h" | 22 #include "components/storage_monitor/test_media_transfer_protocol_manager_linux.
h" |
| 22 #include "components/storage_monitor/test_storage_monitor.h" | 23 #include "components/storage_monitor/test_storage_monitor.h" |
| 23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/test/test_browser_thread_bundle.h" | 25 #include "content/public/test/test_browser_thread_bundle.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 140 |
| 140 StorageMonitor::EjectStatus status_; | 141 StorageMonitor::EjectStatus status_; |
| 141 | 142 |
| 142 private: | 143 private: |
| 143 content::TestBrowserThreadBundle thread_bundle_; | 144 content::TestBrowserThreadBundle thread_bundle_; |
| 144 | 145 |
| 145 // Temporary directory for created test data. | 146 // Temporary directory for created test data. |
| 146 base::ScopedTempDir scoped_temp_dir_; | 147 base::ScopedTempDir scoped_temp_dir_; |
| 147 | 148 |
| 148 // Objects that talks with StorageMonitorCros. | 149 // Objects that talks with StorageMonitorCros. |
| 149 scoped_ptr<MockRemovableStorageObserver> mock_storage_observer_; | 150 std::unique_ptr<MockRemovableStorageObserver> mock_storage_observer_; |
| 150 | 151 |
| 151 DISALLOW_COPY_AND_ASSIGN(StorageMonitorCrosTest); | 152 DISALLOW_COPY_AND_ASSIGN(StorageMonitorCrosTest); |
| 152 }; | 153 }; |
| 153 | 154 |
| 154 StorageMonitorCrosTest::StorageMonitorCrosTest() | 155 StorageMonitorCrosTest::StorageMonitorCrosTest() |
| 155 : monitor_(NULL), | 156 : monitor_(NULL), |
| 156 disk_mount_manager_mock_(NULL), | 157 disk_mount_manager_mock_(NULL), |
| 157 status_(StorageMonitor::EJECT_FAILURE), | 158 status_(StorageMonitor::EJECT_FAILURE), |
| 158 thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD) { | 159 thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD) { |
| 159 } | 160 } |
| 160 | 161 |
| 161 StorageMonitorCrosTest::~StorageMonitorCrosTest() { | 162 StorageMonitorCrosTest::~StorageMonitorCrosTest() { |
| 162 } | 163 } |
| 163 | 164 |
| 164 void StorageMonitorCrosTest::SetUp() { | 165 void StorageMonitorCrosTest::SetUp() { |
| 165 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 166 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 166 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 167 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
| 167 disk_mount_manager_mock_ = new chromeos::disks::MockDiskMountManager(); | 168 disk_mount_manager_mock_ = new chromeos::disks::MockDiskMountManager(); |
| 168 DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); | 169 DiskMountManager::InitializeForTesting(disk_mount_manager_mock_); |
| 169 disk_mount_manager_mock_->SetupDefaultReplies(); | 170 disk_mount_manager_mock_->SetupDefaultReplies(); |
| 170 | 171 |
| 171 mock_storage_observer_.reset(new MockRemovableStorageObserver); | 172 mock_storage_observer_.reset(new MockRemovableStorageObserver); |
| 172 | 173 |
| 173 // Initialize the test subject. | 174 // Initialize the test subject. |
| 174 TestStorageMonitor::Destroy(); | 175 TestStorageMonitor::Destroy(); |
| 175 monitor_ = new TestStorageMonitorCros(); | 176 monitor_ = new TestStorageMonitorCros(); |
| 176 scoped_ptr<StorageMonitor> pass_monitor(monitor_); | 177 std::unique_ptr<StorageMonitor> pass_monitor(monitor_); |
| 177 StorageMonitor::SetStorageMonitorForTesting(std::move(pass_monitor)); | 178 StorageMonitor::SetStorageMonitorForTesting(std::move(pass_monitor)); |
| 178 | 179 |
| 179 monitor_->Init(); | 180 monitor_->Init(); |
| 180 monitor_->AddObserver(mock_storage_observer_.get()); | 181 monitor_->AddObserver(mock_storage_observer_.get()); |
| 181 } | 182 } |
| 182 | 183 |
| 183 void StorageMonitorCrosTest::TearDown() { | 184 void StorageMonitorCrosTest::TearDown() { |
| 184 monitor_->RemoveObserver(mock_storage_observer_.get()); | 185 monitor_->RemoveObserver(mock_storage_observer_.get()); |
| 185 monitor_ = NULL; | 186 monitor_ = NULL; |
| 186 | 187 |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 base::Bind(&StorageMonitorCrosTest::EjectNotify, | 550 base::Bind(&StorageMonitorCrosTest::EjectNotify, |
| 550 base::Unretained(this))); | 551 base::Unretained(this))); |
| 551 base::RunLoop().RunUntilIdle(); | 552 base::RunLoop().RunUntilIdle(); |
| 552 | 553 |
| 553 EXPECT_EQ(StorageMonitor::EJECT_OK, status_); | 554 EXPECT_EQ(StorageMonitor::EJECT_OK, status_); |
| 554 } | 555 } |
| 555 | 556 |
| 556 } // namespace | 557 } // namespace |
| 557 | 558 |
| 558 } // namespace storage_monitor | 559 } // namespace storage_monitor |
| OLD | NEW |