| 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 "chrome/browser/system_monitor/removable_device_notifications_window_wi
n.h" | 5 #include "chrome/browser/system_monitor/removable_device_notifications_window_wi
n.h" |
| 6 | 6 |
| 7 #include <dbt.h> | 7 #include <dbt.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 17 #include "base/system_monitor/system_monitor.h" | |
| 18 #include "base/test/mock_devices_changed_observer.h" | |
| 19 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 20 #include "chrome/browser/system_monitor/media_storage_util.h" | 18 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 19 #include "chrome/browser/system_monitor/mock_removable_storage_observer.h" |
| 21 #include "chrome/browser/system_monitor/portable_device_watcher_win.h" | 20 #include "chrome/browser/system_monitor/portable_device_watcher_win.h" |
| 22 #include "chrome/browser/system_monitor/removable_device_constants.h" | 21 #include "chrome/browser/system_monitor/removable_device_constants.h" |
| 23 #include "chrome/browser/system_monitor/volume_mount_watcher_win.h" | 22 #include "chrome/browser/system_monitor/volume_mount_watcher_win.h" |
| 24 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 26 |
| 28 namespace chrome { | 27 namespace chrome { |
| 29 | 28 |
| 30 typedef std::vector<int> DeviceIndices; | 29 typedef std::vector<int> DeviceIndices; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 void DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices); | 322 void DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices); |
| 324 | 323 |
| 325 // Injects a device attach or detach change (depending on the value of | 324 // Injects a device attach or detach change (depending on the value of |
| 326 // |test_attach|) and tests that the appropriate handler is called. | 325 // |test_attach|) and tests that the appropriate handler is called. |
| 327 void DoMTPDeviceTest(const string16& pnp_device_id, bool test_attach); | 326 void DoMTPDeviceTest(const string16& pnp_device_id, bool test_attach); |
| 328 | 327 |
| 329 MessageLoopForUI message_loop_; | 328 MessageLoopForUI message_loop_; |
| 330 content::TestBrowserThread ui_thread_; | 329 content::TestBrowserThread ui_thread_; |
| 331 content::TestBrowserThread file_thread_; | 330 content::TestBrowserThread file_thread_; |
| 332 | 331 |
| 333 base::SystemMonitor system_monitor_; | 332 MockRemovableStorageObserver observer_; |
| 334 base::MockDevicesChangedObserver observer_; | |
| 335 scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_; | 333 scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_; |
| 336 scoped_refptr<TestVolumeMountWatcherWin> volume_mount_watcher_; | 334 scoped_refptr<TestVolumeMountWatcherWin> volume_mount_watcher_; |
| 337 }; | 335 }; |
| 338 | 336 |
| 339 RemovableDeviceNotificationsWindowWinTest:: | 337 RemovableDeviceNotificationsWindowWinTest:: |
| 340 RemovableDeviceNotificationsWindowWinTest() | 338 RemovableDeviceNotificationsWindowWinTest() |
| 341 : ui_thread_(BrowserThread::UI, &message_loop_), | 339 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 342 file_thread_(BrowserThread::FILE, &message_loop_) { | 340 file_thread_(BrowserThread::FILE, &message_loop_) { |
| 343 } | 341 } |
| 344 | 342 |
| 345 RemovableDeviceNotificationsWindowWinTest:: | 343 RemovableDeviceNotificationsWindowWinTest:: |
| 346 ~RemovableDeviceNotificationsWindowWinTest() { | 344 ~RemovableDeviceNotificationsWindowWinTest() { |
| 347 } | 345 } |
| 348 | 346 |
| 349 void RemovableDeviceNotificationsWindowWinTest::SetUp() { | 347 void RemovableDeviceNotificationsWindowWinTest::SetUp() { |
| 350 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 348 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 351 volume_mount_watcher_ = new TestVolumeMountWatcherWin; | 349 volume_mount_watcher_ = new TestVolumeMountWatcherWin; |
| 352 window_.reset(new TestRemovableDeviceNotificationsWindowWin( | 350 window_.reset(new TestRemovableDeviceNotificationsWindowWin( |
| 353 volume_mount_watcher_.get(), new TestPortableDeviceWatcherWin)); | 351 volume_mount_watcher_.get(), new TestPortableDeviceWatcherWin)); |
| 354 window_->InitWithTestData(false); | 352 window_->InitWithTestData(false); |
| 355 RunUntilIdle(); | 353 RunUntilIdle(); |
| 356 system_monitor_.AddDevicesChangedObserver(&observer_); | 354 window_->AddObserver(&observer_); |
| 357 } | 355 } |
| 358 | 356 |
| 359 void RemovableDeviceNotificationsWindowWinTest::TearDown() { | 357 void RemovableDeviceNotificationsWindowWinTest::TearDown() { |
| 360 RunUntilIdle(); | 358 RunUntilIdle(); |
| 361 system_monitor_.RemoveDevicesChangedObserver(&observer_); | 359 window_->RemoveObserver(&observer_); |
| 362 } | 360 } |
| 363 | 361 |
| 364 void RemovableDeviceNotificationsWindowWinTest:: | 362 void RemovableDeviceNotificationsWindowWinTest:: |
| 365 AddMassStorageDeviceAttachExpectation(FilePath drive) { | 363 AddMassStorageDeviceAttachExpectation(FilePath drive) { |
| 366 std::string unique_id; | 364 std::string unique_id; |
| 367 string16 device_name; | 365 string16 device_name; |
| 368 bool removable; | 366 bool removable; |
| 369 ASSERT_TRUE(GetMassStorageDeviceDetails(drive, NULL, &unique_id, | 367 ASSERT_TRUE(GetMassStorageDeviceDetails(drive, NULL, &unique_id, |
| 370 &device_name, &removable)); | 368 &device_name, &removable)); |
| 371 if (removable) { | 369 if (removable) { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 PreAttachDevices(); | 582 PreAttachDevices(); |
| 585 | 583 |
| 586 // An invalid path. | 584 // An invalid path. |
| 587 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(L"COM1:\\"), NULL)); | 585 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(L"COM1:\\"), NULL)); |
| 588 | 586 |
| 589 // An unconnected removable device. | 587 // An unconnected removable device. |
| 590 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(L"E:\\"), NULL)); | 588 EXPECT_FALSE(window_->GetDeviceInfoForPath(FilePath(L"E:\\"), NULL)); |
| 591 | 589 |
| 592 // A connected removable device. | 590 // A connected removable device. |
| 593 FilePath removable_device(L"F:\\"); | 591 FilePath removable_device(L"F:\\"); |
| 594 base::SystemMonitor::RemovableStorageInfo device_info; | 592 RemovableStorageNotifications::StorageInfo device_info; |
| 595 EXPECT_TRUE(window_->GetDeviceInfoForPath(removable_device, &device_info)); | 593 EXPECT_TRUE(window_->GetDeviceInfoForPath(removable_device, &device_info)); |
| 596 | 594 |
| 597 std::string unique_id; | 595 std::string unique_id; |
| 598 string16 device_name; | 596 string16 device_name; |
| 599 bool removable; | 597 bool removable; |
| 600 ASSERT_TRUE(GetMassStorageDeviceDetails(removable_device, NULL, &unique_id, | 598 ASSERT_TRUE(GetMassStorageDeviceDetails(removable_device, NULL, &unique_id, |
| 601 &device_name, &removable)); | 599 &device_name, &removable)); |
| 602 EXPECT_TRUE(removable); | 600 EXPECT_TRUE(removable); |
| 603 std::string device_id = MediaStorageUtil::MakeDeviceId( | 601 std::string device_id = MediaStorageUtil::MakeDeviceId( |
| 604 MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, unique_id); | 602 MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM, unique_id); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 | 634 |
| 637 // Attach a device with two data partitions. Verify that attach/detach | 635 // Attach a device with two data partitions. Verify that attach/detach |
| 638 // notifications are sent out for each removable storage. | 636 // notifications are sent out for each removable storage. |
| 639 TEST_F(RemovableDeviceNotificationsWindowWinTest, | 637 TEST_F(RemovableDeviceNotificationsWindowWinTest, |
| 640 MTPDeviceWithMultipleStorageObjects) { | 638 MTPDeviceWithMultipleStorageObjects) { |
| 641 DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, true); | 639 DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, true); |
| 642 DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, false); | 640 DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, false); |
| 643 } | 641 } |
| 644 | 642 |
| 645 } // namespace chrome | 643 } // namespace chrome |
| OLD | NEW |