OLD | NEW |
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 "base/test/simple_test_clock.h" | 10 #include "base/test/simple_test_clock.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 EXPECT_EQ(PermissionReport::ANDROID_PLATFORM, | 111 EXPECT_EQ(PermissionReport::ANDROID_PLATFORM, |
112 permission_report.platform_type()); | 112 permission_report.platform_type()); |
113 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ | 113 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ |
114 defined(OS_LINUX) | 114 defined(OS_LINUX) |
115 EXPECT_EQ(PermissionReport::DESKTOP_PLATFORM, | 115 EXPECT_EQ(PermissionReport::DESKTOP_PLATFORM, |
116 permission_report.platform_type()); | 116 permission_report.platform_type()); |
117 #endif | 117 #endif |
118 | 118 |
119 EXPECT_EQ(GURL(kPermissionActionReportingUploadUrl), | 119 EXPECT_EQ(GURL(kPermissionActionReportingUploadUrl), |
120 mock_report_sender_->latest_report_uri()); | 120 mock_report_sender_->latest_report_uri()); |
| 121 EXPECT_EQ("application/octet-stream", |
| 122 mock_report_sender_->latest_content_type()); |
121 } | 123 } |
122 | 124 |
123 // Test that PermissionReporter::SendReport sends a serialized report string | 125 // Test that PermissionReporter::SendReport sends a serialized report string |
124 // with field trials to SafeBrowsing CSD servers. | 126 // with field trials to SafeBrowsing CSD servers. |
125 TEST_F(PermissionReporterTest, SendReportWithFieldTrials) { | 127 TEST_F(PermissionReporterTest, SendReportWithFieldTrials) { |
126 typedef std::set<variations::ActiveGroupId, variations::ActiveGroupIdCompare> | 128 typedef std::set<variations::ActiveGroupId, variations::ActiveGroupIdCompare> |
127 ActiveGroupIdSet; | 129 ActiveGroupIdSet; |
128 | 130 |
129 // Add and activate dummy field trials. | 131 // Add and activate dummy field trials. |
130 base::FieldTrialList field_trial_list(nullptr); | 132 base::FieldTrialList field_trial_list(nullptr); |
(...skipping 15 matching lines...) Expand all Loading... |
146 | 148 |
147 // This is necessary to activate both field trials. | 149 // This is necessary to activate both field trials. |
148 base::FeatureList::IsEnabled(kFeatureOnByDefault); | 150 base::FeatureList::IsEnabled(kFeatureOnByDefault); |
149 base::FeatureList::IsEnabled(kFeatureOffByDefault); | 151 base::FeatureList::IsEnabled(kFeatureOffByDefault); |
150 | 152 |
151 EXPECT_TRUE(base::FieldTrialList::IsTrialActive(trial_one->trial_name())); | 153 EXPECT_TRUE(base::FieldTrialList::IsTrialActive(trial_one->trial_name())); |
152 EXPECT_TRUE(base::FieldTrialList::IsTrialActive(trial_two->trial_name())); | 154 EXPECT_TRUE(base::FieldTrialList::IsTrialActive(trial_two->trial_name())); |
153 | 155 |
154 permission_reporter_->SendReport(BuildDummyReportInfo()); | 156 permission_reporter_->SendReport(BuildDummyReportInfo()); |
155 | 157 |
| 158 EXPECT_EQ("application/octet-stream", |
| 159 mock_report_sender_->latest_content_type()); |
| 160 |
156 PermissionReport permission_report; | 161 PermissionReport permission_report; |
157 ASSERT_TRUE( | 162 ASSERT_TRUE( |
158 permission_report.ParseFromString(mock_report_sender_->latest_report())); | 163 permission_report.ParseFromString(mock_report_sender_->latest_report())); |
159 | 164 |
160 variations::ActiveGroupId field_trial_one = | 165 variations::ActiveGroupId field_trial_one = |
161 variations::MakeActiveGroupId(kDummyTrialOne, kDummyGroupOne); | 166 variations::MakeActiveGroupId(kDummyTrialOne, kDummyGroupOne); |
162 variations::ActiveGroupId field_trial_two = | 167 variations::ActiveGroupId field_trial_two = |
163 variations::MakeActiveGroupId(kDummyTrialTwo, kDummyGroupTwo); | 168 variations::MakeActiveGroupId(kDummyTrialTwo, kDummyGroupTwo); |
164 ActiveGroupIdSet expected_group_ids = {field_trial_one, field_trial_two}; | 169 ActiveGroupIdSet expected_group_ids = {field_trial_one, field_trial_two}; |
165 | 170 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 reports_to_send = 12; | 210 reports_to_send = 12; |
206 while (reports_to_send--) { | 211 while (reports_to_send--) { |
207 clock_->Advance(base::TimeDelta::FromSeconds(5)); | 212 clock_->Advance(base::TimeDelta::FromSeconds(5)); |
208 permission_reporter_->SendReport(BuildDummyReportInfo()); | 213 permission_reporter_->SendReport(BuildDummyReportInfo()); |
209 } | 214 } |
210 EXPECT_EQ(kMaximumReportsPerOriginPerPermissionPerMinute, | 215 EXPECT_EQ(kMaximumReportsPerOriginPerPermissionPerMinute, |
211 mock_report_sender_->GetAndResetNumberOfReportsSent()); | 216 mock_report_sender_->GetAndResetNumberOfReportsSent()); |
212 } | 217 } |
213 | 218 |
214 } // namespace safe_browsing | 219 } // namespace safe_browsing |
OLD | NEW |