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

Side by Side Diff: chrome/browser/history/history_unittest.cc

Issue 8008021: Add new UMA stats to get a handle on Downloads UI Usage (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: comments Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // History unit tests come in two flavors: 5 // History unit tests come in two flavors:
6 // 6 //
7 // 1. The more complicated style is that the unit test creates a full history 7 // 1. The more complicated style is that the unit test creates a full history
8 // service. This spawns a background thread for the history backend, and 8 // service. This spawns a background thread for the history backend, and
9 // all communication is asynchronous. This is useful for testing more 9 // all communication is asynchronous. This is useful for testing more
10 // complicated things or end-to-end behavior. 10 // complicated things or end-to-end behavior.
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // our destroy task. 184 // our destroy task.
185 MessageLoop::current()->Run(); 185 MessageLoop::current()->Run();
186 } 186 }
187 187
188 int64 AddDownload(int32 state, const Time& time) { 188 int64 AddDownload(int32 state, const Time& time) {
189 DownloadPersistentStoreInfo download( 189 DownloadPersistentStoreInfo download(
190 FilePath(FILE_PATH_LITERAL("foo-path")), 190 FilePath(FILE_PATH_LITERAL("foo-path")),
191 GURL("foo-url"), 191 GURL("foo-url"),
192 GURL(""), 192 GURL(""),
193 time, 193 time,
194 time,
194 0, 195 0,
195 512, 196 512,
196 state, 197 state,
198 0,
197 0); 199 0);
198 return db_->CreateDownload(download); 200 return db_->CreateDownload(download);
199 } 201 }
200 202
201 // Fills the query_url_row_ and query_url_visits_ structures with the 203 // Fills the query_url_row_ and query_url_visits_ structures with the
202 // information about the given URL and returns true. If the URL was not 204 // information about the given URL and returns true. If the URL was not
203 // found, this will return false and those structures will not be changed. 205 // found, this will return false and those structures will not be changed.
204 bool QueryURL(HistoryService* history, const GURL& url) { 206 bool QueryURL(HistoryService* history, const GURL& url) {
205 history->QueryURL(url, true, &consumer_, 207 history->QueryURL(url, true, &consumer_,
206 NewCallback(this, &HistoryTest::SaveURLAndQuit)); 208 NewCallback(this, &HistoryTest::SaveURLAndQuit));
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state); 360 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state);
359 EXPECT_EQ(0, downloads[0].start_time.ToInternalValue()); 361 EXPECT_EQ(0, downloads[0].start_time.ToInternalValue());
360 EXPECT_EQ(DownloadItem::IN_PROGRESS, downloads[1].state); 362 EXPECT_EQ(DownloadItem::IN_PROGRESS, downloads[1].state);
361 EXPECT_EQ(month_ago_lossy.ToInternalValue(), 363 EXPECT_EQ(month_ago_lossy.ToInternalValue(),
362 downloads[1].start_time.ToInternalValue()); 364 downloads[1].start_time.ToInternalValue());
363 EXPECT_EQ(DownloadItem::REMOVING, downloads[2].state); 365 EXPECT_EQ(DownloadItem::REMOVING, downloads[2].state);
364 EXPECT_EQ(month_ago_lossy.ToInternalValue(), 366 EXPECT_EQ(month_ago_lossy.ToInternalValue(),
365 downloads[2].start_time.ToInternalValue()); 367 downloads[2].start_time.ToInternalValue());
366 368
367 // Change state so we can delete the downloads. 369 // Change state so we can delete the downloads.
368 EXPECT_TRUE(db_->UpdateDownload(512, DownloadItem::COMPLETE, in_progress)); 370 history::DownloadItemData data;
369 EXPECT_TRUE(db_->UpdateDownload(512, DownloadItem::CANCELLED, removing)); 371 data.received_bytes = 512;
372 data.state = DownloadItem::COMPLETE;
373 data.end_time = base::Time::Now();
374 data.opened = false;
375 data.db_handle = in_progress;
376 EXPECT_TRUE(db_->UpdateDownload(data));
377 data.state = DownloadItem::CANCELLED;
378 data.db_handle = removing;
379 EXPECT_TRUE(db_->UpdateDownload(data));
370 380
371 // Try removing from Time=0. This should delete all. 381 // Try removing from Time=0. This should delete all.
372 db_->RemoveDownloadsBetween(Time(), Time()); 382 db_->RemoveDownloadsBetween(Time(), Time());
373 db_->QueryDownloads(&downloads); 383 db_->QueryDownloads(&downloads);
374 EXPECT_EQ(0U, downloads.size()); 384 EXPECT_EQ(0U, downloads.size());
375 385
376 // Check removal of downloads stuck in IN_PROGRESS state. 386 // Check removal of downloads stuck in IN_PROGRESS state.
377 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago)); 387 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago));
378 EXPECT_NE(0, AddDownload(DownloadItem::IN_PROGRESS, month_ago)); 388 EXPECT_NE(0, AddDownload(DownloadItem::IN_PROGRESS, month_ago));
379 db_->QueryDownloads(&downloads); 389 db_->QueryDownloads(&downloads);
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 history_service_ = history; 869 history_service_ = history;
860 history->ScheduleDBTask(task.get(), &request_consumer); 870 history->ScheduleDBTask(task.get(), &request_consumer);
861 request_consumer.CancelAllRequests(); 871 request_consumer.CancelAllRequests();
862 CleanupHistoryService(); 872 CleanupHistoryService();
863 // WARNING: history has now been deleted. 873 // WARNING: history has now been deleted.
864 history = NULL; 874 history = NULL;
865 ASSERT_FALSE(task->done_invoked); 875 ASSERT_FALSE(task->done_invoked);
866 } 876 }
867 877
868 } // namespace history 878 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698