| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "base/threading/platform_thread.h" | 43 #include "base/threading/platform_thread.h" |
| 44 #include "base/time/time.h" | 44 #include "base/time/time.h" |
| 45 #include "chrome/browser/history/download_row.h" | 45 #include "chrome/browser/history/download_row.h" |
| 46 #include "chrome/browser/history/history_backend.h" | 46 #include "chrome/browser/history/history_backend.h" |
| 47 #include "chrome/browser/history/history_database.h" | 47 #include "chrome/browser/history/history_database.h" |
| 48 #include "chrome/browser/history/history_db_task.h" | 48 #include "chrome/browser/history/history_db_task.h" |
| 49 #include "chrome/browser/history/history_notifications.h" | 49 #include "chrome/browser/history/history_notifications.h" |
| 50 #include "chrome/browser/history/history_service.h" | 50 #include "chrome/browser/history/history_service.h" |
| 51 #include "chrome/browser/history/history_unittest_base.h" | 51 #include "chrome/browser/history/history_unittest_base.h" |
| 52 #include "chrome/browser/history/in_memory_history_backend.h" | 52 #include "chrome/browser/history/in_memory_history_backend.h" |
| 53 #include "chrome/common/chrome_constants.h" | |
| 54 #include "chrome/common/chrome_paths.h" | 53 #include "chrome/common/chrome_paths.h" |
| 55 #include "chrome/tools/profiles/thumbnail-inl.h" | 54 #include "chrome/tools/profiles/thumbnail-inl.h" |
| 55 #include "components/history/core/browser/history_constants.h" |
| 56 #include "components/history/core/browser/in_memory_database.h" | 56 #include "components/history/core/browser/in_memory_database.h" |
| 57 #include "components/history/core/browser/page_usage_data.h" | 57 #include "components/history/core/browser/page_usage_data.h" |
| 58 #include "components/history/core/common/thumbnail_score.h" | 58 #include "components/history/core/common/thumbnail_score.h" |
| 59 #include "content/public/browser/download_item.h" | 59 #include "content/public/browser/download_item.h" |
| 60 #include "content/public/browser/notification_details.h" | 60 #include "content/public/browser/notification_details.h" |
| 61 #include "content/public/browser/notification_source.h" | 61 #include "content/public/browser/notification_source.h" |
| 62 #include "sql/connection.h" | 62 #include "sql/connection.h" |
| 63 #include "sql/statement.h" | 63 #include "sql/statement.h" |
| 64 #include "sync/api/attachments/attachment_id.h" | 64 #include "sync/api/attachments/attachment_id.h" |
| 65 #include "sync/api/fake_sync_change_processor.h" | 65 #include "sync/api/fake_sync_change_processor.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 "HistoryBackend::Init"; | 133 "HistoryBackend::Init"; |
| 134 } | 134 } |
| 135 | 135 |
| 136 void CreateDBVersion(int version) { | 136 void CreateDBVersion(int version) { |
| 137 base::FilePath data_path; | 137 base::FilePath data_path; |
| 138 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 138 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
| 139 data_path = data_path.AppendASCII("History"); | 139 data_path = data_path.AppendASCII("History"); |
| 140 data_path = | 140 data_path = |
| 141 data_path.AppendASCII(base::StringPrintf("history.%d.sql", version)); | 141 data_path.AppendASCII(base::StringPrintf("history.%d.sql", version)); |
| 142 ASSERT_NO_FATAL_FAILURE( | 142 ASSERT_NO_FATAL_FAILURE( |
| 143 ExecuteSQLScript(data_path, history_dir_.Append( | 143 ExecuteSQLScript(data_path, history_dir_.Append(kHistoryFilename))); |
| 144 chrome::kHistoryFilename))); | |
| 145 } | 144 } |
| 146 | 145 |
| 147 void CreateArchivedDB() { | 146 void CreateArchivedDB() { |
| 148 base::FilePath data_path; | 147 base::FilePath data_path; |
| 149 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 148 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
| 150 data_path = data_path.AppendASCII("History"); | 149 data_path = data_path.AppendASCII("History"); |
| 151 data_path = data_path.AppendASCII("archived_history.4.sql"); | 150 data_path = data_path.AppendASCII("archived_history.4.sql"); |
| 152 ASSERT_NO_FATAL_FAILURE( | 151 ASSERT_NO_FATAL_FAILURE(ExecuteSQLScript( |
| 153 ExecuteSQLScript(data_path, history_dir_.Append( | 152 data_path, history_dir_.Append(kArchivedHistoryFilename))); |
| 154 chrome::kArchivedHistoryFilename))); | |
| 155 } | 153 } |
| 156 | 154 |
| 157 // testing::Test | 155 // testing::Test |
| 158 void SetUp() override { | 156 void SetUp() override { |
| 159 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 157 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 160 history_dir_ = temp_dir_.path().AppendASCII("HistoryBackendDBTest"); | 158 history_dir_ = temp_dir_.path().AppendASCII("HistoryBackendDBTest"); |
| 161 ASSERT_TRUE(base::CreateDirectory(history_dir_)); | 159 ASSERT_TRUE(base::CreateDirectory(history_dir_)); |
| 162 } | 160 } |
| 163 | 161 |
| 164 void DeleteBackend() { | 162 void DeleteBackend() { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 db_->QueryDownloads(&downloads); | 279 db_->QueryDownloads(&downloads); |
| 282 EXPECT_EQ(0U, downloads.size()); | 280 EXPECT_EQ(0U, downloads.size()); |
| 283 } | 281 } |
| 284 | 282 |
| 285 TEST_F(HistoryBackendDBTest, MigrateDownloadsState) { | 283 TEST_F(HistoryBackendDBTest, MigrateDownloadsState) { |
| 286 // Create the db we want. | 284 // Create the db we want. |
| 287 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22)); | 285 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22)); |
| 288 { | 286 { |
| 289 // Open the db for manual manipulation. | 287 // Open the db for manual manipulation. |
| 290 sql::Connection db; | 288 sql::Connection db; |
| 291 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 289 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 292 | 290 |
| 293 // Manually insert corrupted rows; there's infrastructure in place now to | 291 // Manually insert corrupted rows; there's infrastructure in place now to |
| 294 // make this impossible, at least according to the test above. | 292 // make this impossible, at least according to the test above. |
| 295 for (int state = 0; state < 5; ++state) { | 293 for (int state = 0; state < 5; ++state) { |
| 296 sql::Statement s(db.GetUniqueStatement( | 294 sql::Statement s(db.GetUniqueStatement( |
| 297 "INSERT INTO downloads (id, full_path, url, start_time, " | 295 "INSERT INTO downloads (id, full_path, url, start_time, " |
| 298 "received_bytes, total_bytes, state, end_time, opened) VALUES " | 296 "received_bytes, total_bytes, state, end_time, opened) VALUES " |
| 299 "(?, ?, ?, ?, ?, ?, ?, ?, ?)")); | 297 "(?, ?, ?, ?, ?, ?, ?, ?, ?)")); |
| 300 s.BindInt64(0, 1 + state); | 298 s.BindInt64(0, 1 + state); |
| 301 s.BindString(1, "path"); | 299 s.BindString(1, "path"); |
| 302 s.BindString(2, "url"); | 300 s.BindString(2, "url"); |
| 303 s.BindInt64(3, base::Time::Now().ToTimeT()); | 301 s.BindInt64(3, base::Time::Now().ToTimeT()); |
| 304 s.BindInt64(4, 100); | 302 s.BindInt64(4, 100); |
| 305 s.BindInt64(5, 100); | 303 s.BindInt64(5, 100); |
| 306 s.BindInt(6, state); | 304 s.BindInt(6, state); |
| 307 s.BindInt64(7, base::Time::Now().ToTimeT()); | 305 s.BindInt64(7, base::Time::Now().ToTimeT()); |
| 308 s.BindInt(8, state % 2); | 306 s.BindInt(8, state % 2); |
| 309 ASSERT_TRUE(s.Run()); | 307 ASSERT_TRUE(s.Run()); |
| 310 } | 308 } |
| 311 } | 309 } |
| 312 | 310 |
| 313 // Re-open the db using the HistoryDatabase, which should migrate from version | 311 // Re-open the db using the HistoryDatabase, which should migrate from version |
| 314 // 22 to the current version, fixing just the row whose state was 3. | 312 // 22 to the current version, fixing just the row whose state was 3. |
| 315 // Then close the db so that we can re-open it directly. | 313 // Then close the db so that we can re-open it directly. |
| 316 CreateBackendAndDatabase(); | 314 CreateBackendAndDatabase(); |
| 317 DeleteBackend(); | 315 DeleteBackend(); |
| 318 { | 316 { |
| 319 // Re-open the db for manual manipulation. | 317 // Re-open the db for manual manipulation. |
| 320 sql::Connection db; | 318 sql::Connection db; |
| 321 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 319 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 322 { | 320 { |
| 323 // The version should have been updated. | 321 // The version should have been updated. |
| 324 int cur_version = HistoryDatabase::GetCurrentVersion(); | 322 int cur_version = HistoryDatabase::GetCurrentVersion(); |
| 325 ASSERT_LT(22, cur_version); | 323 ASSERT_LT(22, cur_version); |
| 326 sql::Statement s(db.GetUniqueStatement( | 324 sql::Statement s(db.GetUniqueStatement( |
| 327 "SELECT value FROM meta WHERE key = 'version'")); | 325 "SELECT value FROM meta WHERE key = 'version'")); |
| 328 EXPECT_TRUE(s.Step()); | 326 EXPECT_TRUE(s.Step()); |
| 329 EXPECT_EQ(cur_version, s.ColumnInt(0)); | 327 EXPECT_EQ(cur_version, s.ColumnInt(0)); |
| 330 } | 328 } |
| 331 { | 329 { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 349 | 347 |
| 350 TEST_F(HistoryBackendDBTest, MigrateDownloadsReasonPathsAndDangerType) { | 348 TEST_F(HistoryBackendDBTest, MigrateDownloadsReasonPathsAndDangerType) { |
| 351 Time now(base::Time::Now()); | 349 Time now(base::Time::Now()); |
| 352 | 350 |
| 353 // Create the db we want. The schema didn't change from 22->23, so just | 351 // Create the db we want. The schema didn't change from 22->23, so just |
| 354 // re-use the v22 file. | 352 // re-use the v22 file. |
| 355 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22)); | 353 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22)); |
| 356 { | 354 { |
| 357 // Re-open the db for manual manipulation. | 355 // Re-open the db for manual manipulation. |
| 358 sql::Connection db; | 356 sql::Connection db; |
| 359 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 357 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 360 | 358 |
| 361 // Manually insert some rows. | 359 // Manually insert some rows. |
| 362 sql::Statement s(db.GetUniqueStatement( | 360 sql::Statement s(db.GetUniqueStatement( |
| 363 "INSERT INTO downloads (id, full_path, url, start_time, " | 361 "INSERT INTO downloads (id, full_path, url, start_time, " |
| 364 "received_bytes, total_bytes, state, end_time, opened) VALUES " | 362 "received_bytes, total_bytes, state, end_time, opened) VALUES " |
| 365 "(?, ?, ?, ?, ?, ?, ?, ?, ?)")); | 363 "(?, ?, ?, ?, ?, ?, ?, ?, ?)")); |
| 366 | 364 |
| 367 int64 id = 0; | 365 int64 id = 0; |
| 368 // Null path. | 366 // Null path. |
| 369 s.BindInt64(0, ++id); | 367 s.BindInt64(0, ++id); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 392 } | 390 } |
| 393 | 391 |
| 394 // Re-open the db using the HistoryDatabase, which should migrate from version | 392 // Re-open the db using the HistoryDatabase, which should migrate from version |
| 395 // 23 to 24, creating the new tables and creating the new path, reason, | 393 // 23 to 24, creating the new tables and creating the new path, reason, |
| 396 // and danger columns. | 394 // and danger columns. |
| 397 CreateBackendAndDatabase(); | 395 CreateBackendAndDatabase(); |
| 398 DeleteBackend(); | 396 DeleteBackend(); |
| 399 { | 397 { |
| 400 // Re-open the db for manual manipulation. | 398 // Re-open the db for manual manipulation. |
| 401 sql::Connection db; | 399 sql::Connection db; |
| 402 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 400 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 403 { | 401 { |
| 404 // The version should have been updated. | 402 // The version should have been updated. |
| 405 int cur_version = HistoryDatabase::GetCurrentVersion(); | 403 int cur_version = HistoryDatabase::GetCurrentVersion(); |
| 406 ASSERT_LT(23, cur_version); | 404 ASSERT_LT(23, cur_version); |
| 407 sql::Statement s(db.GetUniqueStatement( | 405 sql::Statement s(db.GetUniqueStatement( |
| 408 "SELECT value FROM meta WHERE key = 'version'")); | 406 "SELECT value FROM meta WHERE key = 'version'")); |
| 409 EXPECT_TRUE(s.Step()); | 407 EXPECT_TRUE(s.Step()); |
| 410 EXPECT_EQ(cur_version, s.ColumnInt(0)); | 408 EXPECT_EQ(cur_version, s.ColumnInt(0)); |
| 411 } | 409 } |
| 412 { | 410 { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 EXPECT_FALSE(statement.Step()); | 457 EXPECT_FALSE(statement.Step()); |
| 460 } | 458 } |
| 461 } | 459 } |
| 462 } | 460 } |
| 463 | 461 |
| 464 TEST_F(HistoryBackendDBTest, MigrateReferrer) { | 462 TEST_F(HistoryBackendDBTest, MigrateReferrer) { |
| 465 Time now(base::Time::Now()); | 463 Time now(base::Time::Now()); |
| 466 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22)); | 464 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22)); |
| 467 { | 465 { |
| 468 sql::Connection db; | 466 sql::Connection db; |
| 469 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 467 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 470 sql::Statement s(db.GetUniqueStatement( | 468 sql::Statement s(db.GetUniqueStatement( |
| 471 "INSERT INTO downloads (id, full_path, url, start_time, " | 469 "INSERT INTO downloads (id, full_path, url, start_time, " |
| 472 "received_bytes, total_bytes, state, end_time, opened) VALUES " | 470 "received_bytes, total_bytes, state, end_time, opened) VALUES " |
| 473 "(?, ?, ?, ?, ?, ?, ?, ?, ?)")); | 471 "(?, ?, ?, ?, ?, ?, ?, ?, ?)")); |
| 474 int64 db_handle = 0; | 472 int64 db_handle = 0; |
| 475 s.BindInt64(0, ++db_handle); | 473 s.BindInt64(0, ++db_handle); |
| 476 s.BindString(1, "full_path"); | 474 s.BindString(1, "full_path"); |
| 477 s.BindString(2, "http://whatever.com/index.html"); | 475 s.BindString(2, "http://whatever.com/index.html"); |
| 478 s.BindInt64(3, now.ToTimeT()); | 476 s.BindInt64(3, now.ToTimeT()); |
| 479 s.BindInt64(4, 100); | 477 s.BindInt64(4, 100); |
| 480 s.BindInt64(5, 100); | 478 s.BindInt64(5, 100); |
| 481 s.BindInt(6, 1); | 479 s.BindInt(6, 1); |
| 482 s.BindInt64(7, now.ToTimeT()); | 480 s.BindInt64(7, now.ToTimeT()); |
| 483 s.BindInt(8, 1); | 481 s.BindInt(8, 1); |
| 484 ASSERT_TRUE(s.Run()); | 482 ASSERT_TRUE(s.Run()); |
| 485 } | 483 } |
| 486 // Re-open the db using the HistoryDatabase, which should migrate to version | 484 // Re-open the db using the HistoryDatabase, which should migrate to version |
| 487 // 26, creating the referrer column. | 485 // 26, creating the referrer column. |
| 488 CreateBackendAndDatabase(); | 486 CreateBackendAndDatabase(); |
| 489 DeleteBackend(); | 487 DeleteBackend(); |
| 490 { | 488 { |
| 491 // Re-open the db for manual manipulation. | 489 // Re-open the db for manual manipulation. |
| 492 sql::Connection db; | 490 sql::Connection db; |
| 493 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 491 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 494 // The version should have been updated. | 492 // The version should have been updated. |
| 495 int cur_version = HistoryDatabase::GetCurrentVersion(); | 493 int cur_version = HistoryDatabase::GetCurrentVersion(); |
| 496 ASSERT_LE(26, cur_version); | 494 ASSERT_LE(26, cur_version); |
| 497 { | 495 { |
| 498 sql::Statement s(db.GetUniqueStatement( | 496 sql::Statement s(db.GetUniqueStatement( |
| 499 "SELECT value FROM meta WHERE key = 'version'")); | 497 "SELECT value FROM meta WHERE key = 'version'")); |
| 500 EXPECT_TRUE(s.Step()); | 498 EXPECT_TRUE(s.Step()); |
| 501 EXPECT_EQ(cur_version, s.ColumnInt(0)); | 499 EXPECT_EQ(cur_version, s.ColumnInt(0)); |
| 502 } | 500 } |
| 503 { | 501 { |
| 504 sql::Statement s(db.GetUniqueStatement( | 502 sql::Statement s(db.GetUniqueStatement( |
| 505 "SELECT referrer from downloads")); | 503 "SELECT referrer from downloads")); |
| 506 EXPECT_TRUE(s.Step()); | 504 EXPECT_TRUE(s.Step()); |
| 507 EXPECT_EQ(std::string(), s.ColumnString(0)); | 505 EXPECT_EQ(std::string(), s.ColumnString(0)); |
| 508 } | 506 } |
| 509 } | 507 } |
| 510 } | 508 } |
| 511 | 509 |
| 512 TEST_F(HistoryBackendDBTest, MigrateDownloadedByExtension) { | 510 TEST_F(HistoryBackendDBTest, MigrateDownloadedByExtension) { |
| 513 Time now(base::Time::Now()); | 511 Time now(base::Time::Now()); |
| 514 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(26)); | 512 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(26)); |
| 515 { | 513 { |
| 516 sql::Connection db; | 514 sql::Connection db; |
| 517 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 515 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 518 { | 516 { |
| 519 sql::Statement s(db.GetUniqueStatement( | 517 sql::Statement s(db.GetUniqueStatement( |
| 520 "INSERT INTO downloads (id, current_path, target_path, start_time, " | 518 "INSERT INTO downloads (id, current_path, target_path, start_time, " |
| 521 "received_bytes, total_bytes, state, danger_type, interrupt_reason, " | 519 "received_bytes, total_bytes, state, danger_type, interrupt_reason, " |
| 522 "end_time, opened, referrer) VALUES " | 520 "end_time, opened, referrer) VALUES " |
| 523 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")); | 521 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")); |
| 524 s.BindInt64(0, 1); | 522 s.BindInt64(0, 1); |
| 525 s.BindString(1, "current_path"); | 523 s.BindString(1, "current_path"); |
| 526 s.BindString(2, "target_path"); | 524 s.BindString(2, "target_path"); |
| 527 s.BindInt64(3, now.ToTimeT()); | 525 s.BindInt64(3, now.ToTimeT()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 545 ASSERT_TRUE(s.Run()); | 543 ASSERT_TRUE(s.Run()); |
| 546 } | 544 } |
| 547 } | 545 } |
| 548 // Re-open the db using the HistoryDatabase, which should migrate to version | 546 // Re-open the db using the HistoryDatabase, which should migrate to version |
| 549 // 27, creating the by_ext_id and by_ext_name columns. | 547 // 27, creating the by_ext_id and by_ext_name columns. |
| 550 CreateBackendAndDatabase(); | 548 CreateBackendAndDatabase(); |
| 551 DeleteBackend(); | 549 DeleteBackend(); |
| 552 { | 550 { |
| 553 // Re-open the db for manual manipulation. | 551 // Re-open the db for manual manipulation. |
| 554 sql::Connection db; | 552 sql::Connection db; |
| 555 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 553 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 556 // The version should have been updated. | 554 // The version should have been updated. |
| 557 int cur_version = HistoryDatabase::GetCurrentVersion(); | 555 int cur_version = HistoryDatabase::GetCurrentVersion(); |
| 558 ASSERT_LE(27, cur_version); | 556 ASSERT_LE(27, cur_version); |
| 559 { | 557 { |
| 560 sql::Statement s(db.GetUniqueStatement( | 558 sql::Statement s(db.GetUniqueStatement( |
| 561 "SELECT value FROM meta WHERE key = 'version'")); | 559 "SELECT value FROM meta WHERE key = 'version'")); |
| 562 EXPECT_TRUE(s.Step()); | 560 EXPECT_TRUE(s.Step()); |
| 563 EXPECT_EQ(cur_version, s.ColumnInt(0)); | 561 EXPECT_EQ(cur_version, s.ColumnInt(0)); |
| 564 } | 562 } |
| 565 { | 563 { |
| 566 sql::Statement s(db.GetUniqueStatement( | 564 sql::Statement s(db.GetUniqueStatement( |
| 567 "SELECT by_ext_id, by_ext_name from downloads")); | 565 "SELECT by_ext_id, by_ext_name from downloads")); |
| 568 EXPECT_TRUE(s.Step()); | 566 EXPECT_TRUE(s.Step()); |
| 569 EXPECT_EQ(std::string(), s.ColumnString(0)); | 567 EXPECT_EQ(std::string(), s.ColumnString(0)); |
| 570 EXPECT_EQ(std::string(), s.ColumnString(1)); | 568 EXPECT_EQ(std::string(), s.ColumnString(1)); |
| 571 } | 569 } |
| 572 } | 570 } |
| 573 } | 571 } |
| 574 | 572 |
| 575 TEST_F(HistoryBackendDBTest, MigrateDownloadValidators) { | 573 TEST_F(HistoryBackendDBTest, MigrateDownloadValidators) { |
| 576 Time now(base::Time::Now()); | 574 Time now(base::Time::Now()); |
| 577 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(27)); | 575 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(27)); |
| 578 { | 576 { |
| 579 sql::Connection db; | 577 sql::Connection db; |
| 580 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 578 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 581 { | 579 { |
| 582 sql::Statement s(db.GetUniqueStatement( | 580 sql::Statement s(db.GetUniqueStatement( |
| 583 "INSERT INTO downloads (id, current_path, target_path, start_time, " | 581 "INSERT INTO downloads (id, current_path, target_path, start_time, " |
| 584 "received_bytes, total_bytes, state, danger_type, interrupt_reason, " | 582 "received_bytes, total_bytes, state, danger_type, interrupt_reason, " |
| 585 "end_time, opened, referrer, by_ext_id, by_ext_name) VALUES " | 583 "end_time, opened, referrer, by_ext_id, by_ext_name) VALUES " |
| 586 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")); | 584 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")); |
| 587 s.BindInt64(0, 1); | 585 s.BindInt64(0, 1); |
| 588 s.BindString(1, "current_path"); | 586 s.BindString(1, "current_path"); |
| 589 s.BindString(2, "target_path"); | 587 s.BindString(2, "target_path"); |
| 590 s.BindInt64(3, now.ToTimeT()); | 588 s.BindInt64(3, now.ToTimeT()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 610 ASSERT_TRUE(s.Run()); | 608 ASSERT_TRUE(s.Run()); |
| 611 } | 609 } |
| 612 } | 610 } |
| 613 // Re-open the db using the HistoryDatabase, which should migrate to the | 611 // Re-open the db using the HistoryDatabase, which should migrate to the |
| 614 // current version, creating the etag and last_modified columns. | 612 // current version, creating the etag and last_modified columns. |
| 615 CreateBackendAndDatabase(); | 613 CreateBackendAndDatabase(); |
| 616 DeleteBackend(); | 614 DeleteBackend(); |
| 617 { | 615 { |
| 618 // Re-open the db for manual manipulation. | 616 // Re-open the db for manual manipulation. |
| 619 sql::Connection db; | 617 sql::Connection db; |
| 620 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 618 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 621 // The version should have been updated. | 619 // The version should have been updated. |
| 622 int cur_version = HistoryDatabase::GetCurrentVersion(); | 620 int cur_version = HistoryDatabase::GetCurrentVersion(); |
| 623 ASSERT_LE(28, cur_version); | 621 ASSERT_LE(28, cur_version); |
| 624 { | 622 { |
| 625 sql::Statement s(db.GetUniqueStatement( | 623 sql::Statement s(db.GetUniqueStatement( |
| 626 "SELECT value FROM meta WHERE key = 'version'")); | 624 "SELECT value FROM meta WHERE key = 'version'")); |
| 627 EXPECT_TRUE(s.Step()); | 625 EXPECT_TRUE(s.Step()); |
| 628 EXPECT_EQ(cur_version, s.ColumnInt(0)); | 626 EXPECT_EQ(cur_version, s.ColumnInt(0)); |
| 629 } | 627 } |
| 630 { | 628 { |
| 631 sql::Statement s(db.GetUniqueStatement( | 629 sql::Statement s(db.GetUniqueStatement( |
| 632 "SELECT etag, last_modified from downloads")); | 630 "SELECT etag, last_modified from downloads")); |
| 633 EXPECT_TRUE(s.Step()); | 631 EXPECT_TRUE(s.Step()); |
| 634 EXPECT_EQ(std::string(), s.ColumnString(0)); | 632 EXPECT_EQ(std::string(), s.ColumnString(0)); |
| 635 EXPECT_EQ(std::string(), s.ColumnString(1)); | 633 EXPECT_EQ(std::string(), s.ColumnString(1)); |
| 636 } | 634 } |
| 637 } | 635 } |
| 638 } | 636 } |
| 639 | 637 |
| 640 TEST_F(HistoryBackendDBTest, PurgeArchivedDatabase) { | 638 TEST_F(HistoryBackendDBTest, PurgeArchivedDatabase) { |
| 641 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(27)); | 639 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(27)); |
| 642 ASSERT_NO_FATAL_FAILURE(CreateArchivedDB()); | 640 ASSERT_NO_FATAL_FAILURE(CreateArchivedDB()); |
| 643 | 641 |
| 644 ASSERT_TRUE(base::PathExists( | 642 ASSERT_TRUE(base::PathExists(history_dir_.Append(kArchivedHistoryFilename))); |
| 645 history_dir_.Append(chrome::kArchivedHistoryFilename))); | |
| 646 | 643 |
| 647 CreateBackendAndDatabase(); | 644 CreateBackendAndDatabase(); |
| 648 DeleteBackend(); | 645 DeleteBackend(); |
| 649 | 646 |
| 650 // We do not retain expired history entries in an archived database as of M37. | 647 // We do not retain expired history entries in an archived database as of M37. |
| 651 // Verify that any legacy archived database is deleted on start-up. | 648 // Verify that any legacy archived database is deleted on start-up. |
| 652 ASSERT_FALSE(base::PathExists( | 649 ASSERT_FALSE(base::PathExists(history_dir_.Append(kArchivedHistoryFilename))); |
| 653 history_dir_.Append(chrome::kArchivedHistoryFilename))); | |
| 654 } | 650 } |
| 655 | 651 |
| 656 TEST_F(HistoryBackendDBTest, MigrateDownloadMimeType) { | 652 TEST_F(HistoryBackendDBTest, MigrateDownloadMimeType) { |
| 657 Time now(base::Time::Now()); | 653 Time now(base::Time::Now()); |
| 658 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(28)); | 654 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(28)); |
| 659 { | 655 { |
| 660 sql::Connection db; | 656 sql::Connection db; |
| 661 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 657 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 662 { | 658 { |
| 663 sql::Statement s(db.GetUniqueStatement( | 659 sql::Statement s(db.GetUniqueStatement( |
| 664 "INSERT INTO downloads (id, current_path, target_path, start_time, " | 660 "INSERT INTO downloads (id, current_path, target_path, start_time, " |
| 665 "received_bytes, total_bytes, state, danger_type, interrupt_reason, " | 661 "received_bytes, total_bytes, state, danger_type, interrupt_reason, " |
| 666 "end_time, opened, referrer, by_ext_id, by_ext_name, etag, " | 662 "end_time, opened, referrer, by_ext_id, by_ext_name, etag, " |
| 667 "last_modified) VALUES " | 663 "last_modified) VALUES " |
| 668 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")); | 664 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")); |
| 669 s.BindInt64(0, 1); | 665 s.BindInt64(0, 1); |
| 670 s.BindString(1, "current_path"); | 666 s.BindString(1, "current_path"); |
| 671 s.BindString(2, "target_path"); | 667 s.BindString(2, "target_path"); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 694 ASSERT_TRUE(s.Run()); | 690 ASSERT_TRUE(s.Run()); |
| 695 } | 691 } |
| 696 } | 692 } |
| 697 // Re-open the db using the HistoryDatabase, which should migrate to the | 693 // Re-open the db using the HistoryDatabase, which should migrate to the |
| 698 // current version, creating themime_type abd original_mime_type columns. | 694 // current version, creating themime_type abd original_mime_type columns. |
| 699 CreateBackendAndDatabase(); | 695 CreateBackendAndDatabase(); |
| 700 DeleteBackend(); | 696 DeleteBackend(); |
| 701 { | 697 { |
| 702 // Re-open the db for manual manipulation. | 698 // Re-open the db for manual manipulation. |
| 703 sql::Connection db; | 699 sql::Connection db; |
| 704 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 700 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 705 // The version should have been updated. | 701 // The version should have been updated. |
| 706 int cur_version = HistoryDatabase::GetCurrentVersion(); | 702 int cur_version = HistoryDatabase::GetCurrentVersion(); |
| 707 ASSERT_LE(29, cur_version); | 703 ASSERT_LE(29, cur_version); |
| 708 { | 704 { |
| 709 sql::Statement s(db.GetUniqueStatement( | 705 sql::Statement s(db.GetUniqueStatement( |
| 710 "SELECT value FROM meta WHERE key = 'version'")); | 706 "SELECT value FROM meta WHERE key = 'version'")); |
| 711 EXPECT_TRUE(s.Step()); | 707 EXPECT_TRUE(s.Step()); |
| 712 EXPECT_EQ(cur_version, s.ColumnInt(0)); | 708 EXPECT_EQ(cur_version, s.ColumnInt(0)); |
| 713 } | 709 } |
| 714 { | 710 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 730 // Add some downloads. | 726 // Add some downloads. |
| 731 uint32 id1 = 1, id2 = 2, id3 = 3; | 727 uint32 id1 = 1, id2 = 2, id3 = 3; |
| 732 AddDownload(id1, DownloadItem::COMPLETE, now); | 728 AddDownload(id1, DownloadItem::COMPLETE, now); |
| 733 AddDownload(id2, DownloadItem::COMPLETE, now + base::TimeDelta::FromDays(2)); | 729 AddDownload(id2, DownloadItem::COMPLETE, now + base::TimeDelta::FromDays(2)); |
| 734 AddDownload(id3, DownloadItem::COMPLETE, now - base::TimeDelta::FromDays(2)); | 730 AddDownload(id3, DownloadItem::COMPLETE, now - base::TimeDelta::FromDays(2)); |
| 735 | 731 |
| 736 // Confirm that resulted in the correct number of rows in the DB. | 732 // Confirm that resulted in the correct number of rows in the DB. |
| 737 DeleteBackend(); | 733 DeleteBackend(); |
| 738 { | 734 { |
| 739 sql::Connection db; | 735 sql::Connection db; |
| 740 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 736 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 741 sql::Statement statement(db.GetUniqueStatement( | 737 sql::Statement statement(db.GetUniqueStatement( |
| 742 "Select Count(*) from downloads")); | 738 "Select Count(*) from downloads")); |
| 743 EXPECT_TRUE(statement.Step()); | 739 EXPECT_TRUE(statement.Step()); |
| 744 EXPECT_EQ(3, statement.ColumnInt(0)); | 740 EXPECT_EQ(3, statement.ColumnInt(0)); |
| 745 | 741 |
| 746 sql::Statement statement1(db.GetUniqueStatement( | 742 sql::Statement statement1(db.GetUniqueStatement( |
| 747 "Select Count(*) from downloads_url_chains")); | 743 "Select Count(*) from downloads_url_chains")); |
| 748 EXPECT_TRUE(statement1.Step()); | 744 EXPECT_TRUE(statement1.Step()); |
| 749 EXPECT_EQ(3, statement1.ColumnInt(0)); | 745 EXPECT_EQ(3, statement1.ColumnInt(0)); |
| 750 } | 746 } |
| 751 | 747 |
| 752 // Delete some rows and make sure the results are still correct. | 748 // Delete some rows and make sure the results are still correct. |
| 753 CreateBackendAndDatabase(); | 749 CreateBackendAndDatabase(); |
| 754 db_->RemoveDownload(id2); | 750 db_->RemoveDownload(id2); |
| 755 db_->RemoveDownload(id3); | 751 db_->RemoveDownload(id3); |
| 756 DeleteBackend(); | 752 DeleteBackend(); |
| 757 { | 753 { |
| 758 sql::Connection db; | 754 sql::Connection db; |
| 759 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 755 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 760 sql::Statement statement(db.GetUniqueStatement( | 756 sql::Statement statement(db.GetUniqueStatement( |
| 761 "Select Count(*) from downloads")); | 757 "Select Count(*) from downloads")); |
| 762 EXPECT_TRUE(statement.Step()); | 758 EXPECT_TRUE(statement.Step()); |
| 763 EXPECT_EQ(1, statement.ColumnInt(0)); | 759 EXPECT_EQ(1, statement.ColumnInt(0)); |
| 764 | 760 |
| 765 sql::Statement statement1(db.GetUniqueStatement( | 761 sql::Statement statement1(db.GetUniqueStatement( |
| 766 "Select Count(*) from downloads_url_chains")); | 762 "Select Count(*) from downloads_url_chains")); |
| 767 EXPECT_TRUE(statement1.Step()); | 763 EXPECT_TRUE(statement1.Step()); |
| 768 EXPECT_EQ(1, statement1.ColumnInt(0)); | 764 EXPECT_EQ(1, statement1.ColumnInt(0)); |
| 769 } | 765 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 796 // Creating records without any urls should fail. | 792 // Creating records without any urls should fail. |
| 797 EXPECT_FALSE(db_->CreateDownload(download)); | 793 EXPECT_FALSE(db_->CreateDownload(download)); |
| 798 | 794 |
| 799 download.url_chain.push_back(GURL("foo-url")); | 795 download.url_chain.push_back(GURL("foo-url")); |
| 800 EXPECT_TRUE(db_->CreateDownload(download)); | 796 EXPECT_TRUE(db_->CreateDownload(download)); |
| 801 | 797 |
| 802 // Pretend that the URLs were dropped. | 798 // Pretend that the URLs were dropped. |
| 803 DeleteBackend(); | 799 DeleteBackend(); |
| 804 { | 800 { |
| 805 sql::Connection db; | 801 sql::Connection db; |
| 806 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 802 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 807 sql::Statement statement(db.GetUniqueStatement( | 803 sql::Statement statement(db.GetUniqueStatement( |
| 808 "DELETE FROM downloads_url_chains WHERE id=1")); | 804 "DELETE FROM downloads_url_chains WHERE id=1")); |
| 809 ASSERT_TRUE(statement.Run()); | 805 ASSERT_TRUE(statement.Run()); |
| 810 } | 806 } |
| 811 CreateBackendAndDatabase(); | 807 CreateBackendAndDatabase(); |
| 812 std::vector<DownloadRow> downloads; | 808 std::vector<DownloadRow> downloads; |
| 813 db_->QueryDownloads(&downloads); | 809 db_->QueryDownloads(&downloads); |
| 814 EXPECT_EQ(0U, downloads.size()); | 810 EXPECT_EQ(0U, downloads.size()); |
| 815 | 811 |
| 816 // QueryDownloads should have nuked the corrupt record. | 812 // QueryDownloads should have nuked the corrupt record. |
| 817 DeleteBackend(); | 813 DeleteBackend(); |
| 818 { | 814 { |
| 819 sql::Connection db; | 815 sql::Connection db; |
| 820 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 816 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 821 { | 817 { |
| 822 sql::Statement statement(db.GetUniqueStatement( | 818 sql::Statement statement(db.GetUniqueStatement( |
| 823 "SELECT count(*) from downloads")); | 819 "SELECT count(*) from downloads")); |
| 824 ASSERT_TRUE(statement.Step()); | 820 ASSERT_TRUE(statement.Step()); |
| 825 EXPECT_EQ(0, statement.ColumnInt(0)); | 821 EXPECT_EQ(0, statement.ColumnInt(0)); |
| 826 } | 822 } |
| 827 } | 823 } |
| 828 } | 824 } |
| 829 | 825 |
| 830 TEST_F(HistoryBackendDBTest, ConfirmDownloadInProgressCleanup) { | 826 TEST_F(HistoryBackendDBTest, ConfirmDownloadInProgressCleanup) { |
| 831 // Create the DB. | 827 // Create the DB. |
| 832 CreateBackendAndDatabase(); | 828 CreateBackendAndDatabase(); |
| 833 | 829 |
| 834 base::Time now(base::Time::Now()); | 830 base::Time now(base::Time::Now()); |
| 835 | 831 |
| 836 // Put an IN_PROGRESS download in the DB. | 832 // Put an IN_PROGRESS download in the DB. |
| 837 AddDownload(1, DownloadItem::IN_PROGRESS, now); | 833 AddDownload(1, DownloadItem::IN_PROGRESS, now); |
| 838 | 834 |
| 839 // Confirm that they made it into the DB unchanged. | 835 // Confirm that they made it into the DB unchanged. |
| 840 DeleteBackend(); | 836 DeleteBackend(); |
| 841 { | 837 { |
| 842 sql::Connection db; | 838 sql::Connection db; |
| 843 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 839 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 844 sql::Statement statement(db.GetUniqueStatement( | 840 sql::Statement statement(db.GetUniqueStatement( |
| 845 "Select Count(*) from downloads")); | 841 "Select Count(*) from downloads")); |
| 846 EXPECT_TRUE(statement.Step()); | 842 EXPECT_TRUE(statement.Step()); |
| 847 EXPECT_EQ(1, statement.ColumnInt(0)); | 843 EXPECT_EQ(1, statement.ColumnInt(0)); |
| 848 | 844 |
| 849 sql::Statement statement1(db.GetUniqueStatement( | 845 sql::Statement statement1(db.GetUniqueStatement( |
| 850 "Select state, interrupt_reason from downloads")); | 846 "Select state, interrupt_reason from downloads")); |
| 851 EXPECT_TRUE(statement1.Step()); | 847 EXPECT_TRUE(statement1.Step()); |
| 852 EXPECT_EQ(DownloadDatabase::kStateInProgress, statement1.ColumnInt(0)); | 848 EXPECT_EQ(DownloadDatabase::kStateInProgress, statement1.ColumnInt(0)); |
| 853 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, statement1.ColumnInt(1)); | 849 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, statement1.ColumnInt(1)); |
| 854 EXPECT_FALSE(statement1.Step()); | 850 EXPECT_FALSE(statement1.Step()); |
| 855 } | 851 } |
| 856 | 852 |
| 857 // Read in the DB through query downloads, then test that the | 853 // Read in the DB through query downloads, then test that the |
| 858 // right transformation was returned. | 854 // right transformation was returned. |
| 859 CreateBackendAndDatabase(); | 855 CreateBackendAndDatabase(); |
| 860 std::vector<DownloadRow> results; | 856 std::vector<DownloadRow> results; |
| 861 db_->QueryDownloads(&results); | 857 db_->QueryDownloads(&results); |
| 862 ASSERT_EQ(1u, results.size()); | 858 ASSERT_EQ(1u, results.size()); |
| 863 EXPECT_EQ(content::DownloadItem::INTERRUPTED, results[0].state); | 859 EXPECT_EQ(content::DownloadItem::INTERRUPTED, results[0].state); |
| 864 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_CRASH, | 860 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_CRASH, |
| 865 results[0].interrupt_reason); | 861 results[0].interrupt_reason); |
| 866 | 862 |
| 867 // Allow the update to propagate, shut down the DB, and confirm that | 863 // Allow the update to propagate, shut down the DB, and confirm that |
| 868 // the query updated the on disk database as well. | 864 // the query updated the on disk database as well. |
| 869 base::MessageLoop::current()->RunUntilIdle(); | 865 base::MessageLoop::current()->RunUntilIdle(); |
| 870 DeleteBackend(); | 866 DeleteBackend(); |
| 871 { | 867 { |
| 872 sql::Connection db; | 868 sql::Connection db; |
| 873 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 869 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 874 sql::Statement statement(db.GetUniqueStatement( | 870 sql::Statement statement(db.GetUniqueStatement( |
| 875 "Select Count(*) from downloads")); | 871 "Select Count(*) from downloads")); |
| 876 EXPECT_TRUE(statement.Step()); | 872 EXPECT_TRUE(statement.Step()); |
| 877 EXPECT_EQ(1, statement.ColumnInt(0)); | 873 EXPECT_EQ(1, statement.ColumnInt(0)); |
| 878 | 874 |
| 879 sql::Statement statement1(db.GetUniqueStatement( | 875 sql::Statement statement1(db.GetUniqueStatement( |
| 880 "Select state, interrupt_reason from downloads")); | 876 "Select state, interrupt_reason from downloads")); |
| 881 EXPECT_TRUE(statement1.Step()); | 877 EXPECT_TRUE(statement1.Step()); |
| 882 EXPECT_EQ(DownloadDatabase::kStateInterrupted, statement1.ColumnInt(0)); | 878 EXPECT_EQ(DownloadDatabase::kStateInterrupted, statement1.ColumnInt(0)); |
| 883 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_CRASH, | 879 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_CRASH, |
| (...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1811 const SegmentID segment_id = 2; | 1807 const SegmentID segment_id = 2; |
| 1812 const URLID url_id = 3; | 1808 const URLID url_id = 3; |
| 1813 const GURL url("http://www.foo.com"); | 1809 const GURL url("http://www.foo.com"); |
| 1814 const std::string url_name(VisitSegmentDatabase::ComputeSegmentName(url)); | 1810 const std::string url_name(VisitSegmentDatabase::ComputeSegmentName(url)); |
| 1815 const base::string16 title(base::ASCIIToUTF16("Title1")); | 1811 const base::string16 title(base::ASCIIToUTF16("Title1")); |
| 1816 const Time segment_time(Time::Now()); | 1812 const Time segment_time(Time::Now()); |
| 1817 | 1813 |
| 1818 { | 1814 { |
| 1819 // Re-open the db for manual manipulation. | 1815 // Re-open the db for manual manipulation. |
| 1820 sql::Connection db; | 1816 sql::Connection db; |
| 1821 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); | 1817 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
| 1822 | 1818 |
| 1823 // Add an entry to urls. | 1819 // Add an entry to urls. |
| 1824 { | 1820 { |
| 1825 sql::Statement s(db.GetUniqueStatement( | 1821 sql::Statement s(db.GetUniqueStatement( |
| 1826 "INSERT INTO urls " | 1822 "INSERT INTO urls " |
| 1827 "(id, url, title, last_visit_time) VALUES " | 1823 "(id, url, title, last_visit_time) VALUES " |
| 1828 "(?, ?, ?, ?)")); | 1824 "(?, ?, ?, ?)")); |
| 1829 s.BindInt64(0, url_id); | 1825 s.BindInt64(0, url_id); |
| 1830 s.BindString(1, url.spec()); | 1826 s.BindString(1, url.spec()); |
| 1831 s.BindString16(2, title); | 1827 s.BindString16(2, title); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1866 std::vector<PageUsageData*> results; | 1862 std::vector<PageUsageData*> results; |
| 1867 db_->QuerySegmentUsage(segment_time, 10, &results); | 1863 db_->QuerySegmentUsage(segment_time, 10, &results); |
| 1868 ASSERT_EQ(1u, results.size()); | 1864 ASSERT_EQ(1u, results.size()); |
| 1869 EXPECT_EQ(url, results[0]->GetURL()); | 1865 EXPECT_EQ(url, results[0]->GetURL()); |
| 1870 EXPECT_EQ(segment_id, results[0]->GetID()); | 1866 EXPECT_EQ(segment_id, results[0]->GetID()); |
| 1871 EXPECT_EQ(title, results[0]->GetTitle()); | 1867 EXPECT_EQ(title, results[0]->GetTitle()); |
| 1872 STLDeleteElements(&results); | 1868 STLDeleteElements(&results); |
| 1873 } | 1869 } |
| 1874 | 1870 |
| 1875 } // namespace history | 1871 } // namespace history |
| OLD | NEW |