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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // Make sure we don't have any event pending that could disrupt the next | 157 // Make sure we don't have any event pending that could disrupt the next |
158 // test. | 158 // test. |
159 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 159 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
160 MessageLoop::current()->Run(); | 160 MessageLoop::current()->Run(); |
161 } | 161 } |
162 | 162 |
163 int64 AddDownload(DownloadItem::DownloadState state, const Time& time) { | 163 int64 AddDownload(DownloadItem::DownloadState state, const Time& time) { |
164 std::vector<GURL> url_chain; | 164 std::vector<GURL> url_chain; |
165 url_chain.push_back(GURL("foo-url")); | 165 url_chain.push_back(GURL("foo-url")); |
166 | 166 |
167 DownloadRow download( | 167 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("foo-path")), |
168 base::FilePath(FILE_PATH_LITERAL("foo-path")), | 168 base::FilePath(FILE_PATH_LITERAL("foo-path")), |
169 base::FilePath(FILE_PATH_LITERAL("foo-path")), | 169 url_chain, |
170 url_chain, | 170 GURL(std::string()), |
171 GURL(""), | 171 time, |
172 time, | 172 time, |
173 time, | 173 0, |
174 0, | 174 512, |
175 512, | 175 state, |
176 state, | 176 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
177 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 177 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
178 content::DOWNLOAD_INTERRUPT_REASON_NONE, | 178 0, |
179 0, | 179 0); |
180 0); | |
181 return db_->CreateDownload(download); | 180 return db_->CreateDownload(download); |
182 } | 181 } |
183 | 182 |
184 base::ScopedTempDir temp_dir_; | 183 base::ScopedTempDir temp_dir_; |
185 | 184 |
186 MessageLoopForUI message_loop_; | 185 MessageLoopForUI message_loop_; |
187 | 186 |
188 // names of the database files | 187 // names of the database files |
189 base::FilePath history_dir_; | 188 base::FilePath history_dir_; |
190 | 189 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 309 |
311 // Manually insert some rows. | 310 // Manually insert some rows. |
312 sql::Statement s(db.GetUniqueStatement( | 311 sql::Statement s(db.GetUniqueStatement( |
313 "INSERT INTO downloads (id, full_path, url, start_time, " | 312 "INSERT INTO downloads (id, full_path, url, start_time, " |
314 "received_bytes, total_bytes, state, end_time, opened) VALUES " | 313 "received_bytes, total_bytes, state, end_time, opened) VALUES " |
315 "(?, ?, ?, ?, ?, ?, ?, ?, ?)")); | 314 "(?, ?, ?, ?, ?, ?, ?, ?, ?)")); |
316 | 315 |
317 int64 db_handle = 0; | 316 int64 db_handle = 0; |
318 // Null path. | 317 // Null path. |
319 s.BindInt64(0, ++db_handle); | 318 s.BindInt64(0, ++db_handle); |
320 s.BindString(1, ""); | 319 s.BindString(1, std::string()); |
321 s.BindString(2, "http://whatever.com/index.html"); | 320 s.BindString(2, "http://whatever.com/index.html"); |
322 s.BindInt64(3, now.ToTimeT()); | 321 s.BindInt64(3, now.ToTimeT()); |
323 s.BindInt64(4, 100); | 322 s.BindInt64(4, 100); |
324 s.BindInt64(5, 100); | 323 s.BindInt64(5, 100); |
325 s.BindInt(6, 1); | 324 s.BindInt(6, 1); |
326 s.BindInt64(7, now.ToTimeT()); | 325 s.BindInt64(7, now.ToTimeT()); |
327 s.BindInt(8, 1); | 326 s.BindInt(8, 1); |
328 ASSERT_TRUE(s.Run()); | 327 ASSERT_TRUE(s.Run()); |
329 s.Reset(true); | 328 s.Reset(true); |
330 | 329 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 "Select Count(*) from downloads_url_chains")); | 456 "Select Count(*) from downloads_url_chains")); |
458 EXPECT_TRUE(statement1.Step()); | 457 EXPECT_TRUE(statement1.Step()); |
459 EXPECT_EQ(1, statement1.ColumnInt(0)); | 458 EXPECT_EQ(1, statement1.ColumnInt(0)); |
460 } | 459 } |
461 } | 460 } |
462 | 461 |
463 TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) { | 462 TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) { |
464 CreateBackendAndDatabase(); | 463 CreateBackendAndDatabase(); |
465 base::Time now(base::Time::Now()); | 464 base::Time now(base::Time::Now()); |
466 std::vector<GURL> url_chain; | 465 std::vector<GURL> url_chain; |
467 DownloadRow download( | 466 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("foo-path")), |
468 base::FilePath(FILE_PATH_LITERAL("foo-path")), | 467 base::FilePath(FILE_PATH_LITERAL("foo-path")), |
469 base::FilePath(FILE_PATH_LITERAL("foo-path")), | 468 url_chain, |
470 url_chain, | 469 GURL(std::string()), |
471 GURL(""), | 470 now, |
472 now, | 471 now, |
473 now, | 472 0, |
474 0, | 473 512, |
475 512, | 474 DownloadItem::COMPLETE, |
476 DownloadItem::COMPLETE, | 475 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
477 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 476 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
478 content::DOWNLOAD_INTERRUPT_REASON_NONE, | 477 0, |
479 0, | 478 0); |
480 0); | |
481 | 479 |
482 // Creating records without any urls should fail. | 480 // Creating records without any urls should fail. |
483 EXPECT_EQ(DownloadDatabase::kUninitializedHandle, | 481 EXPECT_EQ(DownloadDatabase::kUninitializedHandle, |
484 db_->CreateDownload(download)); | 482 db_->CreateDownload(download)); |
485 | 483 |
486 download.url_chain.push_back(GURL("foo-url")); | 484 download.url_chain.push_back(GURL("foo-url")); |
487 EXPECT_EQ(1, db_->CreateDownload(download)); | 485 EXPECT_EQ(1, db_->CreateDownload(download)); |
488 | 486 |
489 // Pretend that the URLs were dropped. | 487 // Pretend that the URLs were dropped. |
490 DeleteBackend(); | 488 DeleteBackend(); |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 std::vector<PageUsageData*> results; | 1684 std::vector<PageUsageData*> results; |
1687 db_->QuerySegmentUsage(segment_time, 10, &results); | 1685 db_->QuerySegmentUsage(segment_time, 10, &results); |
1688 ASSERT_EQ(1u, results.size()); | 1686 ASSERT_EQ(1u, results.size()); |
1689 EXPECT_EQ(url, results[0]->GetURL()); | 1687 EXPECT_EQ(url, results[0]->GetURL()); |
1690 EXPECT_EQ(segment_id, results[0]->GetID()); | 1688 EXPECT_EQ(segment_id, results[0]->GetID()); |
1691 EXPECT_EQ(title, results[0]->GetTitle()); | 1689 EXPECT_EQ(title, results[0]->GetTitle()); |
1692 STLDeleteElements(&results); | 1690 STLDeleteElements(&results); |
1693 } | 1691 } |
1694 | 1692 |
1695 } // namespace history | 1693 } // namespace history |
OLD | NEW |