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

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

Issue 2582533002: Simplify AudioInputRendererHost IPC interface. (Closed)
Patch Set: Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/renderer_host/media/audio_input_renderer_host.h" 5 #include "content/browser/renderer_host/media/audio_input_renderer_host.h"
6 6
7 #include <utility>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
12 #include "content/browser/bad_message.h" 13 #include "content/browser/bad_message.h"
13 #include "content/browser/media/capture/audio_mirroring_manager.h" 14 #include "content/browser/media/capture/audio_mirroring_manager.h"
14 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 15 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
15 #include "content/browser/renderer_host/media/media_stream_manager.h" 16 #include "content/browser/renderer_host/media/media_stream_manager.h"
16 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 17 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 70 }
70 71
71 class MockRenderer { 72 class MockRenderer {
72 public: 73 public:
73 MOCK_METHOD5(NotifyStreamCreated, 74 MOCK_METHOD5(NotifyStreamCreated,
74 void(int /*stream_id*/, 75 void(int /*stream_id*/,
75 base::SharedMemoryHandle /*handle*/, 76 base::SharedMemoryHandle /*handle*/,
76 base::SyncSocket::TransitDescriptor /*socket_desriptor*/, 77 base::SyncSocket::TransitDescriptor /*socket_desriptor*/,
77 uint32_t /*length*/, 78 uint32_t /*length*/,
78 uint32_t /*total_segments*/)); 79 uint32_t /*total_segments*/));
79 MOCK_METHOD2(NotifyStreamVolume, void(int /*stream_id*/, double /*volume*/)); 80 MOCK_METHOD1(NotifyStreamError, void(int /*stream_id*/));
80 MOCK_METHOD2(NotifyStreamStateChanged,
81 void(int /*stream_id*/,
82 media::AudioInputIPCDelegateState /*state*/));
83 MOCK_METHOD0(WasShutDown, void()); 81 MOCK_METHOD0(WasShutDown, void());
84 }; 82 };
85 83
86 // This class overrides Send to intercept the messages that the 84 // This class overrides Send to intercept the messages that the
87 // AudioInputRendererHost sends to the renderer. They are sent to 85 // AudioInputRendererHost sends to the renderer. They are sent to
88 // the provided MockRenderer instead. 86 // the provided MockRenderer instead.
89 class AudioInputRendererHostWithInterception : public AudioInputRendererHost { 87 class AudioInputRendererHostWithInterception : public AudioInputRendererHost {
90 public: 88 public:
91 AudioInputRendererHostWithInterception( 89 AudioInputRendererHostWithInterception(
92 int render_process_id, 90 int render_process_id,
(...skipping 17 matching lines...) Expand all
110 ~AudioInputRendererHostWithInterception() override = default; 108 ~AudioInputRendererHostWithInterception() override = default;
111 109
112 private: 110 private:
113 bool Send(IPC::Message* message) override { 111 bool Send(IPC::Message* message) override {
114 DCHECK_CURRENTLY_ON(BrowserThread::IO); 112 DCHECK_CURRENTLY_ON(BrowserThread::IO);
115 bool handled = true; 113 bool handled = true;
116 114
117 IPC_BEGIN_MESSAGE_MAP(AudioInputRendererHostWithInterception, *message) 115 IPC_BEGIN_MESSAGE_MAP(AudioInputRendererHostWithInterception, *message)
118 IPC_MESSAGE_HANDLER(AudioInputMsg_NotifyStreamCreated, 116 IPC_MESSAGE_HANDLER(AudioInputMsg_NotifyStreamCreated,
119 NotifyRendererStreamCreated) 117 NotifyRendererStreamCreated)
120 IPC_MESSAGE_HANDLER(AudioInputMsg_NotifyStreamVolume, 118 IPC_MESSAGE_HANDLER(AudioInputMsg_NotifyStreamError,
121 NotifyRendererStreamVolume) 119 NotifyRendererStreamError)
122 IPC_MESSAGE_HANDLER(AudioInputMsg_NotifyStreamStateChanged,
123 NotifyRendererStreamStateChanged)
124 IPC_MESSAGE_UNHANDLED(handled = false) 120 IPC_MESSAGE_UNHANDLED(handled = false)
125 IPC_END_MESSAGE_MAP() 121 IPC_END_MESSAGE_MAP()
126 122
127 EXPECT_TRUE(handled); 123 EXPECT_TRUE(handled);
128 delete message; 124 delete message;
129 return true; 125 return true;
130 } 126 }
131 127
132 void ShutdownForBadMessage() override { renderer_->WasShutDown(); } 128 void ShutdownForBadMessage() override { renderer_->WasShutDown(); }
133 129
134 void NotifyRendererStreamCreated( 130 void NotifyRendererStreamCreated(
135 int stream_id, 131 int stream_id,
136 base::SharedMemoryHandle handle, 132 base::SharedMemoryHandle handle,
137 base::SyncSocket::TransitDescriptor socket_descriptor, 133 base::SyncSocket::TransitDescriptor socket_descriptor,
138 uint32_t length, 134 uint32_t length,
139 uint32_t total_segments) { 135 uint32_t total_segments) {
140 // It's difficult to check that the sync socket and shared memory is 136 // It's difficult to check that the sync socket and shared memory is
141 // valid in the gmock macros, so we check them here. 137 // valid in the gmock macros, so we check them here.
142 EXPECT_NE(base::SyncSocket::UnwrapHandle(socket_descriptor), 138 EXPECT_NE(base::SyncSocket::UnwrapHandle(socket_descriptor),
143 base::SyncSocket::kInvalidHandle); 139 base::SyncSocket::kInvalidHandle);
144 base::SharedMemory memory(handle, /*read_only*/ true); 140 base::SharedMemory memory(handle, /*read_only*/ true);
145 EXPECT_TRUE(memory.Map(length)); 141 EXPECT_TRUE(memory.Map(length));
146 renderer_->NotifyStreamCreated(stream_id, handle, socket_descriptor, length, 142 renderer_->NotifyStreamCreated(stream_id, handle, socket_descriptor, length,
147 total_segments); 143 total_segments);
148 EXPECT_TRUE(memory.Unmap()); 144 EXPECT_TRUE(memory.Unmap());
149 memory.Close(); 145 memory.Close();
150 } 146 }
151 147
152 void NotifyRendererStreamVolume(int stream_id, double volume) { 148 void NotifyRendererStreamError(int stream_id) {
153 renderer_->NotifyStreamVolume(stream_id, volume); 149 renderer_->NotifyStreamError(stream_id);
154 }
155
156 void NotifyRendererStreamStateChanged(
157 int stream_id,
158 media::AudioInputIPCDelegateState state) {
159 renderer_->NotifyStreamStateChanged(stream_id, state);
160 } 150 }
161 151
162 MockRenderer* renderer_; 152 MockRenderer* renderer_;
163 }; 153 };
164 154
165 class MockAudioInputController : public AudioInputController { 155 class MockAudioInputController : public AudioInputController {
166 public: 156 public:
167 MockAudioInputController( 157 MockAudioInputController(
168 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 158 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
169 AudioInputController::SyncWriter* writer, 159 AudioInputController::SyncWriter* writer,
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 airh_->OnMessageReceived(AudioInputHostMsg_CreateStream( 326 airh_->OnMessageReceived(AudioInputHostMsg_CreateStream(
337 kStreamId, kRenderFrameId, session_id, DefaultConfig())); 327 kStreamId, kRenderFrameId, session_id, DefaultConfig()));
338 328
339 base::RunLoop().RunUntilIdle(); 329 base::RunLoop().RunUntilIdle();
340 EXPECT_CALL(*controller_factory_.controller(0), Close(_)); 330 EXPECT_CALL(*controller_factory_.controller(0), Close(_));
341 } 331 }
342 332
343 // If authorization hasn't been granted, only reply with and error and do 333 // If authorization hasn't been granted, only reply with and error and do
344 // nothing else. 334 // nothing else.
345 TEST_F(AudioInputRendererHostTest, CreateWithoutAuthorization_Error) { 335 TEST_F(AudioInputRendererHostTest, CreateWithoutAuthorization_Error) {
346 EXPECT_CALL(renderer_, 336 EXPECT_CALL(renderer_, NotifyStreamError(kStreamId));
347 NotifyStreamStateChanged(
348 kStreamId, media::AUDIO_INPUT_IPC_DELEGATE_STATE_ERROR));
349 337
350 int session_id = 0; 338 int session_id = 0;
351 airh_->OnMessageReceived(AudioInputHostMsg_CreateStream( 339 airh_->OnMessageReceived(AudioInputHostMsg_CreateStream(
352 kStreamId, kRenderFrameId, session_id, DefaultConfig())); 340 kStreamId, kRenderFrameId, session_id, DefaultConfig()));
353 base::RunLoop().RunUntilIdle(); 341 base::RunLoop().RunUntilIdle();
354 } 342 }
355 343
356 // Like CreateWithDefaultDevice but with a nondefault device. 344 // Like CreateWithDefaultDevice but with a nondefault device.
357 TEST_F(AudioInputRendererHostTest, CreateWithNonDefaultDevice) { 345 TEST_F(AudioInputRendererHostTest, CreateWithNonDefaultDevice) {
358 int session_id = Open("Nondefault device", GetRawNondefaultId()); 346 int session_id = Open("Nondefault device", GetRawNondefaultId());
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 base::RunLoop().RunUntilIdle(); 446 base::RunLoop().RunUntilIdle();
459 } 447 }
460 448
461 // Checks that a stream_id cannot be reused. 449 // Checks that a stream_id cannot be reused.
462 TEST_F(AudioInputRendererHostTest, CreateTwice_Error) { 450 TEST_F(AudioInputRendererHostTest, CreateTwice_Error) {
463 int session_id = 451 int session_id =
464 Open("Default device", media::AudioDeviceDescription::kDefaultDeviceId); 452 Open("Default device", media::AudioDeviceDescription::kDefaultDeviceId);
465 453
466 EXPECT_CALL(renderer_, 454 EXPECT_CALL(renderer_,
467 NotifyStreamCreated(kStreamId, _, _, _, kSharedMemoryCount)); 455 NotifyStreamCreated(kStreamId, _, _, _, kSharedMemoryCount));
468 EXPECT_CALL(renderer_, 456 EXPECT_CALL(renderer_, NotifyStreamError(kStreamId));
469 NotifyStreamStateChanged(
470 kStreamId, media::AUDIO_INPUT_IPC_DELEGATE_STATE_ERROR));
471 EXPECT_CALL(controller_factory_, ControllerCreated()); 457 EXPECT_CALL(controller_factory_, ControllerCreated());
472 458
473 airh_->OnMessageReceived(AudioInputHostMsg_CreateStream( 459 airh_->OnMessageReceived(AudioInputHostMsg_CreateStream(
474 kStreamId, kRenderFrameId, session_id, DefaultConfig())); 460 kStreamId, kRenderFrameId, session_id, DefaultConfig()));
475 airh_->OnMessageReceived(AudioInputHostMsg_CreateStream( 461 airh_->OnMessageReceived(AudioInputHostMsg_CreateStream(
476 kStreamId, kRenderFrameId, session_id, DefaultConfig())); 462 kStreamId, kRenderFrameId, session_id, DefaultConfig()));
477 base::RunLoop().RunUntilIdle(); 463 base::RunLoop().RunUntilIdle();
478 464
479 EXPECT_CALL(*controller_factory_.controller(0), Close(_)); 465 EXPECT_CALL(*controller_factory_.controller(0), Close(_));
480 } 466 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 511
526 EXPECT_CALL(renderer_, 512 EXPECT_CALL(renderer_,
527 NotifyStreamCreated(kStreamId, _, _, _, kSharedMemoryCount)); 513 NotifyStreamCreated(kStreamId, _, _, _, kSharedMemoryCount));
528 EXPECT_CALL(controller_factory_, ControllerCreated()); 514 EXPECT_CALL(controller_factory_, ControllerCreated());
529 515
530 airh_->OnMessageReceived(AudioInputHostMsg_CreateStream( 516 airh_->OnMessageReceived(AudioInputHostMsg_CreateStream(
531 kStreamId, kRenderFrameId, session_id, DefaultConfig())); 517 kStreamId, kRenderFrameId, session_id, DefaultConfig()));
532 518
533 base::RunLoop().RunUntilIdle(); 519 base::RunLoop().RunUntilIdle();
534 EXPECT_CALL(*controller_factory_.controller(0), Close(_)); 520 EXPECT_CALL(*controller_factory_.controller(0), Close(_));
535 EXPECT_CALL(renderer_, 521 EXPECT_CALL(renderer_, NotifyStreamError(kStreamId));
536 NotifyStreamStateChanged(
537 kStreamId, media::AUDIO_INPUT_IPC_DELEGATE_STATE_ERROR));
538 522
539 controller_factory_.controller(0)->handler()->OnError( 523 controller_factory_.controller(0)->handler()->OnError(
540 controller_factory_.controller(0), AudioInputController::UNKNOWN_ERROR); 524 controller_factory_.controller(0), AudioInputController::UNKNOWN_ERROR);
541 525
542 // Check Close expectation before the destructor. 526 // Check Close expectation before the destructor.
543 base::RunLoop().RunUntilIdle(); 527 base::RunLoop().RunUntilIdle();
544 Mock::VerifyAndClear(controller_factory_.controller(0)); 528 Mock::VerifyAndClear(controller_factory_.controller(0));
545 } 529 }
546 530
547 // Checks that tab capture streams can be created. 531 // Checks that tab capture streams can be created.
(...skipping 14 matching lines...) Expand all
562 EXPECT_CALL(controller_factory_, ControllerCreated()); 546 EXPECT_CALL(controller_factory_, ControllerCreated());
563 547
564 airh_->OnMessageReceived(AudioInputHostMsg_CreateStream( 548 airh_->OnMessageReceived(AudioInputHostMsg_CreateStream(
565 kStreamId, kRenderFrameId, session_id, DefaultConfig())); 549 kStreamId, kRenderFrameId, session_id, DefaultConfig()));
566 base::RunLoop().RunUntilIdle(); 550 base::RunLoop().RunUntilIdle();
567 551
568 EXPECT_CALL(*controller_factory_.controller(0), Close(_)); 552 EXPECT_CALL(*controller_factory_.controller(0), Close(_));
569 } 553 }
570 554
571 } // namespace content 555 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698