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

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

Issue 13044019: Clean up entries left by crashes in the DownloadDB. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Get around new DCHECK in MockDownloadItemImpl constructor. Created 7 years, 8 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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 EXPECT_TRUE(statement.Step()); 455 EXPECT_TRUE(statement.Step());
456 EXPECT_EQ(1, statement.ColumnInt(0)); 456 EXPECT_EQ(1, statement.ColumnInt(0));
457 457
458 sql::Statement statement1(db.GetUniqueStatement( 458 sql::Statement statement1(db.GetUniqueStatement(
459 "Select Count(*) from downloads_url_chains")); 459 "Select Count(*) from downloads_url_chains"));
460 EXPECT_TRUE(statement1.Step()); 460 EXPECT_TRUE(statement1.Step());
461 EXPECT_EQ(1, statement1.ColumnInt(0)); 461 EXPECT_EQ(1, statement1.ColumnInt(0));
462 } 462 }
463 } 463 }
464 464
465 TEST_F(HistoryBackendDBTest, ConfirmDownloadInProgressCleanup) {
466 // Create the DB.
467 CreateBackendAndDatabase();
468
469 base::Time now(base::Time::Now());
470
471 // Put an IN_PROGRESS download in the DB.
472 AddDownload(DownloadItem::IN_PROGRESS, now);
473
474 // Confirm that they made it into the DB unchanged.
475 DeleteBackend();
476 {
477 sql::Connection db;
478 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
479 sql::Statement statement(db.GetUniqueStatement(
480 "Select Count(*) from downloads"));
481 EXPECT_TRUE(statement.Step());
482 EXPECT_EQ(1, statement.ColumnInt(0));
483
484 sql::Statement statement1(db.GetUniqueStatement(
485 "Select state, interrupt_reason from downloads"));
486 EXPECT_TRUE(statement1.Step());
487 EXPECT_EQ(DownloadDatabase::kStateInProgress, statement1.ColumnInt(0));
488 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, statement1.ColumnInt(1));
489 EXPECT_FALSE(statement1.Step());
490 }
491
492 // Read in the DB through query downloads, then test that the
493 // right transformation was returned.
494 CreateBackendAndDatabase();
495 std::vector<DownloadRow> results;
496 db_->QueryDownloads(&results);
497 ASSERT_EQ(1u, results.size());
498 EXPECT_EQ(content::DownloadItem::INTERRUPTED, results[0].state);
499 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_CRASH,
500 results[0].interrupt_reason);
501
502 // Allow the update to propagate, shut down the DB, and confirm that
503 // the query updated the on disk database as well.
504 MessageLoop::current()->RunUntilIdle();
505 DeleteBackend();
506 {
507 sql::Connection db;
508 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
509 sql::Statement statement(db.GetUniqueStatement(
510 "Select Count(*) from downloads"));
511 EXPECT_TRUE(statement.Step());
512 EXPECT_EQ(1, statement.ColumnInt(0));
513
514 sql::Statement statement1(db.GetUniqueStatement(
515 "Select state, interrupt_reason from downloads"));
516 EXPECT_TRUE(statement1.Step());
517 EXPECT_EQ(DownloadDatabase::kStateInterrupted, statement1.ColumnInt(0));
518 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_CRASH,
519 statement1.ColumnInt(1));
520 EXPECT_FALSE(statement1.Step());
521 }
522 }
523
465 struct InterruptReasonAssociation { 524 struct InterruptReasonAssociation {
466 std::string name; 525 std::string name;
467 int value; 526 int value;
468 }; 527 };
469 528
470 // Test is dependent on interrupt reasons being listed in header file 529 // Test is dependent on interrupt reasons being listed in header file
471 // in order. 530 // in order.
472 const InterruptReasonAssociation current_reasons[] = { 531 const InterruptReasonAssociation current_reasons[] = {
473 #define INTERRUPT_REASON(a, b) { #a, b }, 532 #define INTERRUPT_REASON(a, b) { #a, b },
474 #include "content/public/browser/download_interrupt_reason_values.h" 533 #include "content/public/browser/download_interrupt_reason_values.h"
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 ASSERT_EQ(1u, results.size()); 1636 ASSERT_EQ(1u, results.size());
1578 EXPECT_EQ(url, results[0]->GetURL()); 1637 EXPECT_EQ(url, results[0]->GetURL());
1579 EXPECT_EQ(segment_id, results[0]->GetID()); 1638 EXPECT_EQ(segment_id, results[0]->GetID());
1580 EXPECT_EQ(title, results[0]->GetTitle()); 1639 EXPECT_EQ(title, results[0]->GetTitle());
1581 STLDeleteElements(&results); 1640 STLDeleteElements(&results);
1582 } 1641 }
1583 1642
1584 } // namespace 1643 } // namespace
1585 1644
1586 } // namespace history 1645 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698