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

Side by Side Diff: content/renderer/media/video_capture_impl_manager_unittest.cc

Issue 2721113002: getUserMedia: handle the device starting status report. (Closed)
Patch Set: Created 3 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include <array> 5 #include <array>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 ~MockVideoCaptureImpl() override { destruct_callback_.Run(); } 57 ~MockVideoCaptureImpl() override { destruct_callback_.Run(); }
58 58
59 private: 59 private:
60 void Start(int32_t device_id, 60 void Start(int32_t device_id,
61 int32_t session_id, 61 int32_t session_id,
62 const media::VideoCaptureParams& params, 62 const media::VideoCaptureParams& params,
63 mojom::VideoCaptureObserverPtr observer) override { 63 mojom::VideoCaptureObserverPtr observer) override {
64 // For every Start(), expect a corresponding Stop() call. 64 // For every Start(), expect a corresponding Stop() call.
65 EXPECT_CALL(*this, Stop(_)); 65 EXPECT_CALL(*this, Stop(_));
66 // Simulate device started.
67 OnStateChanged(mojom::VideoCaptureState::STARTED);
66 } 68 }
67 69
68 MOCK_METHOD1(Stop, void(int32_t)); 70 MOCK_METHOD1(Stop, void(int32_t));
69 71
70 void Pause(int device_id) { pause_callback_->OnPaused(session_id()); } 72 void Pause(int device_id) { pause_callback_->OnPaused(session_id()); }
71 73
72 void Resume(int32_t device_id, 74 void Resume(int32_t device_id,
73 int32_t session_id, 75 int32_t session_id,
74 const media::VideoCaptureParams& params) override { 76 const media::VideoCaptureParams& params) override {
75 pause_callback_->OnResumed(session_id); 77 pause_callback_->OnResumed(session_id);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 this, 126 this,
125 BindToCurrentLoop(cleanup_run_loop_.QuitClosure()))) {} 127 BindToCurrentLoop(cleanup_run_loop_.QuitClosure()))) {}
126 128
127 protected: 129 protected:
128 static constexpr size_t kNumClients = 3; 130 static constexpr size_t kNumClients = 3;
129 131
130 std::array<base::Closure, kNumClients> StartCaptureForAllClients( 132 std::array<base::Closure, kNumClients> StartCaptureForAllClients(
131 bool same_session_id) { 133 bool same_session_id) {
132 base::RunLoop run_loop; 134 base::RunLoop run_loop;
133 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); 135 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure());
134 EXPECT_CALL(*this, OnStarted(_)).Times(kNumClients - 1) 136 if (!same_session_id) {
135 .RetiresOnSaturation(); 137 // |OnStarted| will only be received once from each device if there are
138 // multiple request to the same device.
139 EXPECT_CALL(*this, OnStarted(_))
140 .Times(kNumClients - 1)
141 .RetiresOnSaturation();
142 }
136 EXPECT_CALL(*this, OnStarted(_)).WillOnce(RunClosure(quit_closure)) 143 EXPECT_CALL(*this, OnStarted(_)).WillOnce(RunClosure(quit_closure))
137 .RetiresOnSaturation(); 144 .RetiresOnSaturation();
chfremer 2017/03/02 17:56:10 If this worked before, it will probably still work
braveyao 2017/03/03 17:53:12 Done.
138 std::array<base::Closure, kNumClients> stop_callbacks; 145 std::array<base::Closure, kNumClients> stop_callbacks;
139 media::VideoCaptureParams params; 146 media::VideoCaptureParams params;
140 params.requested_format = media::VideoCaptureFormat( 147 params.requested_format = media::VideoCaptureFormat(
141 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); 148 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420);
142 for (size_t i = 0; i < kNumClients; ++i) { 149 for (size_t i = 0; i < kNumClients; ++i) {
143 stop_callbacks[i] = StartCapture( 150 stop_callbacks[i] = StartCapture(
144 same_session_id ? 0 : static_cast<media::VideoCaptureSessionId>(i), 151 same_session_id ? 0 : static_cast<media::VideoCaptureSessionId>(i),
145 params); 152 params);
146 } 153 }
147 run_loop.Run(); 154 run_loop.Run();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 run_loop.Run(); 299 run_loop.Run();
293 } 300 }
294 301
295 StopCaptureForAllClients(&stop_callbacks); 302 StopCaptureForAllClients(&stop_callbacks);
296 for (const auto& release_callback : release_callbacks) 303 for (const auto& release_callback : release_callbacks)
297 release_callback.Run(); 304 release_callback.Run();
298 cleanup_run_loop_.Run(); 305 cleanup_run_loop_.Run();
299 } 306 }
300 307
301 } // namespace content 308 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698