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

Unified Diff: components/certificate_reporting/error_report_unittest.cc

Issue 2448943004: Add experimental feature info to certificate reports (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « components/certificate_reporting/error_report.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/certificate_reporting/error_report_unittest.cc
diff --git a/components/certificate_reporting/error_report_unittest.cc b/components/certificate_reporting/error_report_unittest.cc
index c49b5448a5365ddbf56d91749c003edcd4c5ac48..f6d4167be1f203c4fe2c532033525ac4ed76d221 100644
--- a/components/certificate_reporting/error_report_unittest.cc
+++ b/components/certificate_reporting/error_report_unittest.cc
@@ -7,10 +7,16 @@
#include <set>
#include <string>
+#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
+#include "base/memory/ptr_util.h"
+#include "base/metrics/field_trial.h"
#include "base/path_service.h"
+#include "base/test/mock_entropy_provider.h"
+#include "base/test/scoped_feature_list.h"
#include "components/certificate_reporting/cert_logger.pb.h"
+#include "components/variations/variations_associated_data.h"
#include "net/cert/cert_status_flags.h"
#include "net/ssl/ssl_info.h"
#include "net/test/cert_test_util.h"
@@ -178,6 +184,59 @@ TEST(ErrorReportTest, CertificateTransparencyError) {
VerifyErrorReportSerialization(report_known, ssl_info, cert_errors));
}
+// Tests that information about relevant features are included in the
+// report.
+TEST(ErrorReportTest, FeatureInfo) {
+ // Set up a test feature.
+ const std::string kTrialName = "Trial";
+ const std::string kGroupName = "group";
+ base::Feature kDummyFeature{"dummy_feature",
+ base::FEATURE_ENABLED_BY_DEFAULT};
+ std::map<std::string, std::string> params;
+ params["foo"] = "bar";
+ params["foo2"] = "bar2";
+
+ variations::testing::ClearAllVariationParams();
+ std::unique_ptr<base::FieldTrialList> field_trial_list;
+ field_trial_list.reset();
meacer 2016/10/26 20:20:31 Needed?
estark 2016/10/28 00:02:34 Done.
+ field_trial_list.reset(
+ new base::FieldTrialList(base::MakeUnique<base::MockEntropyProvider>()));
+
+ base::FieldTrial* trial = base::FieldTrialList::FactoryGetFieldTrial(
+ kTrialName, 100, kGroupName, 1971, 1, 1,
+ base::FieldTrial::SESSION_RANDOMIZED, nullptr /* default_group_number */);
+ ASSERT_TRUE(
+ variations::AssociateVariationParams(kTrialName, kGroupName, params));
+
+ std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
+ feature_list->RegisterFieldTrialOverride(
+ kDummyFeature.name, base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial);
+ std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list(
+ new base::test::ScopedFeatureList());
+ scoped_feature_list->InitWithFeatureList(std::move(feature_list));
+
+ // Serialize a report containing information about the test feature.
+ SSLInfo ssl_info;
+ ASSERT_NO_FATAL_FAILURE(
+ GetTestSSLInfo(INCLUDE_UNVERIFIED_CERT_CHAIN, &ssl_info, kCertStatus));
+ ErrorReport report(kDummyHostname, ssl_info);
+ report.AddFeature(kDummyFeature);
+ std::string serialized_report;
+ ASSERT_TRUE(report.Serialize(&serialized_report));
+
+ // Check that the report contains the test feature information.
+ CertLoggerRequest parsed;
+ ASSERT_TRUE(parsed.ParseFromString(serialized_report));
+ ASSERT_EQ(1, parsed.features_info().size());
+ EXPECT_EQ(kDummyFeature.name, parsed.features_info(0).feature());
+ EXPECT_TRUE(parsed.features_info(0).enabled());
+ std::map<std::string, std::string> parsed_params;
+ for (const auto& param : parsed.features_info(0).params()) {
+ parsed_params[param.name()] = param.value();
+ }
+ EXPECT_EQ(params, parsed_params);
+}
+
} // namespace
} // namespace certificate_reporting
« no previous file with comments | « components/certificate_reporting/error_report.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698