| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "base/system_monitor/system_monitor.h" | 9 #include "base/system_monitor/system_monitor.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/system_monitor/media_storage_util.h" | 11 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 12 #include "chrome/browser/system_monitor/removable_storage_notifications.h" |
| 13 #include "chrome/browser/system_monitor/test_removable_storage_notifications.h" |
| 12 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/test/test_browser_thread.h" | 15 #include "content/public/test/test_browser_thread.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 16 namespace chrome { | 18 namespace chrome { |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 // Sample mtp device id and unique id. | 22 // Sample mtp device id and unique id. |
| 21 const char kMtpDeviceId[] = "mtp:VendorModelSerial:ABC:1233:1237912873"; | 23 const char kMtpDeviceId[] = "mtp:VendorModelSerial:ABC:1233:1237912873"; |
| 22 const char kUniqueId[] = "VendorModelSerial:ABC:1233:1237912873"; | 24 const char kUniqueId[] = "VendorModelSerial:ABC:1233:1237912873"; |
| 23 const char kImageCaptureDeviceId[] = "ic:xyz"; | 25 const char kImageCaptureDeviceId[] = "ic:xyz"; |
| 24 | 26 |
| 25 } // namespace | 27 } // namespace |
| 26 | 28 |
| 27 typedef testing::Test MediaStorageUtilTest; | 29 class MediaStorageUtilTest : public testing::Test { |
| 30 public: |
| 31 void ProcessAttach(const std::string& id, |
| 32 const string16& name, |
| 33 const FilePath::StringType& location) { |
| 34 RemovableStorageNotifications::GetInstance()->ProcessAttach( |
| 35 id, name, location); |
| 36 } |
| 37 |
| 38 private: |
| 39 chrome::test::TestRemovableStorageNotifications notifications_; |
| 40 }; |
| 28 | 41 |
| 29 // Test to verify |MediaStorageUtil::MakeDeviceId| functionality using a sample | 42 // Test to verify |MediaStorageUtil::MakeDeviceId| functionality using a sample |
| 30 // mtp device unique id. | 43 // mtp device unique id. |
| 31 TEST_F(MediaStorageUtilTest, MakeMtpDeviceId) { | 44 TEST_F(MediaStorageUtilTest, MakeMtpDeviceId) { |
| 32 std::string device_id = | 45 std::string device_id = |
| 33 MediaStorageUtil::MakeDeviceId(MediaStorageUtil::MTP_OR_PTP, kUniqueId); | 46 MediaStorageUtil::MakeDeviceId(MediaStorageUtil::MTP_OR_PTP, kUniqueId); |
| 34 ASSERT_EQ(kMtpDeviceId, device_id); | 47 ASSERT_EQ(kMtpDeviceId, device_id); |
| 35 } | 48 } |
| 36 | 49 |
| 37 // Test to verify |MediaStorageUtil::CrackDeviceId| functionality using a sample | 50 // Test to verify |MediaStorageUtil::CrackDeviceId| functionality using a sample |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 MediaStorageUtil::DeviceIdSet devices; | 90 MediaStorageUtil::DeviceIdSet devices; |
| 78 devices.insert(kImageCaptureDeviceId); | 91 devices.insert(kImageCaptureDeviceId); |
| 79 | 92 |
| 80 base::WaitableEvent event(true, false); | 93 base::WaitableEvent event(true, false); |
| 81 MediaStorageUtil::FilterAttachedDevices(&devices, | 94 MediaStorageUtil::FilterAttachedDevices(&devices, |
| 82 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | 95 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
| 83 loop.RunUntilIdle(); | 96 loop.RunUntilIdle(); |
| 84 event.Wait(); | 97 event.Wait(); |
| 85 EXPECT_FALSE(devices.find(kImageCaptureDeviceId) != devices.end()); | 98 EXPECT_FALSE(devices.find(kImageCaptureDeviceId) != devices.end()); |
| 86 | 99 |
| 87 base::SystemMonitor::Get()->ProcessRemovableStorageAttached( | 100 ProcessAttach(kImageCaptureDeviceId, ASCIIToUTF16("name"), |
| 88 kImageCaptureDeviceId, ASCIIToUTF16("name"), | 101 FILE_PATH_LITERAL("/location")); |
| 89 FILE_PATH_LITERAL("/location")); | |
| 90 devices.insert(kImageCaptureDeviceId); | 102 devices.insert(kImageCaptureDeviceId); |
| 91 event.Reset(); | 103 event.Reset(); |
| 92 MediaStorageUtil::FilterAttachedDevices(&devices, | 104 MediaStorageUtil::FilterAttachedDevices(&devices, |
| 93 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | 105 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
| 94 loop.RunUntilIdle(); | 106 loop.RunUntilIdle(); |
| 95 event.Wait(); | 107 event.Wait(); |
| 96 | 108 |
| 97 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); | 109 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); |
| 98 } | 110 } |
| 99 | 111 |
| 100 } // namespace chrome | 112 } // namespace chrome |
| OLD | NEW |