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

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

Issue 348433004: Prune all safe browsing incidents when already reported. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more test cleanups Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/safe_browsing/incident_reporting_service.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/incident_reporting_service.h" 5 #include "chrome/browser/safe_browsing/incident_reporting_service.h"
6 6
7 #include <map>
7 #include <string> 8 #include <string>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/test_simple_task_runner.h" 14 #include "base/test/test_simple_task_runner.h"
13 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
14 #include "base/threading/thread_local.h" 16 #include "base/threading/thread_local.h"
15 #include "chrome/browser/prefs/browser_prefs.h" 17 #include "chrome/browser/prefs/browser_prefs.h"
16 #include "chrome/browser/safe_browsing/incident_report_uploader.h" 18 #include "chrome/browser/safe_browsing/incident_report_uploader.h"
17 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
18 #include "chrome/common/safe_browsing/csd.pb.h" 20 #include "chrome/common/safe_browsing/csd.pb.h"
19 #include "chrome/test/base/scoped_testing_local_state.h"
20 #include "chrome/test/base/testing_browser_process.h" 21 #include "chrome/test/base/testing_browser_process.h"
21 #include "chrome/test/base/testing_pref_service_syncable.h" 22 #include "chrome/test/base/testing_pref_service_syncable.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
24 #include "chrome/test/base/testing_profile_manager.h"
23 #include "net/url_request/url_request_context_getter.h" 25 #include "net/url_request/url_request_context_getter.h"
24 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
25 27
26 // A test fixture that sets up a test task runner and makes it the thread's 28 // A test fixture that sets up a test task runner and makes it the thread's
27 // runner. The fixture implements a fake envrionment data collector and a fake 29 // runner. The fixture implements a fake envrionment data collector and a fake
28 // report uploader. 30 // report uploader.
29 class IncidentReportingServiceTest : public testing::Test { 31 class IncidentReportingServiceTest : public testing::Test {
30 protected: 32 protected:
31 // An IRS class that allows a test harness to provide a fake environment 33 // An IRS class that allows a test harness to provide a fake environment
32 // collector and report uploader via callbacks. 34 // collector and report uploader via callbacks.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 }; 85 };
84 86
85 static base::LazyInstance<base::ThreadLocalPointer< 87 static base::LazyInstance<base::ThreadLocalPointer<
86 TestIncidentReportingService> >::Leaky test_instance_; 88 TestIncidentReportingService> >::Leaky test_instance_;
87 89
88 PreProfileCreateCallback pre_profile_create_callback_; 90 PreProfileCreateCallback pre_profile_create_callback_;
89 CollectEnvironmentCallback collect_environment_callback_; 91 CollectEnvironmentCallback collect_environment_callback_;
90 StartUploadCallback start_upload_callback_; 92 StartUploadCallback start_upload_callback_;
91 }; 93 };
92 94
95 // A type for specifying whether or not a profile created by CreateProfile
96 // participates in safe browsing.
97 enum SafeBrowsingDisposition {
98 SAFE_BROWSING_OPT_OUT,
99 SAFE_BROWSING_OPT_IN,
100 };
101
102 // A type for specifying the action to be taken by the test fixture during
103 // profile initialization (before NOTIFICATION_PROFILE_CREATED is sent).
104 enum OnProfileCreationAction {
105 ON_PROFILE_CREATION_NO_ACTION,
106 ON_PROFILE_CREATION_ADD_INCIDENT, // Add an incident to the service.
107 };
108
93 static const int64 kIncidentTimeMsec; 109 static const int64 kIncidentTimeMsec;
94 static const char kFakeOsName[]; 110 static const char kFakeOsName[];
95 111
96 IncidentReportingServiceTest() 112 IncidentReportingServiceTest()
97 : task_runner_(new base::TestSimpleTaskRunner), 113 : task_runner_(new base::TestSimpleTaskRunner),
98 thread_task_runner_handle_(task_runner_), 114 thread_task_runner_handle_(task_runner_),
99 local_state_(TestingBrowserProcess::GetGlobal()), 115 profile_manager_(TestingBrowserProcess::GetGlobal()),
100 instance_(new TestIncidentReportingService( 116 instance_(new TestIncidentReportingService(
101 task_runner_, 117 task_runner_,
102 base::Bind(&IncidentReportingServiceTest::PreProfileCreate, 118 base::Bind(&IncidentReportingServiceTest::PreProfileCreate,
103 base::Unretained(this)), 119 base::Unretained(this)),
104 base::Bind(&IncidentReportingServiceTest::CollectEnvironmentData, 120 base::Bind(&IncidentReportingServiceTest::CollectEnvironmentData,
105 base::Unretained(this)), 121 base::Unretained(this)),
106 base::Bind(&IncidentReportingServiceTest::StartUpload, 122 base::Bind(&IncidentReportingServiceTest::StartUpload,
107 base::Unretained(this)))), 123 base::Unretained(this)))),
108 upload_result_(safe_browsing::IncidentReportUploader::UPLOAD_SUCCESS), 124 upload_result_(safe_browsing::IncidentReportUploader::UPLOAD_SUCCESS),
109 environment_collected_(), 125 environment_collected_(),
110 uploader_destroyed_() {} 126 uploader_destroyed_() {}
111 127
112 // Begins the test by creating a profile. An incident will be created within 128 virtual void SetUp() OVERRIDE {
113 // PreProfileCreate. Tasks are run to allow the service to operate to 129 testing::Test::SetUp();
114 // completion. 130 ASSERT_TRUE(profile_manager_.SetUp());
115 void CreateProfileAndRunTest(bool safe_browsing_enabled) { 131 }
132
133 // Creates and returns a profile (owned by the profile manager) with or
134 // without safe browsing enabled. An incident will be created within
135 // PreProfileCreate if requested.
136 TestingProfile* CreateProfile(const std::string& profile_name,
137 SafeBrowsingDisposition safe_browsing_opt_in,
138 OnProfileCreationAction on_creation_action) {
116 // Create prefs for the profile with safe browsing enabled or not. 139 // Create prefs for the profile with safe browsing enabled or not.
117 scoped_ptr<TestingPrefServiceSyncable> prefs( 140 scoped_ptr<TestingPrefServiceSyncable> prefs(
118 new TestingPrefServiceSyncable); 141 new TestingPrefServiceSyncable);
119 chrome::RegisterUserProfilePrefs(prefs->registry()); 142 chrome::RegisterUserProfilePrefs(prefs->registry());
120 prefs->SetBoolean(prefs::kSafeBrowsingEnabled, safe_browsing_enabled); 143 prefs->SetBoolean(prefs::kSafeBrowsingEnabled,
144 safe_browsing_opt_in == SAFE_BROWSING_OPT_IN);
121 145
122 // Build the test profile (PreProfileCreate will be called). 146 // Remember whether or not to create an incident.
123 TestingProfile::Builder builder; 147 profile_properties_[profile_name].on_creation_action = on_creation_action;
124 builder.SetPrefService(prefs.PassAs<PrefServiceSyncable>());
125 testing_profile_ = builder.Build().Pass();
126 148
127 // Let all tasks run. 149 // Boom (or fizzle).
128 task_runner_->RunUntilIdle(); 150 return profile_manager_.CreateTestingProfile(
151 profile_name,
152 prefs.PassAs<PrefServiceSyncable>(),
153 base::ASCIIToUTF16(profile_name),
154 0, // avatar_id (unused)
155 std::string(), // supervised_user_id (unused)
156 TestingProfile::TestingFactories());
157 }
158
159 // Configures a callback to run when the next upload is started that will post
160 // a task to delete the profile. This task will run before the upload
161 // finishes.
162 void DeleteProfileOnUpload(Profile* profile) {
163 ASSERT_TRUE(on_start_upload_callback_.is_null());
164 on_start_upload_callback_ =
165 base::Bind(&IncidentReportingServiceTest::DelayedDeleteProfile,
166 base::Unretained(this),
167 profile);
129 } 168 }
130 169
131 // Returns an incident suitable for testing. 170 // Returns an incident suitable for testing.
132 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> 171 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData>
133 MakeTestIncident() { 172 MakeTestIncident() {
134 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident( 173 scoped_ptr<safe_browsing::ClientIncidentReport_IncidentData> incident(
135 new safe_browsing::ClientIncidentReport_IncidentData()); 174 new safe_browsing::ClientIncidentReport_IncidentData());
136 incident->set_incident_time_msec(kIncidentTimeMsec); 175 incident->set_incident_time_msec(kIncidentTimeMsec);
137 incident->mutable_tracked_preference(); 176 incident->mutable_tracked_preference();
138 return incident.Pass(); 177 return incident.Pass();
139 } 178 }
140 179
141 // Confirms that the test incident was uploaded by the service. 180 // Adds a test incident to the service.
181 void AddTestIncident(Profile* profile) {
182 instance_->GetAddIncidentCallback(profile).Run(MakeTestIncident().Pass());
183 }
184
185 // Confirms that the test incident was uploaded by the service, then clears
186 // the instance for subsequent incidents.
142 void ExpectTestIncidentUploaded() { 187 void ExpectTestIncidentUploaded() {
143 ASSERT_TRUE(uploaded_report_); 188 ASSERT_TRUE(uploaded_report_);
144 ASSERT_EQ(1, uploaded_report_->incident_size()); 189 ASSERT_EQ(1, uploaded_report_->incident_size());
145 ASSERT_TRUE(uploaded_report_->incident(0).has_incident_time_msec()); 190 ASSERT_TRUE(uploaded_report_->incident(0).has_incident_time_msec());
146 ASSERT_EQ(kIncidentTimeMsec, 191 ASSERT_EQ(kIncidentTimeMsec,
147 uploaded_report_->incident(0).incident_time_msec()); 192 uploaded_report_->incident(0).incident_time_msec());
148 ASSERT_TRUE(uploaded_report_->has_environment()); 193 ASSERT_TRUE(uploaded_report_->has_environment());
149 ASSERT_TRUE(uploaded_report_->environment().has_os()); 194 ASSERT_TRUE(uploaded_report_->environment().has_os());
150 ASSERT_TRUE(uploaded_report_->environment().os().has_os_name()); 195 ASSERT_TRUE(uploaded_report_->environment().os().has_os_name());
151 ASSERT_EQ(std::string(kFakeOsName), 196 ASSERT_EQ(std::string(kFakeOsName),
152 uploaded_report_->environment().os().os_name()); 197 uploaded_report_->environment().os().os_name());
198
199 uploaded_report_.reset();
153 } 200 }
154 201
155 void ExpectNoUpload() { ASSERT_FALSE(uploaded_report_); } 202 void ExpectNoUpload() { ASSERT_FALSE(uploaded_report_); }
156 203
157 bool HasCollectedEnvironmentData() const { return environment_collected_; } 204 bool HasCollectedEnvironmentData() const { return environment_collected_; }
158 bool UploaderDestroyed() const { return uploader_destroyed_; } 205 bool UploaderDestroyed() const { return uploader_destroyed_; }
159 206
160 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 207 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
161 base::ThreadTaskRunnerHandle thread_task_runner_handle_; 208 base::ThreadTaskRunnerHandle thread_task_runner_handle_;
162 ScopedTestingLocalState local_state_; 209 TestingProfileManager profile_manager_;
163 scoped_ptr<safe_browsing::IncidentReportingService> instance_; 210 scoped_ptr<safe_browsing::IncidentReportingService> instance_;
211 base::Closure on_start_upload_callback_;
164 safe_browsing::IncidentReportUploader::Result upload_result_; 212 safe_browsing::IncidentReportUploader::Result upload_result_;
165 bool environment_collected_; 213 bool environment_collected_;
166 scoped_ptr<safe_browsing::ClientIncidentReport> uploaded_report_; 214 scoped_ptr<safe_browsing::ClientIncidentReport> uploaded_report_;
167 bool uploader_destroyed_; 215 bool uploader_destroyed_;
168 scoped_ptr<TestingProfile> testing_profile_;
169 216
170 private: 217 private:
171 // A fake IncidentReportUploader that posts a task to provide a given response 218 // A fake IncidentReportUploader that posts a task to provide a given response
172 // back to the incident reporting service. It also reports back to the test 219 // back to the incident reporting service. It also reports back to the test
173 // harness via a closure when it is deleted by the incident reporting service. 220 // harness via a closure when it is deleted by the incident reporting service.
174 class FakeUploader : public safe_browsing::IncidentReportUploader { 221 class FakeUploader : public safe_browsing::IncidentReportUploader {
175 public: 222 public:
176 FakeUploader( 223 FakeUploader(
177 const base::Closure& on_deleted, 224 const base::Closure& on_deleted,
178 const safe_browsing::IncidentReportUploader::OnResultCallback& callback, 225 const safe_browsing::IncidentReportUploader::OnResultCallback& callback,
(...skipping 15 matching lines...) Expand all
194 callback_.Run(result_, 241 callback_.Run(result_,
195 scoped_ptr<safe_browsing::ClientIncidentResponse>()); 242 scoped_ptr<safe_browsing::ClientIncidentResponse>());
196 } 243 }
197 244
198 base::Closure on_deleted_; 245 base::Closure on_deleted_;
199 safe_browsing::IncidentReportUploader::Result result_; 246 safe_browsing::IncidentReportUploader::Result result_;
200 247
201 DISALLOW_COPY_AND_ASSIGN(FakeUploader); 248 DISALLOW_COPY_AND_ASSIGN(FakeUploader);
202 }; 249 };
203 250
251 // Properties for a profile that impact the behavior of the test.
252 struct ProfileProperties {
253 ProfileProperties() : on_creation_action(ON_PROFILE_CREATION_NO_ACTION) {}
254
255 // The action taken by the test fixture during profile initialization
256 // (before NOTIFICATION_PROFILE_CREATED is sent).
257 OnProfileCreationAction on_creation_action;
258 };
259
260 // Returns the name of a profile as provided to CreateProfile.
261 static std::string GetProfileName(Profile* profile) {
262 // Cannot reliably use profile->GetProfileName() since the test needs the
263 // name before the profile manager sets it (which happens after profile
264 // creation).
265 return profile->GetPath().BaseName().AsUTF8Unsafe();
266 }
267
268 // Posts a task to delete the profile.
269 void DelayedDeleteProfile(Profile* profile) {
270 base::ThreadTaskRunnerHandle::Get()->PostTask(
271 FROM_HERE,
272 base::Bind(&TestingProfileManager::DeleteTestingProfile,
273 base::Unretained(&profile_manager_),
274 GetProfileName(profile)));
275 }
276
204 // A callback run by the test fixture when a profile is created. An incident 277 // A callback run by the test fixture when a profile is created. An incident
205 // is added. 278 // is added.
206 void PreProfileCreate(Profile* profile) { 279 void PreProfileCreate(Profile* profile) {
207 // The instance must have already been created. 280 // The instance must have already been created.
208 ASSERT_TRUE(instance_); 281 ASSERT_TRUE(instance_);
209 // Add a test incident to the service. 282 // Add a test incident to the service if requested.
210 instance_->GetAddIncidentCallback(profile).Run(MakeTestIncident().Pass()); 283 switch (profile_properties_[GetProfileName(profile)].on_creation_action) {
284 case ON_PROFILE_CREATION_ADD_INCIDENT:
285 AddTestIncident(profile);
286 break;
287 default:
288 ASSERT_EQ(
289 ON_PROFILE_CREATION_NO_ACTION,
290 profile_properties_[GetProfileName(profile)].on_creation_action);
291 break;
292 }
211 } 293 }
212 294
213 // A fake CollectEnvironmentData implementation invoked by the service during 295 // A fake CollectEnvironmentData implementation invoked by the service during
214 // operation. 296 // operation.
215 void CollectEnvironmentData( 297 void CollectEnvironmentData(
216 safe_browsing::ClientIncidentReport_EnvironmentData* data) { 298 safe_browsing::ClientIncidentReport_EnvironmentData* data) {
217 ASSERT_NE( 299 ASSERT_NE(
218 static_cast<safe_browsing::ClientIncidentReport_EnvironmentData*>(NULL), 300 static_cast<safe_browsing::ClientIncidentReport_EnvironmentData*>(NULL),
219 data); 301 data);
220 data->mutable_os()->set_os_name(kFakeOsName); 302 data->mutable_os()->set_os_name(kFakeOsName);
221 environment_collected_ = true; 303 environment_collected_ = true;
222 } 304 }
223 305
224 // A fake StartUpload implementation invoked by the service during operation. 306 // A fake StartUpload implementation invoked by the service during operation.
225 scoped_ptr<safe_browsing::IncidentReportUploader> StartUpload( 307 scoped_ptr<safe_browsing::IncidentReportUploader> StartUpload(
226 const safe_browsing::IncidentReportUploader::OnResultCallback& callback, 308 const safe_browsing::IncidentReportUploader::OnResultCallback& callback,
227 const safe_browsing::ClientIncidentReport& report) { 309 const safe_browsing::ClientIncidentReport& report) {
228 // Remember the report that is being uploaded. 310 // Remember the report that is being uploaded.
229 uploaded_report_.reset(new safe_browsing::ClientIncidentReport(report)); 311 uploaded_report_.reset(new safe_browsing::ClientIncidentReport(report));
312 // Run and clear the OnStartUpload callback, if provided.
313 if (!on_start_upload_callback_.is_null()) {
314 on_start_upload_callback_.Run();
315 on_start_upload_callback_ = base::Closure();
316 }
230 return scoped_ptr<safe_browsing::IncidentReportUploader>(new FakeUploader( 317 return scoped_ptr<safe_browsing::IncidentReportUploader>(new FakeUploader(
231 base::Bind(&IncidentReportingServiceTest::OnUploaderDestroyed, 318 base::Bind(&IncidentReportingServiceTest::OnUploaderDestroyed,
232 base::Unretained(this)), 319 base::Unretained(this)),
233 callback, 320 callback,
234 upload_result_)); 321 upload_result_));
235 } 322 }
236 323
237 void OnUploaderDestroyed() { uploader_destroyed_ = true; } 324 void OnUploaderDestroyed() { uploader_destroyed_ = true; }
325
326 // A mapping of profile name to its corresponding properties.
327 std::map<std::string, ProfileProperties> profile_properties_;
238 }; 328 };
239 329
240 // static 330 // static
241 base::LazyInstance<base::ThreadLocalPointer< 331 base::LazyInstance<base::ThreadLocalPointer<
242 IncidentReportingServiceTest::TestIncidentReportingService> >::Leaky 332 IncidentReportingServiceTest::TestIncidentReportingService> >::Leaky
243 IncidentReportingServiceTest::TestIncidentReportingService::test_instance_ = 333 IncidentReportingServiceTest::TestIncidentReportingService::test_instance_ =
244 LAZY_INSTANCE_INITIALIZER; 334 LAZY_INSTANCE_INITIALIZER;
245 335
246 // static
247 const int64 IncidentReportingServiceTest::kIncidentTimeMsec = 47LL; 336 const int64 IncidentReportingServiceTest::kIncidentTimeMsec = 47LL;
248 const char IncidentReportingServiceTest::kFakeOsName[] = "fakedows"; 337 const char IncidentReportingServiceTest::kFakeOsName[] = "fakedows";
249 338
250 // Tests that an incident added during profile initialization when safe browsing 339 // Tests that an incident added during profile initialization when safe browsing
251 // is on is uploaded. 340 // is on is uploaded.
252 TEST_F(IncidentReportingServiceTest, AddIncident) { 341 TEST_F(IncidentReportingServiceTest, AddIncident) {
253 // Create the profile, thereby causing the test to begin. 342 CreateProfile(
254 CreateProfileAndRunTest(true); 343 "profile1", SAFE_BROWSING_OPT_IN, ON_PROFILE_CREATION_ADD_INCIDENT);
344
345 // Let all tasks run.
346 task_runner_->RunUntilIdle();
255 347
256 // Verify that environment collection took place. 348 // Verify that environment collection took place.
257 EXPECT_TRUE(HasCollectedEnvironmentData()); 349 EXPECT_TRUE(HasCollectedEnvironmentData());
258 350
259 // Verify that report upload took place and contained the incident and 351 // Verify that report upload took place and contained the incident and
260 // environment data. 352 // environment data.
261 ExpectTestIncidentUploaded(); 353 ExpectTestIncidentUploaded();
262 354
263 // Verify that the uploader was destroyed. 355 // Verify that the uploader was destroyed.
264 ASSERT_TRUE(UploaderDestroyed()); 356 ASSERT_TRUE(UploaderDestroyed());
265 } 357 }
266 358
267 // Tests that an incident added during profile initialization when safe browsing 359 // Tests that an incident added during profile initialization when safe browsing
268 // is off is not uploaded. 360 // is off is not uploaded.
269 TEST_F(IncidentReportingServiceTest, NoSafeBrowsing) { 361 TEST_F(IncidentReportingServiceTest, NoSafeBrowsing) {
270 // Create the profile, thereby causing the test to begin. 362 // Create the profile, thereby causing the test to begin.
271 CreateProfileAndRunTest(false); 363 CreateProfile(
364 "profile1", SAFE_BROWSING_OPT_OUT, ON_PROFILE_CREATION_ADD_INCIDENT);
365
366 // Let all tasks run.
367 task_runner_->RunUntilIdle();
272 368
273 // Verify that no report upload took place. 369 // Verify that no report upload took place.
274 ExpectNoUpload(); 370 ExpectNoUpload();
275 } 371 }
276 372
373 // Tests that an incident added after upload is not uploaded again.
374 TEST_F(IncidentReportingServiceTest, OnlyOneUpload) {
375 // Create the profile, thereby causing the test to begin.
376 Profile* profile = CreateProfile(
377 "profile1", SAFE_BROWSING_OPT_IN, ON_PROFILE_CREATION_ADD_INCIDENT);
378
379 // Let all tasks run.
380 task_runner_->RunUntilIdle();
381
382 // Verify that report upload took place and contained the incident and
383 // environment data.
384 ExpectTestIncidentUploaded();
385
386 // Add the incident to the service again.
387 AddTestIncident(profile);
388
389 // Let all tasks run.
390 task_runner_->RunUntilIdle();
391
392 // Verify that no additional report upload took place.
393 ExpectNoUpload();
394 }
395
396 // Tests that the same incident added for two different profiles in sequence
397 // results in two uploads.
398 TEST_F(IncidentReportingServiceTest, TwoProfilesTwoUploads) {
399 // Create the profile, thereby causing the test to begin.
400 CreateProfile(
401 "profile1", SAFE_BROWSING_OPT_IN, ON_PROFILE_CREATION_ADD_INCIDENT);
402
403 // Let all tasks run.
404 task_runner_->RunUntilIdle();
405
406 // Verify that report upload took place and contained the incident and
407 // environment data.
408 ExpectTestIncidentUploaded();
409
410 // Create a second profile with its own incident on creation.
411 CreateProfile(
412 "profile2", SAFE_BROWSING_OPT_IN, ON_PROFILE_CREATION_ADD_INCIDENT);
413
414 // Let all tasks run.
415 task_runner_->RunUntilIdle();
416
417 // Verify that a second report upload took place.
418 ExpectTestIncidentUploaded();
419 }
420
421 // Tests that an upload succeeds if the profile is destroyed while it is
422 // pending.
423 TEST_F(IncidentReportingServiceTest, ProfileDestroyedDuringUpload) {
424 // Create a profile for which an incident will be added.
425 Profile* profile = CreateProfile(
426 "profile1", SAFE_BROWSING_OPT_IN, ON_PROFILE_CREATION_ADD_INCIDENT);
427
428 // Hook up a callback to run when the upload is started that will post a task
429 // to delete the profile. This task will run before the upload finishes.
430 DeleteProfileOnUpload(profile);
431
432 // Let all tasks run.
433 task_runner_->RunUntilIdle();
434
435 // Verify that report upload took place and contained the incident and
436 // environment data.
437 ExpectTestIncidentUploaded();
438
439 // The lack of a crash indicates that the deleted profile was not accessed by
440 // the service while handling the upload response.
441 }
442
277 // Parallel uploads 443 // Parallel uploads
278 // Shutdown during processing 444 // Shutdown during processing
279 // environment colection taking longer than incident delay timer 445 // environment colection taking longer than incident delay timer
280 // environment colection taking longer than incident delay timer, and then 446 // environment colection taking longer than incident delay timer, and then
281 // another incident arriving 447 // another incident arriving
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/incident_reporting_service.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698