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

Side by Side Diff: components/ukm/ukm_service_unittest.cc

Issue 2736683003: Handle the case where Purge is called while upload is in progress. (Closed)
Patch Set: Created 3 years, 9 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/ukm/ukm_service.h" 5 #include "components/ukm/ukm_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/test/test_simple_task_runner.h" 10 #include "base/test/test_simple_task_runner.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 service.RecordSource(MakeSource("https://google.com", 300)); 181 service.RecordSource(MakeSource("https://google.com", 300));
182 // Includes a Source, so will persist. 182 // Includes a Source, so will persist.
183 service.Flush(); 183 service.Flush();
184 EXPECT_EQ(GetPersistedLogCount(), 1); 184 EXPECT_EQ(GetPersistedLogCount(), 1);
185 185
186 // Current log has no Sources. 186 // Current log has no Sources.
187 service.Flush(); 187 service.Flush();
188 EXPECT_EQ(GetPersistedLogCount(), 1); 188 EXPECT_EQ(GetPersistedLogCount(), 1);
189 } 189 }
190 190
191 TEST_F(UkmServiceTest, PurgeMidUpload) {
192 UkmService service(&prefs_, &client_);
193 EXPECT_EQ(GetPersistedLogCount(), 0);
194 service.Initialize();
195 task_runner_->RunUntilIdle();
196 service.EnableRecording();
197 service.EnableReporting();
198 service.RecordSource(MakeSource("https://google.com", 300));
199 // Should init, generate a log, and start an upload.
200 task_runner_->RunPendingTasks();
201 EXPECT_TRUE(client_.uploader()->is_uploading());
202 // Purge should delete all logs, including the one being sent.
203 service.Purge();
204 // Upload succeeds after logs was deleted.
205 client_.uploader()->CompleteUpload(200);
206 EXPECT_EQ(GetPersistedLogCount(), 0);
207 EXPECT_FALSE(client_.uploader()->is_uploading());
208 }
209
191 } // namespace ukm 210 } // namespace ukm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698