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

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: Addressed review comment and disabled MediaFileSystemRegistryTest.GalleryNameMTP Created 7 years, 11 months 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
336 scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_;
337
338 private:
329 MessageLoopForUI message_loop_; 339 MessageLoopForUI message_loop_;
330 content::TestBrowserThread ui_thread_; 340 content::TestBrowserThread ui_thread_;
331 content::TestBrowserThread file_thread_; 341 content::TestBrowserThread file_thread_;
332 342
333 base::SystemMonitor system_monitor_; 343 base::SystemMonitor system_monitor_;
334 base::MockDevicesChangedObserver observer_; 344 base::MockDevicesChangedObserver observer_;
335 scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_;
336 scoped_refptr<TestVolumeMountWatcherWin> volume_mount_watcher_; 345 scoped_refptr<TestVolumeMountWatcherWin> volume_mount_watcher_;
337 }; 346 };
338 347
339 RemovableDeviceNotificationsWindowWinTest:: 348 RemovableDeviceNotificationsWindowWinTest::
340 RemovableDeviceNotificationsWindowWinTest() 349 RemovableDeviceNotificationsWindowWinTest()
341 : ui_thread_(BrowserThread::UI, &message_loop_), 350 : ui_thread_(BrowserThread::UI, &message_loop_),
342 file_thread_(BrowserThread::FILE, &message_loop_) { 351 file_thread_(BrowserThread::FILE, &message_loop_) {
343 } 352 }
344 353
345 RemovableDeviceNotificationsWindowWinTest:: 354 RemovableDeviceNotificationsWindowWinTest::
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 .Times((name.empty() || unique_id.empty()) ? 0 : 1); 493 .Times((name.empty() || unique_id.empty()) ? 0 : 1);
485 } 494 }
486 } 495 }
487 } 496 }
488 window_->InjectDeviceChange( 497 window_->InjectDeviceChange(
489 test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE, 498 test_attach ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE,
490 reinterpret_cast<DWORD>(dev_interface_broadcast.get())); 499 reinterpret_cast<DWORD>(dev_interface_broadcast.get()));
491 RunUntilIdle(); 500 RunUntilIdle();
492 } 501 }
493 502
503 bool RemovableDeviceNotificationsWindowWinTest::GetMTPStorageInfo(
504 const std::string& storage_device_id,
505 string16* pnp_device_id,
506 string16* storage_object_id) {
507 return window_->GetMTPStorageInfoFromDeviceId(storage_device_id,
508 pnp_device_id,
509 storage_object_id);
510 }
511
494 TEST_F(RemovableDeviceNotificationsWindowWinTest, RandomMessage) { 512 TEST_F(RemovableDeviceNotificationsWindowWinTest, RandomMessage) {
495 window_->InjectDeviceChange(DBT_DEVICEQUERYREMOVE, NULL); 513 window_->InjectDeviceChange(DBT_DEVICEQUERYREMOVE, NULL);
496 RunUntilIdle(); 514 RunUntilIdle();
497 } 515 }
498 516
499 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttached) { 517 TEST_F(RemovableDeviceNotificationsWindowWinTest, DevicesAttached) {
500 DeviceIndices device_indices; 518 DeviceIndices device_indices;
501 device_indices.push_back(1); 519 device_indices.push_back(1);
502 device_indices.push_back(5); 520 device_indices.push_back(5);
503 device_indices.push_back(7); 521 device_indices.push_back(7);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 } 653 }
636 654
637 // Attach a device with two data partitions. Verify that attach/detach 655 // Attach a device with two data partitions. Verify that attach/detach
638 // notifications are sent out for each removable storage. 656 // notifications are sent out for each removable storage.
639 TEST_F(RemovableDeviceNotificationsWindowWinTest, 657 TEST_F(RemovableDeviceNotificationsWindowWinTest,
640 MTPDeviceWithMultipleStorageObjects) { 658 MTPDeviceWithMultipleStorageObjects) {
641 DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, true); 659 DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, true);
642 DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, false); 660 DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, false);
643 } 661 }
644 662
663 // Given a MTP storage persistent id, GetMTPStorageInfo() should fetch the
664 // device interface path and local storage object identifier.
665 TEST_F(RemovableDeviceNotificationsWindowWinTest, GetMTPStorageInfo) {
Lei Zhang 2013/01/14 20:49:02 nit: isn't this really testing GetMTPStorageInfoFr
kmadhusu 2013/01/15 19:08:17 Done.
666 DoMTPDeviceTest(kMTPDeviceWithValidInfo, true);
667 PortableDeviceWatcherWin::StorageObjects storage_objects =
668 GetDeviceStorageObjects(kMTPDeviceWithValidInfo);
669 for (PortableDeviceWatcherWin::StorageObjects::const_iterator it =
670 storage_objects.begin(); it != storage_objects.end(); ++it) {
671 string16 pnp_device_id;
672 string16 storage_object_id;
673 ASSERT_TRUE(GetMTPStorageInfo(it->object_persistent_id, &pnp_device_id,
674 &storage_object_id));
675 EXPECT_EQ(kMTPDeviceWithValidInfo, pnp_device_id);
676 EXPECT_EQ(it->object_persistent_id,
677 GetMTPStorageUniqueId(pnp_device_id, storage_object_id));
678 }
679
680 DoMTPDeviceTest(kMTPDeviceWithValidInfo, false);
681 }
682
645 } // namespace chrome 683 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698