diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
commit | fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch) | |
tree | 4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /toolkit/components/resistfingerprinting/tests/gtest/test_usercharping.cpp | |
parent | Releasing progress-linux version 124.0.1-1~progress7.99u1. (diff) | |
download | firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/resistfingerprinting/tests/gtest/test_usercharping.cpp')
-rw-r--r-- | toolkit/components/resistfingerprinting/tests/gtest/test_usercharping.cpp | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/toolkit/components/resistfingerprinting/tests/gtest/test_usercharping.cpp b/toolkit/components/resistfingerprinting/tests/gtest/test_usercharping.cpp new file mode 100644 index 0000000000..dd1cbe7d46 --- /dev/null +++ b/toolkit/components/resistfingerprinting/tests/gtest/test_usercharping.cpp @@ -0,0 +1,143 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "gtest/gtest.h" +#include "mozilla/gtest/nsUserCharacteristics.h" + +#include "mozilla/glean/GleanPings.h" +#include "mozilla/glean/GleanMetrics.h" + +using namespace mozilla; + +const auto* const kUUIDPref = + "toolkit.telemetry.user_characteristics_ping.uuid"; + +TEST(ResistFingerprinting, UserCharacteristics_Simple) +{ + mozilla::glean::characteristics::max_touch_points.Set(7); + + bool submitted = false; + mozilla::glean_pings::UserCharacteristics.TestBeforeNextSubmit( + [&submitted](const nsACString& aReason) { + submitted = true; + + ASSERT_EQ( + 7, mozilla::glean::characteristics::max_touch_points.TestGetValue() + .unwrap() + .ref()); + }); + mozilla::glean_pings::UserCharacteristics.Submit(); + ASSERT_TRUE(submitted); +} + +TEST(ResistFingerprinting, UserCharacteristics_Complex) +{ + nsUserCharacteristics::PopulateData(true); + + bool submitted = false; + mozilla::glean_pings::UserCharacteristics.TestBeforeNextSubmit( + [&submitted](const nsACString& aReason) { + submitted = true; + + ASSERT_STRNE("", mozilla::glean::characteristics::client_identifier + .TestGetValue() + .unwrap() + .value() + .get()); + + nsCString fullUuidStr; + Preferences::GetCString(kUUIDPref, fullUuidStr); + + // Remove the '{' and '}' + nsAutoCString uuidString; + uuidString = Substring(fullUuidStr, 1, NSID_LENGTH - 3); + + ASSERT_STREQ( + uuidString.get(), + mozilla::glean::characteristics::client_identifier.TestGetValue() + .unwrap() + .value() + .get()); + ASSERT_EQ( + testing::MaxTouchPoints(), + mozilla::glean::characteristics::max_touch_points.TestGetValue() + .unwrap() + .ref()); + }); + nsUserCharacteristics::SubmitPing(); + ASSERT_TRUE(submitted); +} + +TEST(ResistFingerprinting, UserCharacteristics_ClearPref) +{ + nsCString originalUUID; + + mozilla::glean_pings::UserCharacteristics.TestBeforeNextSubmit( + [&originalUUID](const nsACString& aReason) { + originalUUID = + mozilla::glean::characteristics::client_identifier.TestGetValue() + .unwrap() + .value() + .get(); + ASSERT_STRNE("", mozilla::glean::characteristics::client_identifier + .TestGetValue() + .unwrap() + .value() + .get()); + + nsCString fullUuidStr; + Preferences::GetCString(kUUIDPref, fullUuidStr); + + // Remove the '{' and '}' + nsAutoCString uuidString; + uuidString = Substring(fullUuidStr, 1, NSID_LENGTH - 3); + + ASSERT_STREQ( + uuidString.get(), + mozilla::glean::characteristics::client_identifier.TestGetValue() + .unwrap() + .value() + .get()); + }); + nsUserCharacteristics::PopulateData(true); + nsUserCharacteristics::SubmitPing(); + + auto original_value = + Preferences::GetBool("datareporting.healthreport.uploadEnabled"); + Preferences::SetBool("datareporting.healthreport.uploadEnabled", true); + Preferences::SetBool("datareporting.healthreport.uploadEnabled", false); + + mozilla::glean_pings::UserCharacteristics.TestBeforeNextSubmit( + [](const nsACString& aReason) { + // Assert that the pref is blank + nsAutoCString uuidValue; + Preferences::GetCString(kUUIDPref, uuidValue); + ASSERT_STREQ("", uuidValue.get()); + }); + nsUserCharacteristics::SubmitPing(); + + Preferences::SetBool("datareporting.healthreport.uploadEnabled", true); + mozilla::glean_pings::UserCharacteristics.TestBeforeNextSubmit( + [&originalUUID](const nsACString& aReason) { + // Assert that the new UUID is different from the old one + ASSERT_STRNE( + originalUUID.get(), + mozilla::glean::characteristics::client_identifier.TestGetValue() + .unwrap() + .value() + .get()); + + // Assert that the pref is not blank + nsAutoCString uuidValue; + Preferences::GetCString(kUUIDPref, uuidValue); + ASSERT_STRNE("", uuidValue.get()); + }); + nsUserCharacteristics::PopulateData(true); + nsUserCharacteristics::SubmitPing(); + + Preferences::SetBool("datareporting.healthreport.uploadEnabled", + original_value); +} |