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

Side by Side Diff: components/storage_monitor/storage_monitor_unittest.cc

Issue 2082333002: Remove calls to deprecated MessageLoop methods in components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/run_loop.h"
6 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
7 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
8 #include "components/storage_monitor/mock_removable_storage_observer.h" 9 #include "components/storage_monitor/mock_removable_storage_observer.h"
9 #include "components/storage_monitor/storage_monitor.h" 10 #include "components/storage_monitor/storage_monitor.h"
10 #include "components/storage_monitor/test_storage_monitor.h" 11 #include "components/storage_monitor/test_storage_monitor.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace { 14 namespace {
14 15
15 void SetLatch(bool* called) { 16 void SetLatch(bool* called) {
(...skipping 24 matching lines...) Expand all
40 const std::string kDeviceId2 = "dcim:UUID:FFF0-0002"; 41 const std::string kDeviceId2 = "dcim:UUID:FFF0-0002";
41 MockRemovableStorageObserver observer1; 42 MockRemovableStorageObserver observer1;
42 MockRemovableStorageObserver observer2; 43 MockRemovableStorageObserver observer2;
43 TestStorageMonitor monitor; 44 TestStorageMonitor monitor;
44 monitor.AddObserver(&observer1); 45 monitor.AddObserver(&observer1);
45 monitor.AddObserver(&observer2); 46 monitor.AddObserver(&observer2);
46 47
47 StorageInfo info(kDeviceId1, FILE_PATH_LITERAL("path"), base::string16(), 48 StorageInfo info(kDeviceId1, FILE_PATH_LITERAL("path"), base::string16(),
48 base::string16(), base::string16(), 0); 49 base::string16(), base::string16(), 0);
49 monitor.receiver()->ProcessAttach(info); 50 monitor.receiver()->ProcessAttach(info);
50 message_loop.RunUntilIdle(); 51 base::RunLoop().RunUntilIdle();
51 52
52 EXPECT_EQ(kDeviceId1, observer1.last_attached().device_id()); 53 EXPECT_EQ(kDeviceId1, observer1.last_attached().device_id());
53 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer1.last_attached().location()); 54 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer1.last_attached().location());
54 EXPECT_EQ(kDeviceId1, observer2.last_attached().device_id()); 55 EXPECT_EQ(kDeviceId1, observer2.last_attached().device_id());
55 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer2.last_attached().location()); 56 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer2.last_attached().location());
56 EXPECT_EQ(1, observer1.attach_calls()); 57 EXPECT_EQ(1, observer1.attach_calls());
57 EXPECT_EQ(0, observer1.detach_calls()); 58 EXPECT_EQ(0, observer1.detach_calls());
58 59
59 monitor.receiver()->ProcessDetach(kDeviceId1); 60 monitor.receiver()->ProcessDetach(kDeviceId1);
60 monitor.receiver()->ProcessDetach(kDeviceId2); 61 monitor.receiver()->ProcessDetach(kDeviceId2);
61 message_loop.RunUntilIdle(); 62 base::RunLoop().RunUntilIdle();
62 63
63 EXPECT_EQ(kDeviceId1, observer1.last_detached().device_id()); 64 EXPECT_EQ(kDeviceId1, observer1.last_detached().device_id());
64 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer1.last_detached().location()); 65 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer1.last_detached().location());
65 EXPECT_EQ(kDeviceId1, observer2.last_detached().device_id()); 66 EXPECT_EQ(kDeviceId1, observer2.last_detached().device_id());
66 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer2.last_detached().location()); 67 EXPECT_EQ(FILE_PATH_LITERAL("path"), observer2.last_detached().location());
67 68
68 EXPECT_EQ(1, observer1.attach_calls()); 69 EXPECT_EQ(1, observer1.attach_calls());
69 EXPECT_EQ(1, observer2.attach_calls()); 70 EXPECT_EQ(1, observer2.attach_calls());
70 71
71 // The kDeviceId2 won't be notified since it was never attached. 72 // The kDeviceId2 won't be notified since it was never attached.
(...skipping 14 matching lines...) Expand all
86 87
87 TEST(StorageMonitorTest, GetAllAvailableStorageAttachDetach) { 88 TEST(StorageMonitorTest, GetAllAvailableStorageAttachDetach) {
88 TestStorageMonitor::Destroy(); 89 TestStorageMonitor::Destroy();
89 base::MessageLoop message_loop; 90 base::MessageLoop message_loop;
90 TestStorageMonitor monitor; 91 TestStorageMonitor monitor;
91 const std::string kDeviceId1 = "dcim:UUID:FFF0-0042"; 92 const std::string kDeviceId1 = "dcim:UUID:FFF0-0042";
92 const base::FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); 93 const base::FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo"));
93 StorageInfo info1(kDeviceId1, kDevicePath1.value(), base::string16(), 94 StorageInfo info1(kDeviceId1, kDevicePath1.value(), base::string16(),
94 base::string16(), base::string16(), 0); 95 base::string16(), base::string16(), 0);
95 monitor.receiver()->ProcessAttach(info1); 96 monitor.receiver()->ProcessAttach(info1);
96 message_loop.RunUntilIdle(); 97 base::RunLoop().RunUntilIdle();
97 std::vector<StorageInfo> devices = monitor.GetAllAvailableStorages(); 98 std::vector<StorageInfo> devices = monitor.GetAllAvailableStorages();
98 ASSERT_EQ(1U, devices.size()); 99 ASSERT_EQ(1U, devices.size());
99 EXPECT_EQ(kDeviceId1, devices[0].device_id()); 100 EXPECT_EQ(kDeviceId1, devices[0].device_id());
100 EXPECT_EQ(kDevicePath1.value(), devices[0].location()); 101 EXPECT_EQ(kDevicePath1.value(), devices[0].location());
101 102
102 const std::string kDeviceId2 = "dcim:UUID:FFF0-0044"; 103 const std::string kDeviceId2 = "dcim:UUID:FFF0-0044";
103 const base::FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); 104 const base::FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar"));
104 StorageInfo info2(kDeviceId2, kDevicePath2.value(), base::string16(), 105 StorageInfo info2(kDeviceId2, kDevicePath2.value(), base::string16(),
105 base::string16(), base::string16(), 0); 106 base::string16(), base::string16(), 0);
106 monitor.receiver()->ProcessAttach(info2); 107 monitor.receiver()->ProcessAttach(info2);
107 message_loop.RunUntilIdle(); 108 base::RunLoop().RunUntilIdle();
108 devices = monitor.GetAllAvailableStorages(); 109 devices = monitor.GetAllAvailableStorages();
109 ASSERT_EQ(2U, devices.size()); 110 ASSERT_EQ(2U, devices.size());
110 EXPECT_EQ(kDeviceId1, devices[0].device_id()); 111 EXPECT_EQ(kDeviceId1, devices[0].device_id());
111 EXPECT_EQ(kDevicePath1.value(), devices[0].location()); 112 EXPECT_EQ(kDevicePath1.value(), devices[0].location());
112 EXPECT_EQ(kDeviceId2, devices[1].device_id()); 113 EXPECT_EQ(kDeviceId2, devices[1].device_id());
113 EXPECT_EQ(kDevicePath2.value(), devices[1].location()); 114 EXPECT_EQ(kDevicePath2.value(), devices[1].location());
114 115
115 monitor.receiver()->ProcessDetach(kDeviceId1); 116 monitor.receiver()->ProcessDetach(kDeviceId1);
116 message_loop.RunUntilIdle(); 117 base::RunLoop().RunUntilIdle();
117 devices = monitor.GetAllAvailableStorages(); 118 devices = monitor.GetAllAvailableStorages();
118 ASSERT_EQ(1U, devices.size()); 119 ASSERT_EQ(1U, devices.size());
119 EXPECT_EQ(kDeviceId2, devices[0].device_id()); 120 EXPECT_EQ(kDeviceId2, devices[0].device_id());
120 EXPECT_EQ(kDevicePath2.value(), devices[0].location()); 121 EXPECT_EQ(kDevicePath2.value(), devices[0].location());
121 122
122 monitor.receiver()->ProcessDetach(kDeviceId2); 123 monitor.receiver()->ProcessDetach(kDeviceId2);
123 message_loop.RunUntilIdle(); 124 base::RunLoop().RunUntilIdle();
124 devices = monitor.GetAllAvailableStorages(); 125 devices = monitor.GetAllAvailableStorages();
125 EXPECT_EQ(0U, devices.size()); 126 EXPECT_EQ(0U, devices.size());
126 } 127 }
127 128
128 } // namespace storage_monitor 129 } // namespace storage_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698