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

Side by Side Diff: chrome/browser/storage_monitor/storage_monitor_unittest.cc

Issue 16186002: Refine StorageMonitor storage device getter (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 6 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
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 "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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
73 } 73 }
74 74
75 TEST(StorageMonitorTest, GetAttachedStorageEmpty) { 75 TEST(StorageMonitorTest, GetAttachedRemovableStoragesEmpty) {
76 base::MessageLoop message_loop; 76 MessageLoop message_loop;
77 test::TestStorageMonitor monitor; 77 test::TestStorageMonitor monitor;
78 std::vector<StorageInfo> devices = monitor.GetAttachedStorage(); 78 std::vector<StorageInfo> devices = monitor.GetAttachedRemovableStorages();
79 EXPECT_EQ(0U, devices.size()); 79 EXPECT_EQ(0U, devices.size());
80 } 80 }
81 81
82 TEST(StorageMonitorTest, GetAllAvailableStoragesEmpty) {
83 MessageLoop message_loop;
84 test::TestStorageMonitor monitor;
85 std::vector<StorageInfo> devices = monitor.GetAllAvailableStorages();
86 EXPECT_EQ(0U, devices.size());
87 }
88
82 TEST(StorageMonitorTest, GetRemovableStorageAttachDetach) { 89 TEST(StorageMonitorTest, GetRemovableStorageAttachDetach) {
83 base::MessageLoop message_loop; 90 base::MessageLoop message_loop;
84 test::TestStorageMonitor monitor; 91 test::TestStorageMonitor monitor;
85 const std::string kDeviceId1 = "42"; 92 const std::string kDeviceId1 = "42";
86 const string16 kDeviceName1 = ASCIIToUTF16("test"); 93 const string16 kDeviceName1 = ASCIIToUTF16("test");
87 const base::FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); 94 const base::FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo"));
88 StorageInfo info1(kDeviceId1, kDeviceName1, kDevicePath1.value(), 95 StorageInfo info1(kDeviceId1, kDeviceName1, kDevicePath1.value(),
89 string16(), string16(), string16(), 0); 96 string16(), string16(), string16(), 0);
90 monitor.receiver()->ProcessAttach(info1); 97 monitor.receiver()->ProcessAttach(info1);
91 message_loop.RunUntilIdle(); 98 message_loop.RunUntilIdle();
92 std::vector<StorageInfo> devices = monitor.GetAttachedStorage(); 99 std::vector<StorageInfo> devices = monitor.GetAttachedRemovableStorages();
93 ASSERT_EQ(1U, devices.size()); 100 ASSERT_EQ(1U, devices.size());
94 EXPECT_EQ(kDeviceId1, devices[0].device_id()); 101 EXPECT_EQ(kDeviceId1, devices[0].device_id());
95 EXPECT_EQ(kDeviceName1, devices[0].name()); 102 EXPECT_EQ(kDeviceName1, devices[0].name());
96 EXPECT_EQ(kDevicePath1.value(), devices[0].location()); 103 EXPECT_EQ(kDevicePath1.value(), devices[0].location());
97 104
98 const std::string kDeviceId2 = "44"; 105 const std::string kDeviceId2 = "44";
99 const string16 kDeviceName2 = ASCIIToUTF16("test2"); 106 const string16 kDeviceName2 = ASCIIToUTF16("test2");
100 const base::FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); 107 const base::FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar"));
101 StorageInfo info2(kDeviceId2, kDeviceName2, kDevicePath2.value(), 108 StorageInfo info2(kDeviceId2, kDeviceName2, kDevicePath2.value(),
102 string16(), string16(), string16(), 0); 109 string16(), string16(), string16(), 0);
103 monitor.receiver()->ProcessAttach(info2); 110 monitor.receiver()->ProcessAttach(info2);
104 message_loop.RunUntilIdle(); 111 message_loop.RunUntilIdle();
105 devices = monitor.GetAttachedStorage(); 112 devices = monitor.GetAttachedRemovableStorages();
106 ASSERT_EQ(2U, devices.size()); 113 ASSERT_EQ(2U, devices.size());
107 EXPECT_EQ(kDeviceId1, devices[0].device_id()); 114 EXPECT_EQ(kDeviceId1, devices[0].device_id());
108 EXPECT_EQ(kDeviceName1, devices[0].name()); 115 EXPECT_EQ(kDeviceName1, devices[0].name());
109 EXPECT_EQ(kDevicePath1.value(), devices[0].location()); 116 EXPECT_EQ(kDevicePath1.value(), devices[0].location());
110 EXPECT_EQ(kDeviceId2, devices[1].device_id()); 117 EXPECT_EQ(kDeviceId2, devices[1].device_id());
111 EXPECT_EQ(kDeviceName2, devices[1].name()); 118 EXPECT_EQ(kDeviceName2, devices[1].name());
112 EXPECT_EQ(kDevicePath2.value(), devices[1].location()); 119 EXPECT_EQ(kDevicePath2.value(), devices[1].location());
113 120
114 monitor.receiver()->ProcessDetach(kDeviceId1); 121 monitor.receiver()->ProcessDetach(kDeviceId1);
115 message_loop.RunUntilIdle(); 122 message_loop.RunUntilIdle();
116 devices = monitor.GetAttachedStorage(); 123 devices = monitor.GetAttachedRemovableStorages();
117 ASSERT_EQ(1U, devices.size()); 124 ASSERT_EQ(1U, devices.size());
118 EXPECT_EQ(kDeviceId2, devices[0].device_id()); 125 EXPECT_EQ(kDeviceId2, devices[0].device_id());
119 EXPECT_EQ(kDeviceName2, devices[0].name()); 126 EXPECT_EQ(kDeviceName2, devices[0].name());
120 EXPECT_EQ(kDevicePath2.value(), devices[0].location()); 127 EXPECT_EQ(kDevicePath2.value(), devices[0].location());
121 128
122 monitor.receiver()->ProcessDetach(kDeviceId2); 129 monitor.receiver()->ProcessDetach(kDeviceId2);
123 message_loop.RunUntilIdle(); 130 message_loop.RunUntilIdle();
124 devices = monitor.GetAttachedStorage(); 131 devices = monitor.GetAttachedRemovableStorages();
125 EXPECT_EQ(0U, devices.size()); 132 EXPECT_EQ(0U, devices.size());
126 } 133 }
127 134
128 } // namespace chrome 135 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698