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.h" | 5 #include "base/message_loop.h" |
6 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.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 23 matching lines...) Expand all Loading... |
34 MockRemovableStorageObserver observer2; | 34 MockRemovableStorageObserver observer2; |
35 test::TestStorageMonitor monitor; | 35 test::TestStorageMonitor monitor; |
36 monitor.AddObserver(&observer1); | 36 monitor.AddObserver(&observer1); |
37 monitor.AddObserver(&observer2); | 37 monitor.AddObserver(&observer2); |
38 | 38 |
39 StorageInfo info(kDeviceId1, kDeviceName, FILE_PATH_LITERAL("path"), | 39 StorageInfo info(kDeviceId1, kDeviceName, FILE_PATH_LITERAL("path"), |
40 string16(), string16(), string16(), 0); | 40 string16(), string16(), string16(), 0); |
41 monitor.receiver()->ProcessAttach(info); | 41 monitor.receiver()->ProcessAttach(info); |
42 message_loop.RunUntilIdle(); | 42 message_loop.RunUntilIdle(); |
43 | 43 |
44 EXPECT_EQ(kDeviceId1, observer1.last_attached().device_id); | 44 EXPECT_EQ(kDeviceId1, observer1.last_attached().device_id()); |
45 EXPECT_EQ(kDeviceName, observer1.last_attached().name); | 45 EXPECT_EQ(kDeviceName, observer1.last_attached().name()); |
46 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer1.last_attached().location); | 46 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer1.last_attached().location()); |
47 EXPECT_EQ(kDeviceId1, observer2.last_attached().device_id); | 47 EXPECT_EQ(kDeviceId1, observer2.last_attached().device_id()); |
48 EXPECT_EQ(kDeviceName, observer2.last_attached().name); | 48 EXPECT_EQ(kDeviceName, observer2.last_attached().name()); |
49 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer2.last_attached().location); | 49 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer2.last_attached().location()); |
50 EXPECT_EQ(1, observer1.attach_calls()); | 50 EXPECT_EQ(1, observer1.attach_calls()); |
51 EXPECT_EQ(0, observer1.detach_calls()); | 51 EXPECT_EQ(0, observer1.detach_calls()); |
52 | 52 |
53 monitor.receiver()->ProcessDetach(kDeviceId1); | 53 monitor.receiver()->ProcessDetach(kDeviceId1); |
54 monitor.receiver()->ProcessDetach(kDeviceId2); | 54 monitor.receiver()->ProcessDetach(kDeviceId2); |
55 message_loop.RunUntilIdle(); | 55 message_loop.RunUntilIdle(); |
56 | 56 |
57 EXPECT_EQ(kDeviceId1, observer1.last_detached().device_id); | 57 EXPECT_EQ(kDeviceId1, observer1.last_detached().device_id()); |
58 EXPECT_EQ(kDeviceName, observer1.last_detached().name); | 58 EXPECT_EQ(kDeviceName, observer1.last_detached().name()); |
59 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer1.last_detached().location); | 59 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer1.last_detached().location()); |
60 EXPECT_EQ(kDeviceId1, observer2.last_detached().device_id); | 60 EXPECT_EQ(kDeviceId1, observer2.last_detached().device_id()); |
61 EXPECT_EQ(kDeviceName, observer2.last_detached().name); | 61 EXPECT_EQ(kDeviceName, observer2.last_detached().name()); |
62 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer2.last_detached().location); | 62 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer2.last_detached().location()); |
63 | 63 |
64 EXPECT_EQ(1, observer1.attach_calls()); | 64 EXPECT_EQ(1, observer1.attach_calls()); |
65 EXPECT_EQ(1, observer2.attach_calls()); | 65 EXPECT_EQ(1, observer2.attach_calls()); |
66 | 66 |
67 // The kDeviceId2 won't be notified since it was never attached. | 67 // The kDeviceId2 won't be notified since it was never attached. |
68 EXPECT_EQ(1, observer1.detach_calls()); | 68 EXPECT_EQ(1, observer1.detach_calls()); |
69 EXPECT_EQ(1, observer2.detach_calls()); | 69 EXPECT_EQ(1, observer2.detach_calls()); |
70 | 70 |
71 monitor.RemoveObserver(&observer1); | 71 monitor.RemoveObserver(&observer1); |
72 monitor.RemoveObserver(&observer2); | 72 monitor.RemoveObserver(&observer2); |
(...skipping 11 matching lines...) Expand all Loading... |
84 test::TestStorageMonitor monitor; | 84 test::TestStorageMonitor monitor; |
85 const std::string kDeviceId1 = "42"; | 85 const std::string kDeviceId1 = "42"; |
86 const string16 kDeviceName1 = ASCIIToUTF16("test"); | 86 const string16 kDeviceName1 = ASCIIToUTF16("test"); |
87 const base::FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); | 87 const base::FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); |
88 StorageInfo info1(kDeviceId1, kDeviceName1, kDevicePath1.value(), | 88 StorageInfo info1(kDeviceId1, kDeviceName1, kDevicePath1.value(), |
89 string16(), string16(), string16(), 0); | 89 string16(), string16(), string16(), 0); |
90 monitor.receiver()->ProcessAttach(info1); | 90 monitor.receiver()->ProcessAttach(info1); |
91 message_loop.RunUntilIdle(); | 91 message_loop.RunUntilIdle(); |
92 std::vector<StorageInfo> devices = monitor.GetAttachedStorage(); | 92 std::vector<StorageInfo> devices = monitor.GetAttachedStorage(); |
93 ASSERT_EQ(1U, devices.size()); | 93 ASSERT_EQ(1U, devices.size()); |
94 EXPECT_EQ(kDeviceId1, devices[0].device_id); | 94 EXPECT_EQ(kDeviceId1, devices[0].device_id()); |
95 EXPECT_EQ(kDeviceName1, devices[0].name); | 95 EXPECT_EQ(kDeviceName1, devices[0].name()); |
96 EXPECT_EQ(kDevicePath1.value(), devices[0].location); | 96 EXPECT_EQ(kDevicePath1.value(), devices[0].location()); |
97 | 97 |
98 const std::string kDeviceId2 = "44"; | 98 const std::string kDeviceId2 = "44"; |
99 const string16 kDeviceName2 = ASCIIToUTF16("test2"); | 99 const string16 kDeviceName2 = ASCIIToUTF16("test2"); |
100 const base::FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); | 100 const base::FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); |
101 StorageInfo info2(kDeviceId2, kDeviceName2, kDevicePath2.value(), | 101 StorageInfo info2(kDeviceId2, kDeviceName2, kDevicePath2.value(), |
102 string16(), string16(), string16(), 0); | 102 string16(), string16(), string16(), 0); |
103 monitor.receiver()->ProcessAttach(info2); | 103 monitor.receiver()->ProcessAttach(info2); |
104 message_loop.RunUntilIdle(); | 104 message_loop.RunUntilIdle(); |
105 devices = monitor.GetAttachedStorage(); | 105 devices = monitor.GetAttachedStorage(); |
106 ASSERT_EQ(2U, devices.size()); | 106 ASSERT_EQ(2U, devices.size()); |
107 EXPECT_EQ(kDeviceId1, devices[0].device_id); | 107 EXPECT_EQ(kDeviceId1, devices[0].device_id()); |
108 EXPECT_EQ(kDeviceName1, devices[0].name); | 108 EXPECT_EQ(kDeviceName1, devices[0].name()); |
109 EXPECT_EQ(kDevicePath1.value(), devices[0].location); | 109 EXPECT_EQ(kDevicePath1.value(), devices[0].location()); |
110 EXPECT_EQ(kDeviceId2, devices[1].device_id); | 110 EXPECT_EQ(kDeviceId2, devices[1].device_id()); |
111 EXPECT_EQ(kDeviceName2, devices[1].name); | 111 EXPECT_EQ(kDeviceName2, devices[1].name()); |
112 EXPECT_EQ(kDevicePath2.value(), devices[1].location); | 112 EXPECT_EQ(kDevicePath2.value(), devices[1].location()); |
113 | 113 |
114 monitor.receiver()->ProcessDetach(kDeviceId1); | 114 monitor.receiver()->ProcessDetach(kDeviceId1); |
115 message_loop.RunUntilIdle(); | 115 message_loop.RunUntilIdle(); |
116 devices = monitor.GetAttachedStorage(); | 116 devices = monitor.GetAttachedStorage(); |
117 ASSERT_EQ(1U, devices.size()); | 117 ASSERT_EQ(1U, devices.size()); |
118 EXPECT_EQ(kDeviceId2, devices[0].device_id); | 118 EXPECT_EQ(kDeviceId2, devices[0].device_id()); |
119 EXPECT_EQ(kDeviceName2, devices[0].name); | 119 EXPECT_EQ(kDeviceName2, devices[0].name()); |
120 EXPECT_EQ(kDevicePath2.value(), devices[0].location); | 120 EXPECT_EQ(kDevicePath2.value(), devices[0].location()); |
121 | 121 |
122 monitor.receiver()->ProcessDetach(kDeviceId2); | 122 monitor.receiver()->ProcessDetach(kDeviceId2); |
123 message_loop.RunUntilIdle(); | 123 message_loop.RunUntilIdle(); |
124 devices = monitor.GetAttachedStorage(); | 124 devices = monitor.GetAttachedStorage(); |
125 EXPECT_EQ(0U, devices.size()); | 125 EXPECT_EQ(0U, devices.size()); |
126 } | 126 } |
127 | 127 |
128 } // namespace chrome | 128 } // namespace chrome |
OLD | NEW |