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

Unified Diff: content/browser/renderer_host/media/media_stream_manager_unittest.cc

Issue 1369723003: Do not hash default and communications media device ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tommi's comments Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/media_stream_manager_unittest.cc
diff --git a/content/browser/renderer_host/media/media_stream_manager_unittest.cc b/content/browser/renderer_host/media/media_stream_manager_unittest.cc
index fc0028c0a7669faf821b1907404c1b7a585304bc..9ef2bd395fc4e09f702acd01f506d5946124d597 100644
--- a/content/browser/renderer_host/media/media_stream_manager_unittest.cc
+++ b/content/browser/renderer_host/media/media_stream_manager_unittest.cc
@@ -50,6 +50,17 @@ typedef media::AudioManagerAndroid AudioManagerPlatform;
typedef media::FakeAudioManager AudioManagerPlatform;
#endif
+namespace {
+
+std::string ReturnMockSalt() {
+ return std::string();
+}
+
+ResourceContext::SaltCallback GetMockSaltCallback() {
+ return base::Bind(&ReturnMockSalt);
+}
+
+} // namespace
// This class mocks the audio manager and overrides the
// GetAudioInputDeviceNames() method to ensure that we can run our tests on
@@ -182,4 +193,39 @@ TEST_F(MediaStreamManagerTest, MakeAndCancelMultipleRequests) {
run_loop_.Run();
}
+TEST_F(MediaStreamManagerTest, DeviceID) {
+ GURL security_origin("http://localhost");
+ const std::string unique_default_id(
+ media::AudioManagerBase::kDefaultDeviceId);
+ const std::string hashed_default_id =
+ MediaStreamManager::GetHMACForMediaDeviceID(
+ GetMockSaltCallback(), security_origin, unique_default_id);
+ EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC(
+ GetMockSaltCallback(), security_origin, hashed_default_id,
+ unique_default_id));
+ EXPECT_EQ(unique_default_id, hashed_default_id);
+
+ const std::string unique_communications_id(
+ media::AudioManagerBase::kCommunicationsDeviceId);
+ const std::string hashed_communications_id =
+ MediaStreamManager::GetHMACForMediaDeviceID(
+ GetMockSaltCallback(), security_origin, unique_communications_id);
+ EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC(
+ GetMockSaltCallback(), security_origin, hashed_communications_id,
+ unique_communications_id));
+ EXPECT_EQ(unique_communications_id, hashed_communications_id);
+
+ const std::string unique_other_id("other-unique-id");
+ const std::string hashed_other_id =
+ MediaStreamManager::GetHMACForMediaDeviceID(
+ GetMockSaltCallback(), security_origin, unique_other_id);
+ EXPECT_TRUE(MediaStreamManager::DoesMediaDeviceIDMatchHMAC(
+ GetMockSaltCallback(), security_origin, hashed_other_id,
+ unique_other_id));
+ EXPECT_NE(unique_other_id, hashed_other_id);
+ EXPECT_EQ(hashed_other_id.size(), 64U);
+ for (const char& c : hashed_other_id)
+ EXPECT_TRUE((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'));
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698