| Index: chrome/browser/system_monitor/removable_storage_notifications_unittest.cc
|
| diff --git a/chrome/browser/system_monitor/removable_storage_notifications_unittest.cc b/chrome/browser/system_monitor/removable_storage_notifications_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..393ce13eb041c908f35c9e1b09dea0d678d99337
|
| --- /dev/null
|
| +++ b/chrome/browser/system_monitor/removable_storage_notifications_unittest.cc
|
| @@ -0,0 +1,128 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/message_loop.h"
|
| +#include "base/utf_string_conversions.h"
|
| +#include "chrome/browser/system_monitor/removable_storage_notifications.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace chrome {
|
| +
|
| +class MockStorageObserver
|
| + : public RemovableStorageNotifications::RemovableStorageObserver {
|
| + public:
|
| + MockStorageObserver() {}
|
| + ~MockStorageObserver() {}
|
| +
|
| + MOCK_METHOD3(OnRemovableStorageAttached,
|
| + void(const std::string& id,
|
| + const string16& name,
|
| + const FilePath::StringType& location));
|
| + MOCK_METHOD1(OnRemovableStorageDetached, void(const std::string& id));
|
| +};
|
| +
|
| +class TestStorageNotifications : public RemovableStorageNotifications {
|
| + public:
|
| + TestStorageNotifications() : RemovableStorageNotifications() {}
|
| + ~TestStorageNotifications() {}
|
| +
|
| + virtual bool GetDeviceInfoForPath(
|
| + const FilePath& path,
|
| + RemovableStorageInfo* device_info) const OVERRIDE {
|
| + return false;
|
| + }
|
| + virtual uint64 GetStorageSize(const std::string& location) const OVERRIDE {
|
| + return 0;
|
| + }
|
| +};
|
| +
|
| +TEST(RemovableStorageNotificationsTest, DeviceAttachDetachNotifications) {
|
| + MessageLoop message_loop;
|
| + const int kObservers = 5;
|
| + const string16 kDeviceName = ASCIIToUTF16("media device");
|
| + const std::string kDeviceId1 = "1";
|
| + const std::string kDeviceId2 = "2";
|
| + testing::Sequence mock_sequencer[kObservers];
|
| + MockStorageObserver observers[kObservers];
|
| + TestStorageNotifications notifications;
|
| + for (int index = 0; index < kObservers; ++index) {
|
| + notifications.AddRemovableStorageObserver(&observers[index]);
|
| +
|
| + EXPECT_CALL(observers[index], OnRemovableStorageAttached(kDeviceId1,
|
| + kDeviceName,
|
| + testing::_))
|
| + .InSequence(mock_sequencer[index]);
|
| + EXPECT_CALL(observers[index], OnRemovableStorageDetached(kDeviceId1))
|
| + .InSequence(mock_sequencer[index]);
|
| + EXPECT_CALL(observers[index], OnRemovableStorageDetached(kDeviceId2))
|
| + .Times(0).InSequence(mock_sequencer[index]);
|
| + }
|
| +
|
| + notifications.ProcessRemovableStorageAttached(kDeviceId1,
|
| + kDeviceName,
|
| + FILE_PATH_LITERAL("path"));
|
| + message_loop.RunUntilIdle();
|
| +
|
| + notifications.ProcessRemovableStorageDetached(kDeviceId1);
|
| + notifications.ProcessRemovableStorageDetached(kDeviceId2);
|
| + message_loop.RunUntilIdle();
|
| +}
|
| +
|
| +TEST(RemovableStorageNotificationsTest, GetAttachedRemovableStorageEmpty) {
|
| + TestStorageNotifications notifications;
|
| + std::vector<RemovableStorageNotifications::RemovableStorageInfo> devices =
|
| + notifications.GetAttachedRemovableStorage();
|
| + EXPECT_EQ(0U, devices.size());
|
| +}
|
| +
|
| +TEST(RemovableStorageNotificationsTest,
|
| + GetAttachedRemovableStorageAttachDetach) {
|
| + MessageLoop message_loop;
|
| + TestStorageNotifications notifications;
|
| + const std::string kDeviceId1 = "42";
|
| + const string16 kDeviceName1 = ASCIIToUTF16("test");
|
| + const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo"));
|
| + notifications.ProcessRemovableStorageAttached(kDeviceId1,
|
| + kDeviceName1,
|
| + kDevicePath1.value());
|
| + message_loop.RunUntilIdle();
|
| + std::vector<RemovableStorageNotifications::RemovableStorageInfo> devices =
|
| + notifications.GetAttachedRemovableStorage();
|
| + ASSERT_EQ(1U, devices.size());
|
| + EXPECT_EQ(kDeviceId1, devices[0].device_id);
|
| + EXPECT_EQ(kDeviceName1, devices[0].name);
|
| + EXPECT_EQ(kDevicePath1.value(), devices[0].location);
|
| +
|
| + const std::string kDeviceId2 = "44";
|
| + const string16 kDeviceName2 = ASCIIToUTF16("test2");
|
| + const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar"));
|
| + notifications.ProcessRemovableStorageAttached(kDeviceId2,
|
| + kDeviceName2,
|
| + kDevicePath2.value());
|
| + message_loop.RunUntilIdle();
|
| + devices = notifications.GetAttachedRemovableStorage();
|
| + ASSERT_EQ(2U, devices.size());
|
| + EXPECT_EQ(kDeviceId1, devices[0].device_id);
|
| + EXPECT_EQ(kDeviceName1, devices[0].name);
|
| + EXPECT_EQ(kDevicePath1.value(), devices[0].location);
|
| + EXPECT_EQ(kDeviceId2, devices[1].device_id);
|
| + EXPECT_EQ(kDeviceName2, devices[1].name);
|
| + EXPECT_EQ(kDevicePath2.value(), devices[1].location);
|
| +
|
| + notifications.ProcessRemovableStorageDetached(kDeviceId1);
|
| + message_loop.RunUntilIdle();
|
| + devices = notifications.GetAttachedRemovableStorage();
|
| + ASSERT_EQ(1U, devices.size());
|
| + EXPECT_EQ(kDeviceId2, devices[0].device_id);
|
| + EXPECT_EQ(kDeviceName2, devices[0].name);
|
| + EXPECT_EQ(kDevicePath2.value(), devices[0].location);
|
| +
|
| + notifications.ProcessRemovableStorageDetached(kDeviceId2);
|
| + message_loop.RunUntilIdle();
|
| + devices = notifications.GetAttachedRemovableStorage();
|
| + EXPECT_EQ(0U, devices.size());
|
| +}
|
| +
|
| +} // namespace chrome
|
|
|