| OLD | NEW |
| 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // Currently, just send the notifications directly to the in-memory database. | 206 // Currently, just send the notifications directly to the in-memory database. |
| 207 // We may want do do something more fancy in the future. | 207 // We may want do do something more fancy in the future. |
| 208 content::Details<HistoryDetails> det(details); | 208 content::Details<HistoryDetails> det(details); |
| 209 history_test_->in_mem_backend_->Observe(type, | 209 history_test_->in_mem_backend_->Observe(type, |
| 210 content::Source<HistoryBackendDBTest>(NULL), det); | 210 content::Source<HistoryBackendDBTest>(NULL), det); |
| 211 | 211 |
| 212 // The backend passes ownership of the details pointer to us. | 212 // The backend passes ownership of the details pointer to us. |
| 213 delete details; | 213 delete details; |
| 214 } | 214 } |
| 215 | 215 |
| 216 namespace { | |
| 217 | |
| 218 TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) { | 216 TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) { |
| 219 CreateBackendAndDatabase(); | 217 CreateBackendAndDatabase(); |
| 220 | 218 |
| 221 // Initially there should be nothing in the downloads database. | 219 // Initially there should be nothing in the downloads database. |
| 222 std::vector<DownloadRow> downloads; | 220 std::vector<DownloadRow> downloads; |
| 223 db_->QueryDownloads(&downloads); | 221 db_->QueryDownloads(&downloads); |
| 224 EXPECT_EQ(0U, downloads.size()); | 222 EXPECT_EQ(0U, downloads.size()); |
| 225 | 223 |
| 226 // Add a download, test that it was added, remove it, test that it was | 224 // Add a download, test that it was added, remove it, test that it was |
| 227 // removed. | 225 // removed. |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 507 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); |
| 510 { | 508 { |
| 511 sql::Statement statement(db.GetUniqueStatement( | 509 sql::Statement statement(db.GetUniqueStatement( |
| 512 "SELECT count(*) from downloads")); | 510 "SELECT count(*) from downloads")); |
| 513 ASSERT_TRUE(statement.Step()); | 511 ASSERT_TRUE(statement.Step()); |
| 514 EXPECT_EQ(0, statement.ColumnInt(0)); | 512 EXPECT_EQ(0, statement.ColumnInt(0)); |
| 515 } | 513 } |
| 516 } | 514 } |
| 517 } | 515 } |
| 518 | 516 |
| 517 TEST_F(HistoryBackendDBTest, ConfirmDownloadInProgressCleanup) { |
| 518 // Create the DB. |
| 519 CreateBackendAndDatabase(); |
| 520 |
| 521 base::Time now(base::Time::Now()); |
| 522 |
| 523 // Put an IN_PROGRESS download in the DB. |
| 524 AddDownload(DownloadItem::IN_PROGRESS, now); |
| 525 |
| 526 // Confirm that they made it into the DB unchanged. |
| 527 DeleteBackend(); |
| 528 { |
| 529 sql::Connection db; |
| 530 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); |
| 531 sql::Statement statement(db.GetUniqueStatement( |
| 532 "Select Count(*) from downloads")); |
| 533 EXPECT_TRUE(statement.Step()); |
| 534 EXPECT_EQ(1, statement.ColumnInt(0)); |
| 535 |
| 536 sql::Statement statement1(db.GetUniqueStatement( |
| 537 "Select state, interrupt_reason from downloads")); |
| 538 EXPECT_TRUE(statement1.Step()); |
| 539 EXPECT_EQ(DownloadDatabase::kStateInProgress, statement1.ColumnInt(0)); |
| 540 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, statement1.ColumnInt(1)); |
| 541 EXPECT_FALSE(statement1.Step()); |
| 542 } |
| 543 |
| 544 // Read in the DB through query downloads, then test that the |
| 545 // right transformation was returned. |
| 546 CreateBackendAndDatabase(); |
| 547 std::vector<DownloadRow> results; |
| 548 db_->QueryDownloads(&results); |
| 549 ASSERT_EQ(1u, results.size()); |
| 550 EXPECT_EQ(content::DownloadItem::INTERRUPTED, results[0].state); |
| 551 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_CRASH, |
| 552 results[0].interrupt_reason); |
| 553 |
| 554 // Allow the update to propagate, shut down the DB, and confirm that |
| 555 // the query updated the on disk database as well. |
| 556 MessageLoop::current()->RunUntilIdle(); |
| 557 DeleteBackend(); |
| 558 { |
| 559 sql::Connection db; |
| 560 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); |
| 561 sql::Statement statement(db.GetUniqueStatement( |
| 562 "Select Count(*) from downloads")); |
| 563 EXPECT_TRUE(statement.Step()); |
| 564 EXPECT_EQ(1, statement.ColumnInt(0)); |
| 565 |
| 566 sql::Statement statement1(db.GetUniqueStatement( |
| 567 "Select state, interrupt_reason from downloads")); |
| 568 EXPECT_TRUE(statement1.Step()); |
| 569 EXPECT_EQ(DownloadDatabase::kStateInterrupted, statement1.ColumnInt(0)); |
| 570 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_CRASH, |
| 571 statement1.ColumnInt(1)); |
| 572 EXPECT_FALSE(statement1.Step()); |
| 573 } |
| 574 } |
| 575 |
| 519 struct InterruptReasonAssociation { | 576 struct InterruptReasonAssociation { |
| 520 std::string name; | 577 std::string name; |
| 521 int value; | 578 int value; |
| 522 }; | 579 }; |
| 523 | 580 |
| 524 // Test is dependent on interrupt reasons being listed in header file | 581 // Test is dependent on interrupt reasons being listed in header file |
| 525 // in order. | 582 // in order. |
| 526 const InterruptReasonAssociation current_reasons[] = { | 583 const InterruptReasonAssociation current_reasons[] = { |
| 527 #define INTERRUPT_REASON(a, b) { #a, b }, | 584 #define INTERRUPT_REASON(a, b) { #a, b }, |
| 528 #include "content/public/browser/download_interrupt_reason_values.h" | 585 #include "content/public/browser/download_interrupt_reason_values.h" |
| (...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1628 | 1685 |
| 1629 std::vector<PageUsageData*> results; | 1686 std::vector<PageUsageData*> results; |
| 1630 db_->QuerySegmentUsage(segment_time, 10, &results); | 1687 db_->QuerySegmentUsage(segment_time, 10, &results); |
| 1631 ASSERT_EQ(1u, results.size()); | 1688 ASSERT_EQ(1u, results.size()); |
| 1632 EXPECT_EQ(url, results[0]->GetURL()); | 1689 EXPECT_EQ(url, results[0]->GetURL()); |
| 1633 EXPECT_EQ(segment_id, results[0]->GetID()); | 1690 EXPECT_EQ(segment_id, results[0]->GetID()); |
| 1634 EXPECT_EQ(title, results[0]->GetTitle()); | 1691 EXPECT_EQ(title, results[0]->GetTitle()); |
| 1635 STLDeleteElements(&results); | 1692 STLDeleteElements(&results); |
| 1636 } | 1693 } |
| 1637 | 1694 |
| 1638 } // namespace | |
| 1639 | |
| 1640 } // namespace history | 1695 } // namespace history |
| OLD | NEW |