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

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

Issue 10704026: Reland DownloadItem::Observer::OnDownloadDestroyed() replaces DownloadItem::REMOVING (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lint Created 8 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, Time())); 330 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, Time()));
331 // Create one for now and +/- 1 day. 331 // Create one for now and +/- 1 day.
332 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, now - one_day)); 332 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, now - one_day));
333 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, now)); 333 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, now));
334 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, now + one_day)); 334 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, now + one_day));
335 // Try the other four states. 335 // Try the other four states.
336 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago)); 336 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago));
337 EXPECT_NE(0, in_progress = AddDownload(DownloadItem::IN_PROGRESS, month_ago)); 337 EXPECT_NE(0, in_progress = AddDownload(DownloadItem::IN_PROGRESS, month_ago));
338 EXPECT_NE(0, AddDownload(DownloadItem::CANCELLED, month_ago)); 338 EXPECT_NE(0, AddDownload(DownloadItem::CANCELLED, month_ago));
339 EXPECT_NE(0, AddDownload(DownloadItem::INTERRUPTED, month_ago)); 339 EXPECT_NE(0, AddDownload(DownloadItem::INTERRUPTED, month_ago));
340 EXPECT_EQ(0, AddDownload(DownloadItem::REMOVING, month_ago));
341 340
342 // Test to see if inserts worked. 341 // Test to see if inserts worked.
343 db_->QueryDownloads(&downloads); 342 db_->QueryDownloads(&downloads);
344 EXPECT_EQ(8U, downloads.size()); 343 EXPECT_EQ(8U, downloads.size());
345 344
346 // Try removing from current timestamp. This should delete the one in the 345 // Try removing from current timestamp. This should delete the one in the
347 // future and one very recent one. 346 // future and one very recent one.
348 db_->RemoveDownloadsBetween(now, Time()); 347 db_->RemoveDownloadsBetween(now, Time());
349 db_->QueryDownloads(&downloads); 348 db_->QueryDownloads(&downloads);
350 EXPECT_EQ(6U, downloads.size()); 349 EXPECT_EQ(6U, downloads.size());
(...skipping 16 matching lines...) Expand all
367 downloads[1].start_time.ToInternalValue()); 366 downloads[1].start_time.ToInternalValue());
368 367
369 // Change state so we can delete the downloads. 368 // Change state so we can delete the downloads.
370 DownloadPersistentStoreInfo data; 369 DownloadPersistentStoreInfo data;
371 data.received_bytes = 512; 370 data.received_bytes = 512;
372 data.state = DownloadItem::COMPLETE; 371 data.state = DownloadItem::COMPLETE;
373 data.end_time = base::Time::Now(); 372 data.end_time = base::Time::Now();
374 data.opened = false; 373 data.opened = false;
375 data.db_handle = in_progress; 374 data.db_handle = in_progress;
376 EXPECT_TRUE(db_->UpdateDownload(data)); 375 EXPECT_TRUE(db_->UpdateDownload(data));
376 data.state = DownloadItem::CANCELLED;
377 EXPECT_TRUE(db_->UpdateDownload(data));
377 378
378 // Try removing from Time=0. This should delete all. 379 // Try removing from Time=0. This should delete all.
379 db_->RemoveDownloadsBetween(Time(), Time()); 380 db_->RemoveDownloadsBetween(Time(), Time());
380 db_->QueryDownloads(&downloads); 381 db_->QueryDownloads(&downloads);
381 EXPECT_EQ(0U, downloads.size()); 382 EXPECT_EQ(0U, downloads.size());
382 383
383 // Check removal of downloads stuck in IN_PROGRESS state. 384 // Check removal of downloads stuck in IN_PROGRESS state.
384 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago)); 385 EXPECT_NE(0, AddDownload(DownloadItem::COMPLETE, month_ago));
385 EXPECT_NE(0, AddDownload(DownloadItem::IN_PROGRESS, month_ago)); 386 EXPECT_NE(0, AddDownload(DownloadItem::IN_PROGRESS, month_ago));
386 db_->QueryDownloads(&downloads); 387 db_->QueryDownloads(&downloads);
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 history_service_ = history; 1023 history_service_ = history;
1023 history->ScheduleDBTask(task.get(), &request_consumer); 1024 history->ScheduleDBTask(task.get(), &request_consumer);
1024 request_consumer.CancelAllRequests(); 1025 request_consumer.CancelAllRequests();
1025 CleanupHistoryService(); 1026 CleanupHistoryService();
1026 // WARNING: history has now been deleted. 1027 // WARNING: history has now been deleted.
1027 history = NULL; 1028 history = NULL;
1028 ASSERT_FALSE(task->done_invoked); 1029 ASSERT_FALSE(task->done_invoked);
1029 } 1030 }
1030 1031
1031 } // namespace history 1032 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698