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