| 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "chrome/browser/storage_monitor/mock_removable_storage_observer.h" | 8 #include "chrome/browser/storage_monitor/mock_removable_storage_observer.h" |
| 9 #include "chrome/browser/storage_monitor/storage_monitor.h" | 9 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 10 #include "chrome/browser/storage_monitor/test_storage_monitor.h" | 10 #include "chrome/browser/storage_monitor/test_storage_monitor.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 monitor.EnsureInitialized(base::Bind(&SetLatch, &initialized)); | 27 monitor.EnsureInitialized(base::Bind(&SetLatch, &initialized)); |
| 28 EXPECT_TRUE(monitor.init_called()); | 28 EXPECT_TRUE(monitor.init_called()); |
| 29 EXPECT_FALSE(initialized); | 29 EXPECT_FALSE(initialized); |
| 30 monitor.MarkInitialized(); | 30 monitor.MarkInitialized(); |
| 31 EXPECT_TRUE(initialized); | 31 EXPECT_TRUE(initialized); |
| 32 } | 32 } |
| 33 | 33 |
| 34 TEST(StorageMonitorTest, DeviceAttachDetachNotifications) { | 34 TEST(StorageMonitorTest, DeviceAttachDetachNotifications) { |
| 35 TestStorageMonitor::RemoveSingleton(); | 35 TestStorageMonitor::RemoveSingleton(); |
| 36 base::MessageLoop message_loop; | 36 base::MessageLoop message_loop; |
| 37 const base::string16 kDeviceName = ASCIIToUTF16("media device"); | 37 const base::string16 kDeviceName = base::ASCIIToUTF16("media device"); |
| 38 const std::string kDeviceId1 = "dcim:UUID:FFF0-0001"; | 38 const std::string kDeviceId1 = "dcim:UUID:FFF0-0001"; |
| 39 const std::string kDeviceId2 = "dcim:UUID:FFF0-0002"; | 39 const std::string kDeviceId2 = "dcim:UUID:FFF0-0002"; |
| 40 MockRemovableStorageObserver observer1; | 40 MockRemovableStorageObserver observer1; |
| 41 MockRemovableStorageObserver observer2; | 41 MockRemovableStorageObserver observer2; |
| 42 TestStorageMonitor monitor; | 42 TestStorageMonitor monitor; |
| 43 monitor.AddObserver(&observer1); | 43 monitor.AddObserver(&observer1); |
| 44 monitor.AddObserver(&observer2); | 44 monitor.AddObserver(&observer2); |
| 45 | 45 |
| 46 StorageInfo info(kDeviceId1, kDeviceName, FILE_PATH_LITERAL("path"), | 46 StorageInfo info(kDeviceId1, kDeviceName, FILE_PATH_LITERAL("path"), |
| 47 base::string16(), base::string16(), base::string16(), 0); | 47 base::string16(), base::string16(), base::string16(), 0); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 TestStorageMonitor monitor; | 85 TestStorageMonitor monitor; |
| 86 std::vector<StorageInfo> devices = monitor.GetAllAvailableStorages(); | 86 std::vector<StorageInfo> devices = monitor.GetAllAvailableStorages(); |
| 87 EXPECT_EQ(0U, devices.size()); | 87 EXPECT_EQ(0U, devices.size()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 TEST(StorageMonitorTest, GetAllAvailableStorageAttachDetach) { | 90 TEST(StorageMonitorTest, GetAllAvailableStorageAttachDetach) { |
| 91 TestStorageMonitor::RemoveSingleton(); | 91 TestStorageMonitor::RemoveSingleton(); |
| 92 base::MessageLoop message_loop; | 92 base::MessageLoop message_loop; |
| 93 TestStorageMonitor monitor; | 93 TestStorageMonitor monitor; |
| 94 const std::string kDeviceId1 = "dcim:UUID:FFF0-0042"; | 94 const std::string kDeviceId1 = "dcim:UUID:FFF0-0042"; |
| 95 const base::string16 kDeviceName1 = ASCIIToUTF16("test"); | 95 const base::string16 kDeviceName1 = base::ASCIIToUTF16("test"); |
| 96 const base::FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); | 96 const base::FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); |
| 97 StorageInfo info1(kDeviceId1, kDeviceName1, kDevicePath1.value(), | 97 StorageInfo info1(kDeviceId1, kDeviceName1, kDevicePath1.value(), |
| 98 base::string16(), base::string16(), base::string16(), 0); | 98 base::string16(), base::string16(), base::string16(), 0); |
| 99 monitor.receiver()->ProcessAttach(info1); | 99 monitor.receiver()->ProcessAttach(info1); |
| 100 message_loop.RunUntilIdle(); | 100 message_loop.RunUntilIdle(); |
| 101 std::vector<StorageInfo> devices = monitor.GetAllAvailableStorages(); | 101 std::vector<StorageInfo> devices = monitor.GetAllAvailableStorages(); |
| 102 ASSERT_EQ(1U, devices.size()); | 102 ASSERT_EQ(1U, devices.size()); |
| 103 EXPECT_EQ(kDeviceId1, devices[0].device_id()); | 103 EXPECT_EQ(kDeviceId1, devices[0].device_id()); |
| 104 EXPECT_EQ(kDeviceName1, devices[0].name()); | 104 EXPECT_EQ(kDeviceName1, devices[0].name()); |
| 105 EXPECT_EQ(kDevicePath1.value(), devices[0].location()); | 105 EXPECT_EQ(kDevicePath1.value(), devices[0].location()); |
| 106 | 106 |
| 107 const std::string kDeviceId2 = "dcim:UUID:FFF0-0044"; | 107 const std::string kDeviceId2 = "dcim:UUID:FFF0-0044"; |
| 108 const base::string16 kDeviceName2 = ASCIIToUTF16("test2"); | 108 const base::string16 kDeviceName2 = base::ASCIIToUTF16("test2"); |
| 109 const base::FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); | 109 const base::FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); |
| 110 StorageInfo info2(kDeviceId2, kDeviceName2, kDevicePath2.value(), | 110 StorageInfo info2(kDeviceId2, kDeviceName2, kDevicePath2.value(), |
| 111 base::string16(), base::string16(), base::string16(), 0); | 111 base::string16(), base::string16(), base::string16(), 0); |
| 112 monitor.receiver()->ProcessAttach(info2); | 112 monitor.receiver()->ProcessAttach(info2); |
| 113 message_loop.RunUntilIdle(); | 113 message_loop.RunUntilIdle(); |
| 114 devices = monitor.GetAllAvailableStorages(); | 114 devices = monitor.GetAllAvailableStorages(); |
| 115 ASSERT_EQ(2U, devices.size()); | 115 ASSERT_EQ(2U, devices.size()); |
| 116 EXPECT_EQ(kDeviceId1, devices[0].device_id()); | 116 EXPECT_EQ(kDeviceId1, devices[0].device_id()); |
| 117 EXPECT_EQ(kDeviceName1, devices[0].name()); | 117 EXPECT_EQ(kDeviceName1, devices[0].name()); |
| 118 EXPECT_EQ(kDevicePath1.value(), devices[0].location()); | 118 EXPECT_EQ(kDevicePath1.value(), devices[0].location()); |
| 119 EXPECT_EQ(kDeviceId2, devices[1].device_id()); | 119 EXPECT_EQ(kDeviceId2, devices[1].device_id()); |
| 120 EXPECT_EQ(kDeviceName2, devices[1].name()); | 120 EXPECT_EQ(kDeviceName2, devices[1].name()); |
| 121 EXPECT_EQ(kDevicePath2.value(), devices[1].location()); | 121 EXPECT_EQ(kDevicePath2.value(), devices[1].location()); |
| 122 | 122 |
| 123 monitor.receiver()->ProcessDetach(kDeviceId1); | 123 monitor.receiver()->ProcessDetach(kDeviceId1); |
| 124 message_loop.RunUntilIdle(); | 124 message_loop.RunUntilIdle(); |
| 125 devices = monitor.GetAllAvailableStorages(); | 125 devices = monitor.GetAllAvailableStorages(); |
| 126 ASSERT_EQ(1U, devices.size()); | 126 ASSERT_EQ(1U, devices.size()); |
| 127 EXPECT_EQ(kDeviceId2, devices[0].device_id()); | 127 EXPECT_EQ(kDeviceId2, devices[0].device_id()); |
| 128 EXPECT_EQ(kDeviceName2, devices[0].name()); | 128 EXPECT_EQ(kDeviceName2, devices[0].name()); |
| 129 EXPECT_EQ(kDevicePath2.value(), devices[0].location()); | 129 EXPECT_EQ(kDevicePath2.value(), devices[0].location()); |
| 130 | 130 |
| 131 monitor.receiver()->ProcessDetach(kDeviceId2); | 131 monitor.receiver()->ProcessDetach(kDeviceId2); |
| 132 message_loop.RunUntilIdle(); | 132 message_loop.RunUntilIdle(); |
| 133 devices = monitor.GetAllAvailableStorages(); | 133 devices = monitor.GetAllAvailableStorages(); |
| 134 EXPECT_EQ(0U, devices.size()); | 134 EXPECT_EQ(0U, devices.size()); |
| 135 } | 135 } |
| OLD | NEW |