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

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: merge 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // our destroy task. 186 // our destroy task.
187 MessageLoop::current()->Run(); 187 MessageLoop::current()->Run();
188 } 188 }
189 189
190 int64 AddDownload(int32 state, const Time& time) { 190 int64 AddDownload(int32 state, const Time& time) {
191 DownloadPersistentStoreInfo download( 191 DownloadPersistentStoreInfo download(
192 FilePath(FILE_PATH_LITERAL("foo-path")), 192 FilePath(FILE_PATH_LITERAL("foo-path")),
193 GURL("foo-url"), 193 GURL("foo-url"),
194 GURL(""), 194 GURL(""),
195 time, 195 time,
196 time,
196 0, 197 0,
197 512, 198 512,
198 state, 199 state,
200 0,
199 0); 201 0);
200 return db_->CreateDownload(download); 202 return db_->CreateDownload(download);
201 } 203 }
202 204
203 // Fills the query_url_row_ and query_url_visits_ structures with the 205 // Fills the query_url_row_ and query_url_visits_ structures with the
204 // information about the given URL and returns true. If the URL was not 206 // information about the given URL and returns true. If the URL was not
205 // found, this will return false and those structures will not be changed. 207 // found, this will return false and those structures will not be changed.
206 bool QueryURL(HistoryService* history, const GURL& url) { 208 bool QueryURL(HistoryService* history, const GURL& url) {
207 history->QueryURL(url, true, &consumer_, 209 history->QueryURL(url, true, &consumer_,
208 base::Bind(&HistoryTest::SaveURLAndQuit, 210 base::Bind(&HistoryTest::SaveURLAndQuit,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state); 364 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state);
363 EXPECT_EQ(0, downloads[0].start_time.ToInternalValue()); 365 EXPECT_EQ(0, downloads[0].start_time.ToInternalValue());
364 EXPECT_EQ(DownloadItem::IN_PROGRESS, downloads[1].state); 366 EXPECT_EQ(DownloadItem::IN_PROGRESS, downloads[1].state);
365 EXPECT_EQ(month_ago_lossy.ToInternalValue(), 367 EXPECT_EQ(month_ago_lossy.ToInternalValue(),
366 downloads[1].start_time.ToInternalValue()); 368 downloads[1].start_time.ToInternalValue());
367 EXPECT_EQ(DownloadItem::REMOVING, downloads[2].state); 369 EXPECT_EQ(DownloadItem::REMOVING, downloads[2].state);
368 EXPECT_EQ(month_ago_lossy.ToInternalValue(), 370 EXPECT_EQ(month_ago_lossy.ToInternalValue(),
369 downloads[2].start_time.ToInternalValue()); 371 downloads[2].start_time.ToInternalValue());
370 372
371 // Change state so we can delete the downloads. 373 // Change state so we can delete the downloads.
372 EXPECT_TRUE(db_->UpdateDownload(512, DownloadItem::COMPLETE, in_progress)); 374 DownloadPersistentStoreInfo data;
373 EXPECT_TRUE(db_->UpdateDownload(512, DownloadItem::CANCELLED, removing)); 375 data.received_bytes = 512;
376 data.state = DownloadItem::COMPLETE;
377 data.end_time = base::Time::Now();
378 data.opened = false;
379 data.db_handle = in_progress;
380 EXPECT_TRUE(db_->UpdateDownload(data));
381 data.state = DownloadItem::CANCELLED;
382 data.db_handle = removing;
383 EXPECT_TRUE(db_->UpdateDownload(data));
374 384
375 // Try removing from Time=0. This should delete all. 385 // Try removing from Time=0. This should delete all.
376 db_->RemoveDownloadsBetween(Time(), Time()); 386 db_->RemoveDownloadsBetween(Time(), Time());
377 db_->QueryDownloads(&downloads); 387 db_->QueryDownloads(&downloads);
378 EXPECT_EQ(0U, downloads.size()); 388 EXPECT_EQ(0U, downloads.size());
379 389
380 // Check removal of downloads stuck in IN_PROGRESS state. 390 // Check removal of downloads stuck in IN_PROGRESS state.
381 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago)); 391 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago));
382 EXPECT_NE(0, AddDownload(DownloadItem::IN_PROGRESS, month_ago)); 392 EXPECT_NE(0, AddDownload(DownloadItem::IN_PROGRESS, month_ago));
383 db_->QueryDownloads(&downloads); 393 db_->QueryDownloads(&downloads);
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 history_service_ = history; 958 history_service_ = history;
949 history->ScheduleDBTask(task.get(), &request_consumer); 959 history->ScheduleDBTask(task.get(), &request_consumer);
950 request_consumer.CancelAllRequests(); 960 request_consumer.CancelAllRequests();
951 CleanupHistoryService(); 961 CleanupHistoryService();
952 // WARNING: history has now been deleted. 962 // WARNING: history has now been deleted.
953 history = NULL; 963 history = NULL;
954 ASSERT_FALSE(task->done_invoked); 964 ASSERT_FALSE(task->done_invoked);
955 } 965 }
956 966
957 } // namespace history 967 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/ui/cocoa/download/download_shelf_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698