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

Side by Side Diff: components/history/core/browser/history_backend_db_unittest.cc

Issue 1548113002: Switch to standard integer types in components/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 4 years, 12 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
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.
11 // 11 //
12 // 2. The simpler style is to create a history backend on this thread and 12 // 2. The simpler style is to create a history backend on this thread and
13 // access it directly without a HistoryService object. This is much simpler 13 // access it directly without a HistoryService object. This is much simpler
14 // because communication is synchronous. Generally, sets should go through 14 // because communication is synchronous. Generally, sets should go through
15 // the history backend (since there is a lot of logic) but gets can come 15 // the history backend (since there is a lot of logic) but gets can come
16 // directly from the HistoryDatabase. This is because the backend generally 16 // directly from the HistoryDatabase. This is because the backend generally
17 // has no logic in the getter except threading stuff, which we don't want 17 // has no logic in the getter except threading stuff, which we don't want
18 // to run. 18 // to run.
19 19
20 #include "components/history/core/browser/history_backend.h" 20 #include "components/history/core/browser/history_backend.h"
21 21
22 #include <stdint.h>
23
22 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
23 #include "components/history/core/browser/download_constants.h" 25 #include "components/history/core/browser/download_constants.h"
24 #include "components/history/core/browser/download_row.h" 26 #include "components/history/core/browser/download_row.h"
25 #include "components/history/core/browser/history_constants.h" 27 #include "components/history/core/browser/history_constants.h"
26 #include "components/history/core/browser/history_database.h" 28 #include "components/history/core/browser/history_database.h"
27 #include "components/history/core/browser/page_usage_data.h" 29 #include "components/history/core/browser/page_usage_data.h"
28 #include "components/history/core/test/history_backend_db_base_test.h" 30 #include "components/history/core/test/history_backend_db_base_test.h"
29 #include "components/history/core/test/test_history_database.h" 31 #include "components/history/core/test/test_history_database.h"
30 32
31 namespace history { 33 namespace history {
(...skipping 11 matching lines...) Expand all
43 CreateBackendAndDatabase(); 45 CreateBackendAndDatabase();
44 46
45 // Initially there should be nothing in the downloads database. 47 // Initially there should be nothing in the downloads database.
46 std::vector<DownloadRow> downloads; 48 std::vector<DownloadRow> downloads;
47 db_->QueryDownloads(&downloads); 49 db_->QueryDownloads(&downloads);
48 EXPECT_EQ(0U, downloads.size()); 50 EXPECT_EQ(0U, downloads.size());
49 51
50 // Add a download, test that it was added correctly, remove it, test that it 52 // Add a download, test that it was added correctly, remove it, test that it
51 // was removed. 53 // was removed.
52 base::Time now = base::Time(); 54 base::Time now = base::Time();
53 uint32 id = 1; 55 uint32_t id = 1;
54 EXPECT_TRUE(AddDownload(id, DownloadState::COMPLETE, base::Time())); 56 EXPECT_TRUE(AddDownload(id, DownloadState::COMPLETE, base::Time()));
55 db_->QueryDownloads(&downloads); 57 db_->QueryDownloads(&downloads);
56 EXPECT_EQ(1U, downloads.size()); 58 EXPECT_EQ(1U, downloads.size());
57 59
58 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("current-path")), 60 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("current-path")),
59 downloads[0].current_path); 61 downloads[0].current_path);
60 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("target-path")), 62 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("target-path")),
61 downloads[0].target_path); 63 downloads[0].target_path);
62 EXPECT_EQ(1UL, downloads[0].url_chain.size()); 64 EXPECT_EQ(1UL, downloads[0].url_chain.size());
63 EXPECT_EQ(GURL("foo-url"), downloads[0].url_chain[0]); 65 EXPECT_EQ(GURL("foo-url"), downloads[0].url_chain[0]);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // Re-open the db for manual manipulation. 160 // Re-open the db for manual manipulation.
159 sql::Connection db; 161 sql::Connection db;
160 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); 162 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename)));
161 163
162 // Manually insert some rows. 164 // Manually insert some rows.
163 sql::Statement s(db.GetUniqueStatement( 165 sql::Statement s(db.GetUniqueStatement(
164 "INSERT INTO downloads (id, full_path, url, start_time, " 166 "INSERT INTO downloads (id, full_path, url, start_time, "
165 "received_bytes, total_bytes, state, end_time, opened) VALUES " 167 "received_bytes, total_bytes, state, end_time, opened) VALUES "
166 "(?, ?, ?, ?, ?, ?, ?, ?, ?)")); 168 "(?, ?, ?, ?, ?, ?, ?, ?, ?)"));
167 169
168 int64 id = 0; 170 int64_t id = 0;
169 // Null path. 171 // Null path.
170 s.BindInt64(0, ++id); 172 s.BindInt64(0, ++id);
171 s.BindString(1, std::string()); 173 s.BindString(1, std::string());
172 s.BindString(2, "http://whatever.com/index.html"); 174 s.BindString(2, "http://whatever.com/index.html");
173 s.BindInt64(3, now.ToTimeT()); 175 s.BindInt64(3, now.ToTimeT());
174 s.BindInt64(4, 100); 176 s.BindInt64(4, 100);
175 s.BindInt64(5, 100); 177 s.BindInt64(5, 100);
176 s.BindInt(6, 1); 178 s.BindInt(6, 1);
177 s.BindInt64(7, now.ToTimeT()); 179 s.BindInt64(7, now.ToTimeT());
178 s.BindInt(8, 1); 180 s.BindInt(8, 1);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 TEST_F(HistoryBackendDBTest, MigrateReferrer) { 267 TEST_F(HistoryBackendDBTest, MigrateReferrer) {
266 base::Time now(base::Time::Now()); 268 base::Time now(base::Time::Now());
267 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22)); 269 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22));
268 { 270 {
269 sql::Connection db; 271 sql::Connection db;
270 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); 272 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename)));
271 sql::Statement s(db.GetUniqueStatement( 273 sql::Statement s(db.GetUniqueStatement(
272 "INSERT INTO downloads (id, full_path, url, start_time, " 274 "INSERT INTO downloads (id, full_path, url, start_time, "
273 "received_bytes, total_bytes, state, end_time, opened) VALUES " 275 "received_bytes, total_bytes, state, end_time, opened) VALUES "
274 "(?, ?, ?, ?, ?, ?, ?, ?, ?)")); 276 "(?, ?, ?, ?, ?, ?, ?, ?, ?)"));
275 int64 db_handle = 0; 277 int64_t db_handle = 0;
276 s.BindInt64(0, ++db_handle); 278 s.BindInt64(0, ++db_handle);
277 s.BindString(1, "full_path"); 279 s.BindString(1, "full_path");
278 s.BindString(2, "http://whatever.com/index.html"); 280 s.BindString(2, "http://whatever.com/index.html");
279 s.BindInt64(3, now.ToTimeT()); 281 s.BindInt64(3, now.ToTimeT());
280 s.BindInt64(4, 100); 282 s.BindInt64(4, 100);
281 s.BindInt64(5, 100); 283 s.BindInt64(5, 100);
282 s.BindInt(6, 1); 284 s.BindInt(6, 1);
283 s.BindInt64(7, now.ToTimeT()); 285 s.BindInt64(7, now.ToTimeT());
284 s.BindInt(8, 1); 286 s.BindInt(8, 1);
285 ASSERT_TRUE(s.Run()); 287 ASSERT_TRUE(s.Run());
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } 508 }
507 } 509 }
508 510
509 TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) { 511 TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) {
510 // Create the DB. 512 // Create the DB.
511 CreateBackendAndDatabase(); 513 CreateBackendAndDatabase();
512 514
513 base::Time now(base::Time::Now()); 515 base::Time now(base::Time::Now());
514 516
515 // Add some downloads. 517 // Add some downloads.
516 uint32 id1 = 1, id2 = 2, id3 = 3; 518 uint32_t id1 = 1, id2 = 2, id3 = 3;
517 AddDownload(id1, DownloadState::COMPLETE, now); 519 AddDownload(id1, DownloadState::COMPLETE, now);
518 AddDownload(id2, DownloadState::COMPLETE, now + base::TimeDelta::FromDays(2)); 520 AddDownload(id2, DownloadState::COMPLETE, now + base::TimeDelta::FromDays(2));
519 AddDownload(id3, DownloadState::COMPLETE, now - base::TimeDelta::FromDays(2)); 521 AddDownload(id3, DownloadState::COMPLETE, now - base::TimeDelta::FromDays(2));
520 522
521 // Confirm that resulted in the correct number of rows in the DB. 523 // Confirm that resulted in the correct number of rows in the DB.
522 DeleteBackend(); 524 DeleteBackend();
523 { 525 {
524 sql::Connection db; 526 sql::Connection db;
525 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); 527 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename)));
526 sql::Statement statement(db.GetUniqueStatement( 528 sql::Statement statement(db.GetUniqueStatement(
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 // Current browser version must be already higher than 28. 776 // Current browser version must be already higher than 28.
775 ASSERT_LT(28, HistoryDatabase::GetCurrentVersion()); 777 ASSERT_LT(28, HistoryDatabase::GetCurrentVersion());
776 // Expect that version in DB remains the same. 778 // Expect that version in DB remains the same.
777 EXPECT_EQ(28, meta.GetVersionNumber()); 779 EXPECT_EQ(28, meta.GetVersionNumber());
778 } 780 }
779 } 781 }
780 } 782 }
781 783
782 } // namespace 784 } // namespace
783 } // namespace history 785 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/history_backend_client.h ('k') | components/history/core/browser/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698