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

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

Issue 283623002: Add support for passing an arbitrary parameter to an IPC message handler. The motivation is for Web… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 6 years, 7 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
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 #include <string> 5 #include <string>
6 #include <queue> 6 #include <queue>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 namespace content { 44 namespace content {
45 45
46 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, 46 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost,
47 public TestContentBrowserClient { 47 public TestContentBrowserClient {
48 public: 48 public:
49 MockMediaStreamDispatcherHost( 49 MockMediaStreamDispatcherHost(
50 const ResourceContext::SaltCallback salt_callback, 50 const ResourceContext::SaltCallback salt_callback,
51 const scoped_refptr<base::MessageLoopProxy>& message_loop, 51 const scoped_refptr<base::MessageLoopProxy>& message_loop,
52 MediaStreamManager* manager) 52 MediaStreamManager* manager)
53 : MediaStreamDispatcherHost(kProcessId, salt_callback, manager), 53 : MediaStreamDispatcherHost(kProcessId, salt_callback, manager),
54 message_loop_(message_loop) {} 54 message_loop_(message_loop),
55 current_ipc_(NULL) {}
55 56
56 // A list of mock methods. 57 // A list of mock methods.
57 MOCK_METHOD4(OnStreamGenerated, 58 MOCK_METHOD4(OnStreamGenerated,
58 void(int routing_id, int request_id, int audio_array_size, 59 void(int routing_id, int request_id, int audio_array_size,
59 int video_array_size)); 60 int video_array_size));
60 MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id, 61 MOCK_METHOD3(OnStreamGenerationFailed, void(int routing_id,
61 int request_id, 62 int request_id,
62 MediaStreamRequestResult result)); 63 MediaStreamRequestResult result));
63 MOCK_METHOD1(OnDeviceStopped, void(int routing_id)); 64 MOCK_METHOD1(OnDeviceStopped, void(int routing_id));
64 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id)); 65 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 StreamDeviceInfoArray enumerated_devices_; 108 StreamDeviceInfoArray enumerated_devices_;
108 109
109 private: 110 private:
110 virtual ~MockMediaStreamDispatcherHost() {} 111 virtual ~MockMediaStreamDispatcherHost() {}
111 112
112 // This method is used to dispatch IPC messages to the renderer. We intercept 113 // This method is used to dispatch IPC messages to the renderer. We intercept
113 // these messages here and dispatch to our mock methods to verify the 114 // these messages here and dispatch to our mock methods to verify the
114 // conversation between this object and the renderer. 115 // conversation between this object and the renderer.
115 virtual bool Send(IPC::Message* message) OVERRIDE { 116 virtual bool Send(IPC::Message* message) OVERRIDE {
116 CHECK(message); 117 CHECK(message);
118 current_ipc_ = message;
117 119
118 // In this method we dispatch the messages to the according handlers as if 120 // In this method we dispatch the messages to the according handlers as if
119 // we are the renderer. 121 // we are the renderer.
120 bool handled = true; 122 bool handled = true;
121 IPC_BEGIN_MESSAGE_MAP(MockMediaStreamDispatcherHost, *message) 123 IPC_BEGIN_MESSAGE_MAP(MockMediaStreamDispatcherHost, *message)
122 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated, OnStreamGenerated) 124 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated,
125 OnStreamGeneratedInternal)
123 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerationFailed, 126 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerationFailed,
124 OnStreamGenerationFailed) 127 OnStreamGenerationFailedInternal)
125 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceStopped, OnDeviceStopped) 128 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceStopped, OnDeviceStoppedInternal)
126 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceOpened, OnDeviceOpened) 129 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceOpened, OnDeviceOpenedInternal)
127 IPC_MESSAGE_HANDLER(MediaStreamMsg_DevicesEnumerated, 130 IPC_MESSAGE_HANDLER(MediaStreamMsg_DevicesEnumerated, OnDevicesEnumerated)
128 OnDevicesEnumerated)
129 IPC_MESSAGE_UNHANDLED(handled = false) 131 IPC_MESSAGE_UNHANDLED(handled = false)
130 IPC_END_MESSAGE_MAP() 132 IPC_END_MESSAGE_MAP()
131 EXPECT_TRUE(handled); 133 EXPECT_TRUE(handled);
132 134
133 delete message; 135 delete message;
136 current_ipc_ = NULL;
134 return true; 137 return true;
135 } 138 }
136 139
137 // These handler methods do minimal things and delegate to the mock methods. 140 // These handler methods do minimal things and delegate to the mock methods.
138 void OnStreamGenerated( 141 void OnStreamGeneratedInternal(
139 const IPC::Message& msg,
140 int request_id, 142 int request_id,
141 std::string label, 143 std::string label,
142 StreamDeviceInfoArray audio_device_list, 144 StreamDeviceInfoArray audio_device_list,
143 StreamDeviceInfoArray video_device_list) { 145 StreamDeviceInfoArray video_device_list) {
144 OnStreamGenerated(msg.routing_id(), request_id, audio_device_list.size(), 146 OnStreamGenerated(current_ipc_->routing_id(), request_id,
145 video_device_list.size()); 147 audio_device_list.size(), video_device_list.size());
146 // Notify that the event have occurred. 148 // Notify that the event have occurred.
147 base::Closure quit_closure = quit_closures_.front(); 149 base::Closure quit_closure = quit_closures_.front();
148 quit_closures_.pop(); 150 quit_closures_.pop();
149 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); 151 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
150 152
151 label_ = label; 153 label_ = label;
152 audio_devices_ = audio_device_list; 154 audio_devices_ = audio_device_list;
153 video_devices_ = video_device_list; 155 video_devices_ = video_device_list;
154 } 156 }
155 157
156 void OnStreamGenerationFailed( 158 void OnStreamGenerationFailedInternal(
157 const IPC::Message& msg,
158 int request_id, 159 int request_id,
159 content::MediaStreamRequestResult result) { 160 content::MediaStreamRequestResult result) {
160 OnStreamGenerationFailed(msg.routing_id(), request_id, result); 161 OnStreamGenerationFailed(current_ipc_->routing_id(), request_id, result);
161 if (!quit_closures_.empty()) { 162 if (!quit_closures_.empty()) {
162 base::Closure quit_closure = quit_closures_.front(); 163 base::Closure quit_closure = quit_closures_.front();
163 quit_closures_.pop(); 164 quit_closures_.pop();
164 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); 165 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
165 } 166 }
166 167
167 label_= ""; 168 label_= "";
168 } 169 }
169 170
170 void OnDeviceStopped(const IPC::Message& msg, 171 void OnDeviceStoppedInternal(const std::string& label,
171 const std::string& label, 172 const content::StreamDeviceInfo& device) {
172 const content::StreamDeviceInfo& device) {
173 if (IsVideoMediaType(device.device.type)) 173 if (IsVideoMediaType(device.device.type))
174 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, video_devices_[0])); 174 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, video_devices_[0]));
175 if (IsAudioMediaType(device.device.type)) 175 if (IsAudioMediaType(device.device.type))
176 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, audio_devices_[0])); 176 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, audio_devices_[0]));
177 177
178 OnDeviceStopped(msg.routing_id()); 178 OnDeviceStopped(current_ipc_->routing_id());
179 } 179 }
180 180
181 void OnDeviceOpened(const IPC::Message& msg, 181 void OnDeviceOpenedInternal(int request_id,
182 int request_id, 182 const std::string& label,
183 const std::string& label, 183 const StreamDeviceInfo& device) {
184 const StreamDeviceInfo& device) {
185 base::Closure quit_closure = quit_closures_.front(); 184 base::Closure quit_closure = quit_closures_.front();
186 quit_closures_.pop(); 185 quit_closures_.pop();
187 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); 186 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
188 label_ = label; 187 label_ = label;
189 opened_device_ = device; 188 opened_device_ = device;
190 } 189 }
191 190
192 void OnDevicesEnumerated(const IPC::Message& msg, 191 void OnDevicesEnumerated(int request_id,
193 int request_id,
194 const StreamDeviceInfoArray& devices) { 192 const StreamDeviceInfoArray& devices) {
195 base::Closure quit_closure = quit_closures_.front(); 193 base::Closure quit_closure = quit_closures_.front();
196 quit_closures_.pop(); 194 quit_closures_.pop();
197 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); 195 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
198 enumerated_devices_ = devices; 196 enumerated_devices_ = devices;
199 } 197 }
200 198
201 scoped_refptr<base::MessageLoopProxy> message_loop_; 199 scoped_refptr<base::MessageLoopProxy> message_loop_;
202 200 IPC::Message* current_ipc_;
203 std::queue<base::Closure> quit_closures_; 201 std::queue<base::Closure> quit_closures_;
204 }; 202 };
205 203
206 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { 204 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy {
207 public: 205 public:
208 MOCK_METHOD2( 206 MOCK_METHOD2(
209 OnStarted, 207 OnStarted,
210 void(const base::Closure& stop, 208 void(const base::Closure& stop,
211 const MediaStreamUIProxy::WindowIdCallback& window_id_callback)); 209 const MediaStreamUIProxy::WindowIdCallback& window_id_callback));
212 }; 210 };
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, 850 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
853 MEDIA_DEVICE_AUDIO_CAPTURE); 851 MEDIA_DEVICE_AUDIO_CAPTURE);
854 } 852 }
855 853
856 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { 854 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) {
857 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, 855 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
858 MEDIA_DEVICE_VIDEO_CAPTURE); 856 MEDIA_DEVICE_VIDEO_CAPTURE);
859 } 857 }
860 858
861 }; // namespace content 859 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698