summaryrefslogtreecommitdiffstats
path: root/toolkit/components/resistfingerprinting/tests
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/resistfingerprinting/tests')
-rw-r--r--toolkit/components/resistfingerprinting/tests/gtest/moz.build1
-rw-r--r--toolkit/components/resistfingerprinting/tests/gtest/test_usercharping.cpp143
2 files changed, 144 insertions, 0 deletions
diff --git a/toolkit/components/resistfingerprinting/tests/gtest/moz.build b/toolkit/components/resistfingerprinting/tests/gtest/moz.build
index dcc6a7e12e..a677def009 100644
--- a/toolkit/components/resistfingerprinting/tests/gtest/moz.build
+++ b/toolkit/components/resistfingerprinting/tests/gtest/moz.build
@@ -1,5 +1,6 @@
UNIFIED_SOURCES += [
"test_reduceprecision.cpp",
+ "test_usercharping.cpp",
]
FINAL_LIBRARY = "xul-gtest"
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);
+}