OLD | NEW |
(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/file_path.h" |
| 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" |
| 8 #include "base/system_monitor/system_monitor.h" |
| 9 #include "chrome/browser/media_gallery/media_device_manager.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace chrome { |
| 13 |
| 14 namespace { |
| 15 |
| 16 using base::SystemMonitor; |
| 17 |
| 18 class MediaDeviceManagerTest : public testing::Test { |
| 19 public: |
| 20 MediaDeviceManagerTest() {} |
| 21 virtual ~MediaDeviceManagerTest() {} |
| 22 |
| 23 virtual void SetUp() OVERRIDE { |
| 24 #if defined(OS_MACOSX) |
| 25 SystemMonitor::AllocateSystemIOPorts(); |
| 26 #endif |
| 27 |
| 28 system_monitor_.reset(new SystemMonitor()); |
| 29 device_manager_.reset(new MediaDeviceManager()); |
| 30 } |
| 31 |
| 32 protected: |
| 33 MessageLoop message_loop_; |
| 34 scoped_ptr<SystemMonitor> system_monitor_; |
| 35 scoped_ptr<MediaDeviceManager> device_manager_; |
| 36 }; |
| 37 |
| 38 TEST_F(MediaDeviceManagerTest, Empty) { |
| 39 std::vector<MediaDeviceManager::MediaDeviceInfo> devices; |
| 40 device_manager_->GetDevices(&devices); |
| 41 EXPECT_EQ(0U, devices.size()); |
| 42 } |
| 43 |
| 44 TEST_F(MediaDeviceManagerTest, AttachDetach) { |
| 45 const SystemMonitor::DeviceIdType kDeviceId1 = 42; |
| 46 const char kDeviceName1[] = "test"; |
| 47 const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo")); |
| 48 system_monitor_->ProcessMediaDeviceAttached(kDeviceId1, |
| 49 kDeviceName1, |
| 50 kDevicePath1); |
| 51 message_loop_.RunAllPending(); |
| 52 std::vector<MediaDeviceManager::MediaDeviceInfo> devices; |
| 53 device_manager_->GetDevices(&devices); |
| 54 ASSERT_EQ(1U, devices.size()); |
| 55 EXPECT_EQ(kDeviceName1, devices[0].first); |
| 56 EXPECT_EQ(kDevicePath1, devices[0].second); |
| 57 |
| 58 const SystemMonitor::DeviceIdType kDeviceId2 = 44; |
| 59 const char kDeviceName2[] = "test2"; |
| 60 const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar")); |
| 61 system_monitor_->ProcessMediaDeviceAttached(kDeviceId2, |
| 62 kDeviceName2, |
| 63 kDevicePath2); |
| 64 message_loop_.RunAllPending(); |
| 65 devices.clear(); |
| 66 device_manager_->GetDevices(&devices); |
| 67 ASSERT_EQ(2U, devices.size()); |
| 68 EXPECT_EQ(kDeviceName1, devices[0].first); |
| 69 EXPECT_EQ(kDevicePath1, devices[0].second); |
| 70 EXPECT_EQ(kDeviceName2, devices[1].first); |
| 71 EXPECT_EQ(kDevicePath2, devices[1].second); |
| 72 |
| 73 system_monitor_->ProcessMediaDeviceDetached(kDeviceId1); |
| 74 message_loop_.RunAllPending(); |
| 75 devices.clear(); |
| 76 device_manager_->GetDevices(&devices); |
| 77 ASSERT_EQ(1U, devices.size()); |
| 78 EXPECT_EQ(kDeviceName2, devices[1].first); |
| 79 EXPECT_EQ(kDevicePath2, devices[1].second); |
| 80 |
| 81 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); |
| 82 message_loop_.RunAllPending(); |
| 83 devices.clear(); |
| 84 device_manager_->GetDevices(&devices); |
| 85 EXPECT_EQ(0U, devices.size()); |
| 86 } |
| 87 |
| 88 } // namespace |
| 89 |
| 90 } // namespace chrome |
OLD | NEW |