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

Side by Side Diff: content/browser/renderer_host/media/video_capture_manager_unittest.cc

Issue 248113003: Fix for closing the desktop sharing notification bar when the shared window is closed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments and add a test Created 6 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Unit test for VideoCaptureManager. 5 // Unit test for VideoCaptureManager.
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 21 matching lines...) Expand all
32 // Listener class used to track progress of VideoCaptureManager test. 32 // Listener class used to track progress of VideoCaptureManager test.
33 class MockMediaStreamProviderListener : public MediaStreamProviderListener { 33 class MockMediaStreamProviderListener : public MediaStreamProviderListener {
34 public: 34 public:
35 MockMediaStreamProviderListener() {} 35 MockMediaStreamProviderListener() {}
36 ~MockMediaStreamProviderListener() {} 36 ~MockMediaStreamProviderListener() {}
37 37
38 MOCK_METHOD2(Opened, void(MediaStreamType, int)); 38 MOCK_METHOD2(Opened, void(MediaStreamType, int));
39 MOCK_METHOD2(Closed, void(MediaStreamType, int)); 39 MOCK_METHOD2(Closed, void(MediaStreamType, int));
40 MOCK_METHOD2(DevicesEnumerated, void(MediaStreamType, 40 MOCK_METHOD2(DevicesEnumerated, void(MediaStreamType,
41 const StreamDeviceInfoArray&)); 41 const StreamDeviceInfoArray&));
42 MOCK_METHOD3(Error, void(MediaStreamType, int, 42 MOCK_METHOD2(Aborted, void(MediaStreamType, int));
43 MediaStreamProviderError));
44 }; // class MockMediaStreamProviderListener 43 }; // class MockMediaStreamProviderListener
45 44
46 // Needed as an input argument to StartCaptureForClient(). 45 // Needed as an input argument to StartCaptureForClient().
47 class MockFrameObserver : public VideoCaptureControllerEventHandler { 46 class MockFrameObserver : public VideoCaptureControllerEventHandler {
48 public: 47 public:
49 MOCK_METHOD1(OnError, void(const VideoCaptureControllerID& id)); 48 MOCK_METHOD1(OnError, void(const VideoCaptureControllerID& id));
50 49
51 virtual void OnBufferCreated(const VideoCaptureControllerID& id, 50 virtual void OnBufferCreated(const VideoCaptureControllerID& id,
52 base::SharedMemoryHandle handle, 51 base::SharedMemoryHandle handle,
53 int length, int buffer_id) OVERRIDE {} 52 int length, int buffer_id) OVERRIDE {}
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 client_id, 119 client_id,
121 run_loop.QuitClosure(), 120 run_loop.QuitClosure(),
122 expect_success)); 121 expect_success));
123 run_loop.Run(); 122 run_loop.Run();
124 return client_id; 123 return client_id;
125 } 124 }
126 125
127 void StopClient(VideoCaptureControllerID client_id) { 126 void StopClient(VideoCaptureControllerID client_id) {
128 ASSERT_TRUE(1 == controllers_.count(client_id)); 127 ASSERT_TRUE(1 == controllers_.count(client_id));
129 vcm_->StopCaptureForClient(controllers_[client_id], client_id, 128 vcm_->StopCaptureForClient(controllers_[client_id], client_id,
130 frame_observer_.get()); 129 frame_observer_.get(), false);
131 controllers_.erase(client_id); 130 controllers_.erase(client_id);
132 } 131 }
133 132
134 int next_client_id_; 133 int next_client_id_;
135 std::map<VideoCaptureControllerID, VideoCaptureController*> controllers_; 134 std::map<VideoCaptureControllerID, VideoCaptureController*> controllers_;
136 scoped_refptr<VideoCaptureManager> vcm_; 135 scoped_refptr<VideoCaptureManager> vcm_;
137 scoped_ptr<MockMediaStreamProviderListener> listener_; 136 scoped_ptr<MockMediaStreamProviderListener> listener_;
138 scoped_ptr<base::MessageLoop> message_loop_; 137 scoped_ptr<base::MessageLoop> message_loop_;
139 scoped_ptr<BrowserThreadImpl> io_thread_; 138 scoped_ptr<BrowserThreadImpl> io_thread_;
140 scoped_ptr<MockFrameObserver> frame_observer_; 139 scoped_ptr<MockFrameObserver> frame_observer_;
(...skipping 23 matching lines...) Expand all
164 VideoCaptureControllerID client_id = StartClient(video_session_id, true); 163 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
165 164
166 StopClient(client_id); 165 StopClient(client_id);
167 vcm_->Close(video_session_id); 166 vcm_->Close(video_session_id);
168 167
169 // Wait to check callbacks before removing the listener. 168 // Wait to check callbacks before removing the listener.
170 message_loop_->RunUntilIdle(); 169 message_loop_->RunUntilIdle();
171 vcm_->Unregister(); 170 vcm_->Unregister();
172 } 171 }
173 172
173 // Try to open, start, and abort a device.
174 TEST_F(VideoCaptureManagerTest, CreateAndAbort) {
175 StreamDeviceInfoArray devices;
176
177 InSequence s;
178 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
179 .WillOnce(SaveArg<1>(&devices));
180 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _));
181 EXPECT_CALL(*listener_, Aborted(MEDIA_DEVICE_VIDEO_CAPTURE, _));
182
183 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE);
184
185 // Wait to get device callback.
186 message_loop_->RunUntilIdle();
187
188 int video_session_id = vcm_->Open(devices.front());
189 VideoCaptureControllerID client_id = StartClient(video_session_id, true);
190
191 // Wait for device opened.
192 message_loop_->RunUntilIdle();
193
194 vcm_->StopCaptureForClient(controllers_[client_id], client_id,
195 frame_observer_.get(), true);
196
197 // Wait to check callbacks before removing the listener.
198 message_loop_->RunUntilIdle();
199 vcm_->Unregister();
200 }
201
174 // Open the same device twice. 202 // Open the same device twice.
175 TEST_F(VideoCaptureManagerTest, OpenTwice) { 203 TEST_F(VideoCaptureManagerTest, OpenTwice) {
176 StreamDeviceInfoArray devices; 204 StreamDeviceInfoArray devices;
177 205
178 InSequence s; 206 InSequence s;
179 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) 207 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _))
180 .WillOnce(SaveArg<1>(&devices)); 208 .WillOnce(SaveArg<1>(&devices));
181 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 209 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
182 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); 210 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2);
183 211
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 477
450 // Wait to check callbacks before removing the listener 478 // Wait to check callbacks before removing the listener
451 message_loop_->RunUntilIdle(); 479 message_loop_->RunUntilIdle();
452 vcm_->Unregister(); 480 vcm_->Unregister();
453 } 481 }
454 482
455 // TODO(mcasas): Add a test to check consolidation of the supported formats 483 // TODO(mcasas): Add a test to check consolidation of the supported formats
456 // provided by the device when http://crbug.com/323913 is closed. 484 // provided by the device when http://crbug.com/323913 is closed.
457 485
458 } // namespace content 486 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698