OLD | NEW |
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 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #elif defined(OS_MACOSX) | 43 #elif defined(OS_MACOSX) |
44 typedef media::AudioManagerMac AudioManagerPlatform; | 44 typedef media::AudioManagerMac AudioManagerPlatform; |
45 #elif defined(OS_WIN) | 45 #elif defined(OS_WIN) |
46 typedef media::AudioManagerWin AudioManagerPlatform; | 46 typedef media::AudioManagerWin AudioManagerPlatform; |
47 #elif defined(OS_ANDROID) | 47 #elif defined(OS_ANDROID) |
48 typedef media::AudioManagerAndroid AudioManagerPlatform; | 48 typedef media::AudioManagerAndroid AudioManagerPlatform; |
49 #else | 49 #else |
50 typedef media::FakeAudioManager AudioManagerPlatform; | 50 typedef media::FakeAudioManager AudioManagerPlatform; |
51 #endif | 51 #endif |
52 | 52 |
| 53 namespace { |
| 54 |
| 55 std::string ReturnMockSalt() { |
| 56 return std::string(); |
| 57 } |
| 58 |
| 59 ResourceContext::SaltCallback GetMockSaltCallback() { |
| 60 return base::Bind(&ReturnMockSalt); |
| 61 } |
| 62 |
| 63 } // namespace |
53 | 64 |
54 // This class mocks the audio manager and overrides the | 65 // This class mocks the audio manager and overrides the |
55 // GetAudioInputDeviceNames() method to ensure that we can run our tests on | 66 // GetAudioInputDeviceNames() method to ensure that we can run our tests on |
56 // the buildbots. media::AudioManagerBase | 67 // the buildbots. media::AudioManagerBase |
57 class MockAudioManager : public AudioManagerPlatform { | 68 class MockAudioManager : public AudioManagerPlatform { |
58 public: | 69 public: |
59 MockAudioManager() : AudioManagerPlatform(&fake_audio_log_factory_) {} | 70 MockAudioManager() : AudioManagerPlatform(&fake_audio_log_factory_) {} |
60 ~MockAudioManager() override {} | 71 ~MockAudioManager() override {} |
61 | 72 |
62 void GetAudioInputDeviceNames( | 73 void GetAudioInputDeviceNames( |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 std::string label1 = MakeMediaAccessRequest(0); | 186 std::string label1 = MakeMediaAccessRequest(0); |
176 std::string label2 = MakeMediaAccessRequest(1); | 187 std::string label2 = MakeMediaAccessRequest(1); |
177 media_stream_manager_->CancelRequest(label1); | 188 media_stream_manager_->CancelRequest(label1); |
178 | 189 |
179 // Expecting the callback from the second request will be triggered and | 190 // Expecting the callback from the second request will be triggered and |
180 // quit the test. | 191 // quit the test. |
181 EXPECT_CALL(*this, Response(1)); | 192 EXPECT_CALL(*this, Response(1)); |
182 run_loop_.Run(); | 193 run_loop_.Run(); |
183 } | 194 } |
184 | 195 |
| 196 TEST_F(MediaStreamManagerTest, DeviceID) { |
| 197 GURL security_origin("http://localhost"); |
| 198 const std::string unique_default_id( |
| 199 media::AudioManagerBase::kDefaultDeviceId); |
| 200 const std::string hashed_default_id = |
| 201 MediaStreamManager::GetHMACForMediaDeviceID( |
| 202 GetMockSaltCallback(), security_origin, unique_default_id); |
| 203 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( |
| 204 GetMockSaltCallback(), security_origin, hashed_default_id, |
| 205 unique_default_id)); |
| 206 EXPECT_EQ(unique_default_id, hashed_default_id); |
| 207 |
| 208 const std::string unique_communications_id( |
| 209 media::AudioManagerBase::kCommunicationsDeviceId); |
| 210 const std::string hashed_communications_id = |
| 211 MediaStreamManager::GetHMACForMediaDeviceID( |
| 212 GetMockSaltCallback(), security_origin, unique_communications_id); |
| 213 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( |
| 214 GetMockSaltCallback(), security_origin, hashed_communications_id, |
| 215 unique_communications_id)); |
| 216 EXPECT_EQ(unique_communications_id, hashed_communications_id); |
| 217 |
| 218 const std::string unique_other_id("other-unique-id"); |
| 219 const std::string hashed_other_id = |
| 220 MediaStreamManager::GetHMACForMediaDeviceID( |
| 221 GetMockSaltCallback(), security_origin, unique_other_id); |
| 222 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( |
| 223 GetMockSaltCallback(), security_origin, hashed_other_id, |
| 224 unique_other_id)); |
| 225 EXPECT_NE(unique_other_id, hashed_other_id); |
| 226 EXPECT_EQ(hashed_other_id.size(), 64U); |
| 227 for (const char& c : hashed_other_id) |
| 228 EXPECT_TRUE((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')); |
| 229 } |
| 230 |
185 } // namespace content | 231 } // namespace content |
OLD | NEW |