| OLD | NEW |
| 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 // Unit tests for AudioOutputAuthorizationHandler. | 5 // Unit tests for AudioOutputAuthorizationHandler. |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/media/audio_output_authorization_handler
.h" | 7 #include "content/browser/renderer_host/media/audio_output_authorization_handler
.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 BrowserThread::IO, FROM_HERE, | 253 BrowserThread::IO, FROM_HERE, |
| 254 (base::Bind(&AudioOutputAuthorizationHandler::RequestDeviceAuthorization, | 254 (base::Bind(&AudioOutputAuthorizationHandler::RequestDeviceAuthorization, |
| 255 base::Unretained(handler.get()), kRenderFrameId, 0, hashed_id, | 255 base::Unretained(handler.get()), kRenderFrameId, 0, hashed_id, |
| 256 SecurityOrigin(), listener.GetCallback()))); | 256 SecurityOrigin(), listener.GetCallback()))); |
| 257 | 257 |
| 258 SyncWithAllThreads(); | 258 SyncWithAllThreads(); |
| 259 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, handler.release()); | 259 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, handler.release()); |
| 260 SyncWithAllThreads(); | 260 SyncWithAllThreads(); |
| 261 } | 261 } |
| 262 | 262 |
| 263 TEST_F(AudioOutputAuthorizationHandlerTest, | 263 TEST_F(AudioOutputAuthorizationHandlerTest, AuthorizeInvalidDeviceId_NotFound) { |
| 264 AuthorizeInvalidDeviceId_BadMessage) { | |
| 265 std::unique_ptr<TestBrowserContext> context = | 264 std::unique_ptr<TestBrowserContext> context = |
| 266 base::MakeUnique<TestBrowserContext>(); | 265 base::MakeUnique<TestBrowserContext>(); |
| 267 std::unique_ptr<MockRenderProcessHost> RPH = | 266 std::unique_ptr<MockRenderProcessHost> RPH = |
| 268 base::MakeUnique<MockRenderProcessHost>(context.get()); | 267 base::MakeUnique<MockRenderProcessHost>(context.get()); |
| 269 MockListener listener; | 268 MockListener listener; |
| 270 std::unique_ptr<AudioOutputAuthorizationHandler> handler = | 269 std::unique_ptr<AudioOutputAuthorizationHandler> handler = |
| 271 base::MakeUnique<AudioOutputAuthorizationHandler>( | 270 base::MakeUnique<AudioOutputAuthorizationHandler>( |
| 272 GetAudioManager(), GetMediaStreamManager(), RPH->GetID(), kSalt); | 271 GetAudioManager(), GetMediaStreamManager(), RPH->GetID(), kSalt); |
| 273 EXPECT_EQ(RPH->bad_msg_count(), 0); | 272 EXPECT_EQ(RPH->bad_msg_count(), 0); |
| 274 | 273 |
| 275 EXPECT_CALL(listener, MockAuthorizationCallback(_, _, _, _)).Times(0); | 274 EXPECT_CALL(listener, |
| 275 MockAuthorizationCallback( |
| 276 media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, _, _, _)) |
| 277 .Times(1); |
| 276 | 278 |
| 277 BrowserThread::PostTask( | 279 BrowserThread::PostTask( |
| 278 BrowserThread::IO, FROM_HERE, | 280 BrowserThread::IO, FROM_HERE, |
| 279 (base::Bind(&AudioOutputAuthorizationHandler::RequestDeviceAuthorization, | 281 (base::Bind(&AudioOutputAuthorizationHandler::RequestDeviceAuthorization, |
| 280 base::Unretained(handler.get()), kRenderFrameId, 0, | 282 base::Unretained(handler.get()), kRenderFrameId, 0, |
| 281 kInvalidDeviceId, SecurityOrigin(), listener.GetCallback()))); | 283 kInvalidDeviceId, SecurityOrigin(), listener.GetCallback()))); |
| 282 | 284 |
| 283 SyncWithAllThreads(); | 285 SyncWithAllThreads(); |
| 284 EXPECT_EQ(RPH->bad_msg_count(), 1); | 286 // It is possible to request an invalid device id from JS APIs, |
| 287 // so we don't want to crash the renderer for this. |
| 288 EXPECT_EQ(RPH->bad_msg_count(), 0); |
| 285 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, handler.release()); | 289 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, handler.release()); |
| 286 SyncWithAllThreads(); | 290 SyncWithAllThreads(); |
| 287 RPH.reset(); | 291 RPH.reset(); |
| 288 context.reset(); | 292 context.reset(); |
| 289 } | 293 } |
| 290 | 294 |
| 291 TEST_F(AudioOutputAuthorizationHandlerTest, | 295 TEST_F(AudioOutputAuthorizationHandlerTest, |
| 292 AuthorizeNondefaultDeviceIdWithBadOrigin_BadMessage) { | 296 AuthorizeNondefaultDeviceIdWithBadOrigin_BadMessage) { |
| 293 std::string raw_nondefault_id = GetRawNondefaultId(); | 297 std::string raw_nondefault_id = GetRawNondefaultId(); |
| 294 std::string hashed_id = MediaStreamManager::GetHMACForMediaDeviceID( | 298 std::string hashed_id = MediaStreamManager::GetHMACForMediaDeviceID( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 (base::Bind(&AudioOutputAuthorizationHandler::RequestDeviceAuthorization, | 340 (base::Bind(&AudioOutputAuthorizationHandler::RequestDeviceAuthorization, |
| 337 base::Unretained(handler.get()), kRenderFrameId, kSessionId, | 341 base::Unretained(handler.get()), kRenderFrameId, kSessionId, |
| 338 std::string(), BadSecurityOrigin(), listener.GetCallback()))); | 342 std::string(), BadSecurityOrigin(), listener.GetCallback()))); |
| 339 | 343 |
| 340 SyncWithAllThreads(); | 344 SyncWithAllThreads(); |
| 341 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, handler.release()); | 345 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, handler.release()); |
| 342 SyncWithAllThreads(); | 346 SyncWithAllThreads(); |
| 343 } | 347 } |
| 344 | 348 |
| 345 } // namespace content | 349 } // namespace content |
| OLD | NEW |