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

Side by Side Diff: chrome/browser/safe_browsing/permission_reporter_unittest.cc

Issue 2153763002: Add user gesture field to permission report (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add-source-ui-to-permission-report
Patch Set: Add user gesture mark Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/safe_browsing/permission_reporter.h" 5 #include "chrome/browser/safe_browsing/permission_reporter.h"
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "chrome/common/safe_browsing/permission_report.pb.h" 10 #include "chrome/common/safe_browsing/permission_report.pb.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // Owned by |permission_reporter_|. 78 // Owned by |permission_reporter_|.
79 MockReportSender* mock_report_sender_; 79 MockReportSender* mock_report_sender_;
80 80
81 std::unique_ptr<PermissionReporter> permission_reporter_; 81 std::unique_ptr<PermissionReporter> permission_reporter_;
82 }; 82 };
83 83
84 // Test that PermissionReporter::SendReport sends a serialized report string to 84 // Test that PermissionReporter::SendReport sends a serialized report string to
85 // SafeBrowsing CSD servers. 85 // SafeBrowsing CSD servers.
86 TEST_F(PermissionReporterTest, SendReport) { 86 TEST_F(PermissionReporterTest, SendReport) {
87 permission_reporter_->SendReport(GURL(kDummyOrigin), kDummyPermission, 87 permission_reporter_->SendReport(GURL(kDummyOrigin), kDummyPermission,
88 kDummyAction, kDummySourceUI); 88 kDummyAction, kDummySourceUI, false);
89 89
90 PermissionReport permission_report; 90 PermissionReport permission_report;
91 ASSERT_TRUE( 91 ASSERT_TRUE(
92 permission_report.ParseFromString(mock_report_sender_->latest_report())); 92 permission_report.ParseFromString(mock_report_sender_->latest_report()));
93 EXPECT_EQ(PermissionReport::GEOLOCATION, permission_report.permission()); 93 EXPECT_EQ(PermissionReport::GEOLOCATION, permission_report.permission());
94 EXPECT_EQ(PermissionReport::GRANTED, permission_report.action()); 94 EXPECT_EQ(PermissionReport::GRANTED, permission_report.action());
95 EXPECT_EQ(PermissionReport::PROMPT, permission_report.source_ui()); 95 EXPECT_EQ(PermissionReport::PROMPT, permission_report.source_ui());
96 EXPECT_EQ(kDummyOrigin, permission_report.origin()); 96 EXPECT_EQ(kDummyOrigin, permission_report.origin());
97 EXPECT_TRUE(permission_report.request_trigger().empty());
97 #if defined(OS_ANDROID) 98 #if defined(OS_ANDROID)
98 EXPECT_EQ(PermissionReport::ANDROID_PLATFORM, 99 EXPECT_EQ(PermissionReport::ANDROID_PLATFORM,
99 permission_report.platform_type()); 100 permission_report.platform_type());
100 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ 101 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \
101 defined(OS_LINUX) 102 defined(OS_LINUX)
102 EXPECT_EQ(PermissionReport::DESKTOP_PLATFORM, 103 EXPECT_EQ(PermissionReport::DESKTOP_PLATFORM,
103 permission_report.platform_type()); 104 permission_report.platform_type());
104 #endif 105 #endif
105 106
106 EXPECT_EQ(GURL(kPermissionActionReportingUploadUrl), 107 EXPECT_EQ(GURL(kPermissionActionReportingUploadUrl),
107 mock_report_sender_->latest_report_uri()); 108 mock_report_sender_->latest_report_uri());
108 } 109 }
109 110
110 // Test that PermissionReporter::SendReport sends a serialized report string 111 // Test that PermissionReporter::SendReport sends a serialized report string
112 // with request trigger to SafeBrowsing CSD servers.
113 TEST_F(PermissionReporterTest, SendReportWithRequestTrigger) {
114 permission_reporter_->SendReport(GURL(kDummyOrigin), kDummyPermission,
115 kDummyAction, kDummySourceUI, true);
116
117 PermissionReport permission_report;
118 ASSERT_TRUE(
119 permission_report.ParseFromString(mock_report_sender_->latest_report()));
120 EXPECT_EQ(PermissionReport::AFTER_GESTURE,
121 static_cast<PermissionReport::RequestTrigger>(
122 permission_report.request_trigger(0)));
123 }
124
125 // Test that PermissionReporter::SendReport sends a serialized report string
111 // with field trials to SafeBrowsing CSD servers. 126 // with field trials to SafeBrowsing CSD servers.
112 TEST_F(PermissionReporterTest, SendReportWithFieldTrials) { 127 TEST_F(PermissionReporterTest, SendReportWithFieldTrials) {
113 typedef std::set<variations::ActiveGroupId, variations::ActiveGroupIdCompare> 128 typedef std::set<variations::ActiveGroupId, variations::ActiveGroupIdCompare>
114 ActiveGroupIdSet; 129 ActiveGroupIdSet;
115 130
116 // Add and activate dummy field trials. 131 // Add and activate dummy field trials.
117 base::FieldTrialList field_trial_list(nullptr); 132 base::FieldTrialList field_trial_list(nullptr);
118 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 133 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
119 base::FieldTrial* trial_one = 134 base::FieldTrial* trial_one =
120 base::FieldTrialList::CreateFieldTrial(kDummyTrialOne, kDummyGroupOne); 135 base::FieldTrialList::CreateFieldTrial(kDummyTrialOne, kDummyGroupOne);
(...skipping 11 matching lines...) Expand all
132 base::FeatureList::SetInstance(std::move(feature_list)); 147 base::FeatureList::SetInstance(std::move(feature_list));
133 148
134 // This is necessary to activate both field trials. 149 // This is necessary to activate both field trials.
135 base::FeatureList::IsEnabled(kFeatureOnByDefault); 150 base::FeatureList::IsEnabled(kFeatureOnByDefault);
136 base::FeatureList::IsEnabled(kFeatureOffByDefault); 151 base::FeatureList::IsEnabled(kFeatureOffByDefault);
137 152
138 EXPECT_TRUE(base::FieldTrialList::IsTrialActive(trial_one->trial_name())); 153 EXPECT_TRUE(base::FieldTrialList::IsTrialActive(trial_one->trial_name()));
139 EXPECT_TRUE(base::FieldTrialList::IsTrialActive(trial_two->trial_name())); 154 EXPECT_TRUE(base::FieldTrialList::IsTrialActive(trial_two->trial_name()));
140 155
141 permission_reporter_->SendReport(GURL(kDummyOrigin), kDummyPermission, 156 permission_reporter_->SendReport(GURL(kDummyOrigin), kDummyPermission,
142 kDummyAction, kDummySourceUI); 157 kDummyAction, kDummySourceUI, false);
143 158
144 PermissionReport permission_report; 159 PermissionReport permission_report;
145 ASSERT_TRUE( 160 ASSERT_TRUE(
146 permission_report.ParseFromString(mock_report_sender_->latest_report())); 161 permission_report.ParseFromString(mock_report_sender_->latest_report()));
147 162
148 variations::ActiveGroupId field_trial_one = 163 variations::ActiveGroupId field_trial_one =
149 variations::MakeActiveGroupId(kDummyTrialOne, kDummyGroupOne); 164 variations::MakeActiveGroupId(kDummyTrialOne, kDummyGroupOne);
150 variations::ActiveGroupId field_trial_two = 165 variations::ActiveGroupId field_trial_two =
151 variations::MakeActiveGroupId(kDummyTrialTwo, kDummyGroupTwo); 166 variations::MakeActiveGroupId(kDummyTrialTwo, kDummyGroupTwo);
152 ActiveGroupIdSet expected_group_ids = {field_trial_one, field_trial_two}; 167 ActiveGroupIdSet expected_group_ids = {field_trial_one, field_trial_two};
153 168
154 EXPECT_EQ(2, permission_report.field_trials().size()); 169 EXPECT_EQ(2, permission_report.field_trials().size());
155 for (auto field_trial : permission_report.field_trials()) { 170 for (auto field_trial : permission_report.field_trials()) {
156 variations::ActiveGroupId group_id = {field_trial.name_id(), 171 variations::ActiveGroupId group_id = {field_trial.name_id(),
157 field_trial.group_id()}; 172 field_trial.group_id()};
158 EXPECT_EQ(1U, expected_group_ids.erase(group_id)); 173 EXPECT_EQ(1U, expected_group_ids.erase(group_id));
159 } 174 }
160 EXPECT_EQ(0U, expected_group_ids.size()); 175 EXPECT_EQ(0U, expected_group_ids.size());
161 } 176 }
162 177
163 } // namespace safe_browsing 178 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698