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

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: address nits 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"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "content/child/child_process.h" 14 #include "content/child/child_process.h"
15 #include "content/common/video_capture.mojom.h" 15 #include "content/common/video_capture.mojom.h"
16 #include "content/renderer/media/video_capture_impl.h" 16 #include "content/renderer/media/video_capture_impl.h"
17 #include "content/renderer/media/video_capture_impl_manager.h" 17 #include "content/renderer/media/video_capture_impl_manager.h"
18 #include "media/base/bind_to_current_loop.h" 18 #include "media/base/bind_to_current_loop.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 using ::testing::_; 22 using ::testing::_;
23 using ::testing::DoAll; 23 using ::testing::DoAll;
24 using ::testing::InSequence;
24 using ::testing::SaveArg; 25 using ::testing::SaveArg;
25 using media::BindToCurrentLoop; 26 using media::BindToCurrentLoop;
26 27
27 namespace content { 28 namespace content {
28 29
29 ACTION_P(RunClosure, closure) { 30 ACTION_P(RunClosure, closure) {
30 closure.Run(); 31 closure.Run();
31 } 32 }
32 33
33 namespace { 34 namespace {
(...skipping 22 matching lines...) Expand all
56 57
57 ~MockVideoCaptureImpl() override { destruct_callback_.Run(); } 58 ~MockVideoCaptureImpl() override { destruct_callback_.Run(); }
58 59
59 private: 60 private:
60 void Start(int32_t device_id, 61 void Start(int32_t device_id,
61 int32_t session_id, 62 int32_t session_id,
62 const media::VideoCaptureParams& params, 63 const media::VideoCaptureParams& params,
63 mojom::VideoCaptureObserverPtr observer) override { 64 mojom::VideoCaptureObserverPtr observer) override {
64 // For every Start(), expect a corresponding Stop() call. 65 // For every Start(), expect a corresponding Stop() call.
65 EXPECT_CALL(*this, Stop(_)); 66 EXPECT_CALL(*this, Stop(_));
67 // Simulate device started.
68 OnStateChanged(mojom::VideoCaptureState::STARTED);
66 } 69 }
67 70
68 MOCK_METHOD1(Stop, void(int32_t)); 71 MOCK_METHOD1(Stop, void(int32_t));
69 72
70 void Pause(int device_id) { pause_callback_->OnPaused(session_id()); } 73 void Pause(int device_id) { pause_callback_->OnPaused(session_id()); }
71 74
72 void Resume(int32_t device_id, 75 void Resume(int32_t device_id,
73 int32_t session_id, 76 int32_t session_id,
74 const media::VideoCaptureParams& params) override { 77 const media::VideoCaptureParams& params) override {
75 pause_callback_->OnResumed(session_id); 78 pause_callback_->OnResumed(session_id);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 this, 127 this,
125 BindToCurrentLoop(cleanup_run_loop_.QuitClosure()))) {} 128 BindToCurrentLoop(cleanup_run_loop_.QuitClosure()))) {}
126 129
127 protected: 130 protected:
128 static constexpr size_t kNumClients = 3; 131 static constexpr size_t kNumClients = 3;
129 132
130 std::array<base::Closure, kNumClients> StartCaptureForAllClients( 133 std::array<base::Closure, kNumClients> StartCaptureForAllClients(
131 bool same_session_id) { 134 bool same_session_id) {
132 base::RunLoop run_loop; 135 base::RunLoop run_loop;
133 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); 136 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure());
134 EXPECT_CALL(*this, OnStarted(_)).Times(kNumClients - 1) 137
135 .RetiresOnSaturation(); 138 InSequence s;
139 if (!same_session_id) {
140 // |OnStarted| will only be received once from each device if there are
141 // multiple request to the same device.
142 EXPECT_CALL(*this, OnStarted(_))
143 .Times(kNumClients - 1)
144 .RetiresOnSaturation();
145 }
136 EXPECT_CALL(*this, OnStarted(_)).WillOnce(RunClosure(quit_closure)) 146 EXPECT_CALL(*this, OnStarted(_)).WillOnce(RunClosure(quit_closure))
137 .RetiresOnSaturation(); 147 .RetiresOnSaturation();
138 std::array<base::Closure, kNumClients> stop_callbacks; 148 std::array<base::Closure, kNumClients> stop_callbacks;
139 media::VideoCaptureParams params; 149 media::VideoCaptureParams params;
140 params.requested_format = media::VideoCaptureFormat( 150 params.requested_format = media::VideoCaptureFormat(
141 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); 151 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420);
142 for (size_t i = 0; i < kNumClients; ++i) { 152 for (size_t i = 0; i < kNumClients; ++i) {
143 stop_callbacks[i] = StartCapture( 153 stop_callbacks[i] = StartCapture(
144 same_session_id ? 0 : static_cast<media::VideoCaptureSessionId>(i), 154 same_session_id ? 0 : static_cast<media::VideoCaptureSessionId>(i),
145 params); 155 params);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 run_loop.Run(); 302 run_loop.Run();
293 } 303 }
294 304
295 StopCaptureForAllClients(&stop_callbacks); 305 StopCaptureForAllClients(&stop_callbacks);
296 for (const auto& release_callback : release_callbacks) 306 for (const auto& release_callback : release_callbacks)
297 release_callback.Run(); 307 release_callback.Run();
298 cleanup_run_loop_.Run(); 308 cleanup_run_loop_.Run();
299 } 309 }
300 310
301 } // namespace content 311 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.cc ('k') | content/renderer/media/video_capture_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698