Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc

Issue 11297002: [Media Gallery] Added code to support mtp device media file system on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // Runs all the pending tasks on UI thread, FILE thread and blocking thread. 319 // Runs all the pending tasks on UI thread, FILE thread and blocking thread.
320 void RunUntilIdle(); 320 void RunUntilIdle();
321 321
322 void DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices); 322 void DoMassStorageDeviceAttachedTest(const DeviceIndices& device_indices);
323 void DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices); 323 void DoMassStorageDevicesDetachedTest(const DeviceIndices& device_indices);
324 324
325 // Injects a device attach or detach change (depending on the value of 325 // Injects a device attach or detach change (depending on the value of
326 // |test_attach|) and tests that the appropriate handler is called. 326 // |test_attach|) and tests that the appropriate handler is called.
327 void DoMTPDeviceTest(const string16& pnp_device_id, bool test_attach); 327 void DoMTPDeviceTest(const string16& pnp_device_id, bool test_attach);
328 328
329 // Gets the MTP details of the storage specified by the |storage_device_id|.
330 // On success, returns true and fills in |pnp_device_id| and
331 // |storage_object_id|.
332 bool GetMTPStorageInfo(const std::string& storage_device_id,
333 string16* pnp_device_id,
334 string16* storage_object_id);
335
329 MessageLoopForUI message_loop_; 336 MessageLoopForUI message_loop_;
330 content::TestBrowserThread ui_thread_; 337 content::TestBrowserThread ui_thread_;
331 content::TestBrowserThread file_thread_; 338 content::TestBrowserThread file_thread_;
332 339
333 base::SystemMonitor system_monitor_; 340 base::SystemMonitor system_monitor_;
334 base::MockDevicesChangedObserver observer_; 341 base::MockDevicesChangedObserver observer_;
335 scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_; 342 scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_;
336 scoped_refptr<TestVolumeMountWatcherWin> volume_mount_watcher_; 343 scoped_refptr<TestVolumeMountWatcherWin> volume_mount_watcher_;
337 }; 344 };
338 345
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 .Times((name.empty() || unique_id.empty()) ? 0 : 1); 491 .Times((name.empty() || unique_id.empty()) ? 0 : 1);
485 } 492 }
486 } 493 }
487 } 494 }
488 window_->InjectDeviceChange( 495 window_->InjectDeviceChange(
489 test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE, 496 test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE,
490 reinterpret_cast<DWORD>(dev_interface_broadcast.get())); 497 reinterpret_cast<DWORD>(dev_interface_broadcast.get()));
491 RunUntilIdle(); 498 RunUntilIdle();
492 } 499 }
493 500
501 bool RemovableDeviceNotificationsWindowWinTest::GetMTPStorageInfo(
502 const std::string& storage_device_id,
503 string16* pnp_device_id,
504 string16* storage_object_id) {
505 return window_->GetMTPStorageInfoFromDeviceId(storage_device_id,
506 pnp_device_id,
507 storage_object_id);
508 }
509
494 TEST_F(RemovableDeviceNotificationsWindowWinTest, RandomMessage) { 510 TEST_F(RemovableDeviceNotificationsWindowWinTest, RandomMessage) {
495 window_->InjectDeviceChange(DBT_DEVICEQUERYREMOVE, NULL); 511 window_->InjectDeviceChange(DBT_DEVICEQUERYREMOVE, NULL);
496 RunUntilIdle(); 512 RunUntilIdle();
497 } 513 }
498 514
499 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttached) { 515 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttached) {
500 DeviceIndices device_indices; 516 DeviceIndices device_indices;
501 device_indices.push_back(1); 517 device_indices.push_back(1);
502 device_indices.push_back(5); 518 device_indices.push_back(5);
503 device_indices.push_back(7); 519 device_indices.push_back(7);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 } 651 }
636 652
637 // Attach a device with two data partitions. Verify that attach/detach 653 // Attach a device with two data partitions. Verify that attach/detach
638 // notifications are sent out for each removable storage. 654 // notifications are sent out for each removable storage.
639 TEST_F(RemovableDeviceNotificationsWindowWinTest, 655 TEST_F(RemovableDeviceNotificationsWindowWinTest,
640 MTPDeviceWithMultipleStorageObjects) { 656 MTPDeviceWithMultipleStorageObjects) {
641 DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, true); 657 DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, true);
642 DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, false); 658 DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, false);
643 } 659 }
644 660
661 // Given a MTP storage persistent id, GetMTPStorageInfo() should fetch the
662 // device interface path and local storage object identifier.
663 TEST_F(RemovableDeviceNotificationsWindowWinTest, GetMTPStorageInfo) {
664 DoMTPDeviceTest(kMTPDeviceWithValidInfo, true);
665 PortableDeviceWatcherWin::StorageObjects storage_objects =
666 GetDeviceStorageObjects(kMTPDeviceWithValidInfo);
667 for (PortableDeviceWatcherWin::StorageObjects::const_iterator it =
668 storage_objects.begin(); it != storage_objects.end(); ++it) {
669 string16 pnp_device_id;
670 string16 storage_object_id;
671 ASSERT_TRUE(GetMTPStorageInfo(it->object_persistent_id, &pnp_device_id,
672 &storage_object_id));
673 EXPECT_EQ(kMTPDeviceWithValidInfo, pnp_device_id);
674 EXPECT_EQ(it->object_persistent_id,
675 GetMTPStorageUniqueId(pnp_device_id, storage_object_id));
676 }
677
678 DoMTPDeviceTest(kMTPDeviceWithValidInfo, false);
679 }
680
645 } // namespace chrome 681 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698