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

Side by Side Diff: chrome/browser/system_monitor/chromeos/media_transfer_protocol_device_observer_unittest.cc

Issue 10894045: ChromeOS: Implement MediaTransferProtocolManager observer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 3 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 // MediaTransferProtocolDeviceObserver unit tests.
6
7 #include "chrome/browser/system_monitor/chromeos/media_transfer_protocol_device_ observer.h"
8
9 #include <string>
10
11 #include "base/message_loop.h"
Lei Zhang 2012/09/10 18:18:01 nit: alphabetical order
kmadhusu 2012/09/11 01:50:19 Done.
12 #include "base/memory/scoped_ptr.h"
13 #include "base/system_monitor/system_monitor.h"
14 #include "base/test/mock_devices_changed_observer.h"
15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/media_gallery/media_storage_util.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace chromeos {
20 namespace mtp {
21
22 namespace {
23
24 // Sample mtp device storage information.
25 const char kStorageLabel[] = "Camera V1.0";
26 const char kStorageLocation[] = "/usb:2,2,88888";
27 const char kStorageName[] = "usb:2,2,88888";
28 const char kStorageUniqueId[] = "VendorModelSerial:COM:MOD2012:283";
29
30 // Returns the mtp device id given the |unique_id|.
31 std::string GetMtpDeviceId(const std::string& unique_id) {
32 return chrome::MediaStorageUtil::MakeDeviceId(
33 chrome::MediaStorageUtil::MTP_OR_PTP, unique_id);
34 }
35
36 // Helper function to get the device storage details such as device id, label
37 // and location. On success, fills in |id|, |label| and |location|.
38 void GetStorageInfo(const std::string& storage_name,
39 std::string* id,
40 string16* label,
41 std::string* location) {
42 if (storage_name != kStorageName) {
43 NOTREACHED();
44 return;
45 }
46 if (id)
47 *id = GetMtpDeviceId(kStorageUniqueId);
48 if (label)
49 *label = ASCIIToUTF16(kStorageLabel);
50 if (location)
51 *location = kStorageLocation;
52 }
53
54 } // namespace
55
56 class MediaTransferProtocolDeviceObserverTest : public testing::Test {
57 public:
58 MediaTransferProtocolDeviceObserverTest() {}
59 virtual ~MediaTransferProtocolDeviceObserverTest() {}
60
61 protected:
62 virtual void SetUp() OVERRIDE {
63 mock_devices_changed_observer_.reset(new base::MockDevicesChangedObserver);
64 system_monitor_.AddDevicesChangedObserver(
65 mock_devices_changed_observer_.get());
66
67 // Initialize the test subject.
68 mtp_dev_observer_.reset(
69 new MediaTransferProtocolDeviceObserver(&GetStorageInfo));
70 }
71
72 virtual void TearDown() OVERRIDE {
73 mtp_dev_observer_.reset();
74 system_monitor_.RemoveDevicesChangedObserver(
75 mock_devices_changed_observer_.get());
76 }
77
78 // Returns the device changed observer object.
79 base::MockDevicesChangedObserver& observer() {
80 return *mock_devices_changed_observer_;
81 }
82
83 // Notifies |MediaTransferProtocolDeviceObserver| about the attachment of
84 // mtp storage device given the |storage_name|.
85 void MtpStorageAttached(const std::string& storage_name) {
86 mtp_dev_observer_->StorageChanged(true, storage_name);
87 ui_loop_.RunAllPending();
88 }
89
90 // Notifies |MediaTransferProtocolDeviceObserver| about the detachment of
91 // mtp storage device given the |storage_name|.
92 void MtpStorageDetached(const std::string& storage_name) {
93 mtp_dev_observer_->StorageChanged(false, storage_name);
94 ui_loop_.RunAllPending();
95 }
96
97 private:
98 // Message loop to run the test on.
99 MessageLoop ui_loop_;
100
101 // SystemMonitor and DevicesChangedObserver to hook together to test.
102 base::SystemMonitor system_monitor_;
103 scoped_ptr<base::MockDevicesChangedObserver> mock_devices_changed_observer_;
104
105 // Test subject.
106 scoped_ptr<MediaTransferProtocolDeviceObserver> mtp_dev_observer_;
107
108 DISALLOW_COPY_AND_ASSIGN(MediaTransferProtocolDeviceObserverTest);
109 };
110
111 // Test to verify basic mtp storage attach and detach notifications.
112 TEST_F(MediaTransferProtocolDeviceObserverTest, BasicAttachDetach) {
113 testing::Sequence mock_sequence;
114 std::string device_id = GetMtpDeviceId(kStorageUniqueId);
115
116 EXPECT_CALL(observer(),
117 OnRemovableStorageAttached(device_id,
118 ASCIIToUTF16(kStorageLabel),
119 kStorageLocation))
120 .InSequence(mock_sequence);
121
122 // Attach a mtp storage.
123 MtpStorageAttached(kStorageName);
124
125 EXPECT_CALL(observer(), OnRemovableStorageDetached(device_id))
126 .InSequence(mock_sequence);
127
128 // Detach the attached storage.
129 MtpStorageDetached(kStorageName);
130 }
131
132 } // namespace mtp
133 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698