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 std::string unique_default_id(media::AudioManagerBase::kDefaultDeviceId); | |
tommi (sloooow) - chröme
2015/09/28 14:30:50
nit: const? (same for unique_communications_id, un
Guido Urdaneta
2015/09/28 14:37:24
Done.
| |
199 std::string unique_communications_id( | |
200 media::AudioManagerBase::kCommunicationsDeviceId); | |
201 std::string unique_other_id("other-unique-id"); | |
202 | |
203 std::string hashed_default_id = MediaStreamManager::GetHMACForMediaDeviceID( | |
204 GetMockSaltCallback(), security_origin, unique_default_id); | |
205 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( | |
206 GetMockSaltCallback(), security_origin, hashed_default_id, | |
207 unique_default_id)); | |
208 EXPECT_EQ(unique_default_id, hashed_default_id); | |
209 | |
210 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 std::string hashed_other_id = MediaStreamManager::GetHMACForMediaDeviceID( | |
219 GetMockSaltCallback(), security_origin, unique_other_id); | |
220 EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC( | |
221 GetMockSaltCallback(), security_origin, hashed_other_id, | |
222 unique_other_id)); | |
223 EXPECT_NE(unique_other_id, hashed_other_id); | |
224 EXPECT_EQ(hashed_other_id.size(), 64U); | |
225 for (const char& c : hashed_other_id) | |
226 EXPECT_TRUE((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')); | |
227 } | |
228 | |
185 } // namespace content | 229 } // namespace content |
OLD | NEW |