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

Side by Side Diff: chrome/browser/system_monitor/removable_storage_notifications_unittest.cc

Issue 11573048: [Media Galleries] Move RemovableStorageInfo notifications to chrome namespace (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to head Created 7 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/message_loop.h"
6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/system_monitor/removable_storage_notifications.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace chrome {
12
13 class MockStorageObserver
14 : public RemovableStorageNotifications::RemovableStorageObserver {
15 public:
16 MockStorageObserver() {}
17 ~MockStorageObserver() {}
18
19 MOCK_METHOD3(OnRemovableStorageAttached,
20 void(const std::string& id,
21 const string16& name,
22 const FilePath::StringType& location));
23 MOCK_METHOD1(OnRemovableStorageDetached, void(const std::string& id));
24 };
25
26 class TestStorageNotifications : public RemovableStorageNotifications {
27 public:
28 TestStorageNotifications() : RemovableStorageNotifications() {}
29 ~TestStorageNotifications() {}
30
31 virtual bool GetDeviceInfoForPath(
32 const FilePath& path,
33 RemovableStorageInfo* device_info) const OVERRIDE {
34 return false;
35 }
36 virtual uint64 GetStorageSize(const std::string& location) const OVERRIDE {
37 return 0;
38 }
39 };
40
41 TEST(RemovableStorageNotificationsTest, DeviceAttachDetachNotifications) {
42 MessageLoop message_loop;
43 const int kObservers = 5;
44 const string16 kDeviceName = ASCIIToUTF16("media device");
45 const std::string kDeviceId1 = "1";
46 const std::string kDeviceId2 = "2";
47 testing::Sequence mock_sequencer[kObservers];
48 MockStorageObserver observers[kObservers];
49 TestStorageNotifications notifications;
50 for (int index = 0; index < kObservers; ++index) {
51 notifications.AddRemovableStorageObserver(&observers[index]);
52
53 EXPECT_CALL(observers[index], OnRemovableStorageAttached(kDeviceId1,
54 kDeviceName,
55 testing::_))
56 .InSequence(mock_sequencer[index]);
57 EXPECT_CALL(observers[index], OnRemovableStorageDetached(kDeviceId1))
58 .InSequence(mock_sequencer[index]);
59 EXPECT_CALL(observers[index], OnRemovableStorageDetached(kDeviceId2))
60 .Times(0).InSequence(mock_sequencer[index]);
61 }
62
63 notifications.ProcessRemovableStorageAttached(kDeviceId1,
64 kDeviceName,
65 FILE_PATH_LITERAL("path"));
66 message_loop.RunUntilIdle();
67
68 notifications.ProcessRemovableStorageDetached(kDeviceId1);
69 notifications.ProcessRemovableStorageDetached(kDeviceId2);
70 message_loop.RunUntilIdle();
71 }
72
73 TEST(RemovableStorageNotificationsTest, GetAttachedRemovableStorageEmpty) {
74 TestStorageNotifications notifications;
75 std::vector<RemovableStorageNotifications::RemovableStorageInfo> devices =
76 notifications.GetAttachedRemovableStorage();
77 EXPECT_EQ(0U, devices.size());
78 }
79
80 TEST(RemovableStorageNotificationsTest,
81 GetAttachedRemovableStorageAttachDetach) {
82 MessageLoop message_loop;
83 TestStorageNotifications notifications;
84 const std::string kDeviceId1 = "42";
85 const string16 kDeviceName1 = ASCIIToUTF16("test");
86 const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo"));
87 notifications.ProcessRemovableStorageAttached(kDeviceId1,
88 kDeviceName1,
89 kDevicePath1.value());
90 message_loop.RunUntilIdle();
91 std::vector<RemovableStorageNotifications::RemovableStorageInfo> devices =
92 notifications.GetAttachedRemovableStorage();
93 ASSERT_EQ(1U, devices.size());
94 EXPECT_EQ(kDeviceId1, devices[0].device_id);
95 EXPECT_EQ(kDeviceName1, devices[0].name);
96 EXPECT_EQ(kDevicePath1.value(), devices[0].location);
97
98 const std::string kDeviceId2 = "44";
99 const string16 kDeviceName2 = ASCIIToUTF16("test2");
100 const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar"));
101 notifications.ProcessRemovableStorageAttached(kDeviceId2,
102 kDeviceName2,
103 kDevicePath2.value());
104 message_loop.RunUntilIdle();
105 devices = notifications.GetAttachedRemovableStorage();
106 ASSERT_EQ(2U, devices.size());
107 EXPECT_EQ(kDeviceId1, devices[0].device_id);
108 EXPECT_EQ(kDeviceName1, devices[0].name);
109 EXPECT_EQ(kDevicePath1.value(), devices[0].location);
110 EXPECT_EQ(kDeviceId2, devices[1].device_id);
111 EXPECT_EQ(kDeviceName2, devices[1].name);
112 EXPECT_EQ(kDevicePath2.value(), devices[1].location);
113
114 notifications.ProcessRemovableStorageDetached(kDeviceId1);
115 message_loop.RunUntilIdle();
116 devices = notifications.GetAttachedRemovableStorage();
117 ASSERT_EQ(1U, devices.size());
118 EXPECT_EQ(kDeviceId2, devices[0].device_id);
119 EXPECT_EQ(kDeviceName2, devices[0].name);
120 EXPECT_EQ(kDevicePath2.value(), devices[0].location);
121
122 notifications.ProcessRemovableStorageDetached(kDeviceId2);
123 message_loop.RunUntilIdle();
124 devices = notifications.GetAttachedRemovableStorage();
125 EXPECT_EQ(0U, devices.size());
126 }
127
128 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698