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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
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/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/storage_monitor/mock_removable_storage_observer.h" 7 #include "chrome/browser/storage_monitor/mock_removable_storage_observer.h"
8 #include "chrome/browser/storage_monitor/storage_monitor.h" 8 #include "chrome/browser/storage_monitor/storage_monitor.h"
9 #include "chrome/browser/storage_monitor/test_storage_monitor.h" 9 #include "chrome/browser/storage_monitor/test_storage_monitor.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace chrome { 12 namespace chrome {
13 13
14 TEST(StorageMonitorTest, DeviceAttachDetachNotifications) { 14 TEST(StorageMonitorTest, DeviceAttachDetachNotifications) {
15 MessageLoop message_loop; 15 base::MessageLoop message_loop;
16 const string16 kDeviceName = ASCIIToUTF16("media device"); 16 const string16 kDeviceName = ASCIIToUTF16("media device");
17 const std::string kDeviceId1 = "1"; 17 const std::string kDeviceId1 = "1";
18 const std::string kDeviceId2 = "2"; 18 const std::string kDeviceId2 = "2";
19 MockRemovableStorageObserver observer1; 19 MockRemovableStorageObserver observer1;
20 MockRemovableStorageObserver observer2; 20 MockRemovableStorageObserver observer2;
21 test::TestStorageMonitor monitor; 21 test::TestStorageMonitor monitor;
22 monitor.AddObserver(&observer1); 22 monitor.AddObserver(&observer1);
23 monitor.AddObserver(&observer2); 23 monitor.AddObserver(&observer2);
24 24
25 StorageInfo info(kDeviceId1, kDeviceName, FILE_PATH_LITERAL("path"), 25 StorageInfo info(kDeviceId1, kDeviceName, FILE_PATH_LITERAL("path"),
(...skipping 26 matching lines...) Expand all
52 52
53 // The kDeviceId2 won't be notified since it was never attached. 53 // The kDeviceId2 won't be notified since it was never attached.
54 EXPECT_EQ(1, observer1.detach_calls()); 54 EXPECT_EQ(1, observer1.detach_calls());
55 EXPECT_EQ(1, observer2.detach_calls()); 55 EXPECT_EQ(1, observer2.detach_calls());
56 56
57 monitor.RemoveObserver(&observer1); 57 monitor.RemoveObserver(&observer1);
58 monitor.RemoveObserver(&observer2); 58 monitor.RemoveObserver(&observer2);
59 } 59 }
60 60
61 TEST(StorageMonitorTest, GetAttachedStorageEmpty) { 61 TEST(StorageMonitorTest, GetAttachedStorageEmpty) {
62 MessageLoop message_loop; 62 base::MessageLoop message_loop;
63 test::TestStorageMonitor monitor; 63 test::TestStorageMonitor monitor;
64 std::vector<StorageInfo> devices = monitor.GetAttachedStorage(); 64 std::vector<StorageInfo> devices = monitor.GetAttachedStorage();
65 EXPECT_EQ(0U, devices.size()); 65 EXPECT_EQ(0U, devices.size());
66 } 66 }
67 67
68 TEST(StorageMonitorTest, GetRemovableStorageAttachDetach) { 68 TEST(StorageMonitorTest, GetRemovableStorageAttachDetach) {
69 MessageLoop message_loop; 69 base::MessageLoop message_loop;
70 test::TestStorageMonitor monitor; 70 test::TestStorageMonitor monitor;
71 const std::string kDeviceId1 = "42"; 71 const std::string kDeviceId1 = "42";
72 const string16 kDeviceName1 = ASCIIToUTF16("test"); 72 const string16 kDeviceName1 = ASCIIToUTF16("test");
73 const base::FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); 73 const base::FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo"));
74 StorageInfo info1(kDeviceId1, kDeviceName1, kDevicePath1.value(), 74 StorageInfo info1(kDeviceId1, kDeviceName1, kDevicePath1.value(),
75 string16(), string16(), string16(), 0); 75 string16(), string16(), string16(), 0);
76 monitor.receiver()->ProcessAttach(info1); 76 monitor.receiver()->ProcessAttach(info1);
77 message_loop.RunUntilIdle(); 77 message_loop.RunUntilIdle();
78 std::vector<StorageInfo> devices = monitor.GetAttachedStorage(); 78 std::vector<StorageInfo> devices = monitor.GetAttachedStorage();
79 ASSERT_EQ(1U, devices.size()); 79 ASSERT_EQ(1U, devices.size());
(...skipping 25 matching lines...) Expand all
105 EXPECT_EQ(kDeviceName2, devices[0].name); 105 EXPECT_EQ(kDeviceName2, devices[0].name);
106 EXPECT_EQ(kDevicePath2.value(), devices[0].location); 106 EXPECT_EQ(kDevicePath2.value(), devices[0].location);
107 107
108 monitor.receiver()->ProcessDetach(kDeviceId2); 108 monitor.receiver()->ProcessDetach(kDeviceId2);
109 message_loop.RunUntilIdle(); 109 message_loop.RunUntilIdle();
110 devices = monitor.GetAttachedStorage(); 110 devices = monitor.GetAttachedStorage();
111 EXPECT_EQ(0U, devices.size()); 111 EXPECT_EQ(0U, devices.size());
112 } 112 }
113 113
114 } // namespace chrome 114 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698