| Index: chrome/browser/media_gallery/media_device_manager_unittest.cc
 | 
| ===================================================================
 | 
| --- chrome/browser/media_gallery/media_device_manager_unittest.cc	(revision 0)
 | 
| +++ chrome/browser/media_gallery/media_device_manager_unittest.cc	(revision 0)
 | 
| @@ -0,0 +1,90 @@
 | 
| +// 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/file_path.h"
 | 
| +#include "base/memory/scoped_ptr.h"
 | 
| +#include "base/message_loop.h"
 | 
| +#include "base/system_monitor/system_monitor.h"
 | 
| +#include "chrome/browser/media_gallery/media_device_manager.h"
 | 
| +#include "testing/gtest/include/gtest/gtest.h"
 | 
| +
 | 
| +namespace chrome {
 | 
| +
 | 
| +namespace {
 | 
| +
 | 
| +using base::SystemMonitor;
 | 
| +
 | 
| +class MediaDeviceManagerTest : public testing::Test {
 | 
| + public:
 | 
| +  MediaDeviceManagerTest() {}
 | 
| +  virtual ~MediaDeviceManagerTest() {}
 | 
| +
 | 
| +  virtual void SetUp() OVERRIDE {
 | 
| +#if defined(OS_MACOSX)
 | 
| +    SystemMonitor::AllocateSystemIOPorts();
 | 
| +#endif
 | 
| +
 | 
| +    system_monitor_.reset(new SystemMonitor());
 | 
| +    device_manager_.reset(new MediaDeviceManager());
 | 
| +  }
 | 
| +
 | 
| + protected:
 | 
| +  MessageLoop message_loop_;
 | 
| +  scoped_ptr<SystemMonitor> system_monitor_;
 | 
| +  scoped_ptr<MediaDeviceManager> device_manager_;
 | 
| +};
 | 
| +
 | 
| +TEST_F(MediaDeviceManagerTest, Empty) {
 | 
| +  std::vector<MediaDeviceManager::MediaDeviceInfo> devices;
 | 
| +  device_manager_->GetDevices(&devices);
 | 
| +  EXPECT_EQ(0U, devices.size());
 | 
| +}
 | 
| +
 | 
| +TEST_F(MediaDeviceManagerTest, AttachDetach) {
 | 
| +  const SystemMonitor::DeviceIdType kDeviceId1 = 42;
 | 
| +  const char kDeviceName1[] = "test";
 | 
| +  const FilePath kDevicePath1(FILE_PATH_LITERAL("/testfoo"));
 | 
| +  system_monitor_->ProcessMediaDeviceAttached(kDeviceId1,
 | 
| +                                              kDeviceName1,
 | 
| +                                              kDevicePath1);
 | 
| +  message_loop_.RunAllPending();
 | 
| +  std::vector<MediaDeviceManager::MediaDeviceInfo> devices;
 | 
| +  device_manager_->GetDevices(&devices);
 | 
| +  ASSERT_EQ(1U, devices.size());
 | 
| +  EXPECT_EQ(kDeviceName1, devices[0].first);
 | 
| +  EXPECT_EQ(kDevicePath1, devices[0].second);
 | 
| +
 | 
| +  const SystemMonitor::DeviceIdType kDeviceId2 = 44;
 | 
| +  const char kDeviceName2[] = "test2";
 | 
| +  const FilePath kDevicePath2(FILE_PATH_LITERAL("/testbar"));
 | 
| +  system_monitor_->ProcessMediaDeviceAttached(kDeviceId2,
 | 
| +                                              kDeviceName2,
 | 
| +                                              kDevicePath2);
 | 
| +  message_loop_.RunAllPending();
 | 
| +  devices.clear();
 | 
| +  device_manager_->GetDevices(&devices);
 | 
| +  ASSERT_EQ(2U, devices.size());
 | 
| +  EXPECT_EQ(kDeviceName1, devices[0].first);
 | 
| +  EXPECT_EQ(kDevicePath1, devices[0].second);
 | 
| +  EXPECT_EQ(kDeviceName2, devices[1].first);
 | 
| +  EXPECT_EQ(kDevicePath2, devices[1].second);
 | 
| +
 | 
| +  system_monitor_->ProcessMediaDeviceDetached(kDeviceId1);
 | 
| +  message_loop_.RunAllPending();
 | 
| +  devices.clear();
 | 
| +  device_manager_->GetDevices(&devices);
 | 
| +  ASSERT_EQ(1U, devices.size());
 | 
| +  EXPECT_EQ(kDeviceName2, devices[1].first);
 | 
| +  EXPECT_EQ(kDevicePath2, devices[1].second);
 | 
| +
 | 
| +  system_monitor_->ProcessMediaDeviceDetached(kDeviceId2);
 | 
| +  message_loop_.RunAllPending();
 | 
| +  devices.clear();
 | 
| +  device_manager_->GetDevices(&devices);
 | 
| +  EXPECT_EQ(0U, devices.size());
 | 
| +}
 | 
| +
 | 
| +}  // namespace
 | 
| +
 | 
| +}  // namespace chrome
 | 
| 
 | 
| Property changes on: chrome/browser/media_gallery/media_device_manager_unittest.cc
 | 
| ___________________________________________________________________
 | 
| Added: svn:eol-style
 | 
|    + LF
 | 
| 
 | 
| 
 |