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

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

Issue 17397003: Add the referrer url to the downloads table in the History database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r207869 Created 7 years, 6 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
« no previous file with comments | « chrome/browser/history/history_database.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // test. 158 // test.
159 base::MessageLoop::current()->PostTask(FROM_HERE, 159 base::MessageLoop::current()->PostTask(FROM_HERE,
160 base::MessageLoop::QuitClosure()); 160 base::MessageLoop::QuitClosure());
161 base::MessageLoop::current()->Run(); 161 base::MessageLoop::current()->Run();
162 } 162 }
163 163
164 int64 AddDownload(DownloadItem::DownloadState state, const Time& time) { 164 int64 AddDownload(DownloadItem::DownloadState state, const Time& time) {
165 std::vector<GURL> url_chain; 165 std::vector<GURL> url_chain;
166 url_chain.push_back(GURL("foo-url")); 166 url_chain.push_back(GURL("foo-url"));
167 167
168 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("foo-path")), 168 DownloadRow download(base::FilePath(FILE_PATH_LITERAL("current-path")),
169 base::FilePath(FILE_PATH_LITERAL("foo-path")), 169 base::FilePath(FILE_PATH_LITERAL("target-path")),
170 url_chain, 170 url_chain,
171 GURL(std::string()), 171 GURL("http://referrer.com/"),
172 time, 172 time,
173 time, 173 time,
174 0, 174 0,
175 512, 175 512,
176 state, 176 state,
177 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, 177 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
178 content::DOWNLOAD_INTERRUPT_REASON_NONE, 178 content::DOWNLOAD_INTERRUPT_REASON_NONE,
179 0, 179 0,
180 0); 180 false);
181 return db_->CreateDownload(download); 181 return db_->CreateDownload(download);
182 } 182 }
183 183
184 base::ScopedTempDir temp_dir_; 184 base::ScopedTempDir temp_dir_;
185 185
186 base::MessageLoopForUI message_loop_; 186 base::MessageLoopForUI message_loop_;
187 187
188 // names of the database files 188 // names of the database files
189 base::FilePath history_dir_; 189 base::FilePath history_dir_;
190 190
(...skipping 23 matching lines...) Expand all
214 } 214 }
215 215
216 TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) { 216 TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) {
217 CreateBackendAndDatabase(); 217 CreateBackendAndDatabase();
218 218
219 // Initially there should be nothing in the downloads database. 219 // Initially there should be nothing in the downloads database.
220 std::vector<DownloadRow> downloads; 220 std::vector<DownloadRow> downloads;
221 db_->QueryDownloads(&downloads); 221 db_->QueryDownloads(&downloads);
222 EXPECT_EQ(0U, downloads.size()); 222 EXPECT_EQ(0U, downloads.size());
223 223
224 // Add a download, test that it was added, remove it, test that it was 224 // Add a download, test that it was added correctly, remove it, test that it
225 // removed. 225 // was removed.
226 DownloadID handle; 226 DownloadID handle;
227 EXPECT_NE(0, handle = AddDownload(DownloadItem::COMPLETE, Time())); 227 Time now = Time();
228 EXPECT_NE(0, handle = AddDownload(DownloadItem::COMPLETE, now));
228 db_->QueryDownloads(&downloads); 229 db_->QueryDownloads(&downloads);
229 EXPECT_EQ(1U, downloads.size()); 230 EXPECT_EQ(1U, downloads.size());
231
232 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("current-path")),
233 downloads[0].current_path);
234 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("target-path")),
235 downloads[0].target_path);
236 EXPECT_EQ(1UL, downloads[0].url_chain.size());
237 EXPECT_EQ(GURL("foo-url"), downloads[0].url_chain[0]);
238 EXPECT_EQ(std::string("http://referrer.com/"),
239 std::string(downloads[0].referrer_url.spec()));
240 EXPECT_EQ(now, downloads[0].start_time);
241 EXPECT_EQ(now, downloads[0].end_time);
242 EXPECT_EQ(0, downloads[0].received_bytes);
243 EXPECT_EQ(512, downloads[0].total_bytes);
244 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0].state);
245 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
246 downloads[0].danger_type);
247 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE,
248 downloads[0].interrupt_reason);
249 EXPECT_FALSE(downloads[0].opened);
250
230 db_->RemoveDownload(handle); 251 db_->RemoveDownload(handle);
231 db_->QueryDownloads(&downloads); 252 db_->QueryDownloads(&downloads);
232 EXPECT_EQ(0U, downloads.size()); 253 EXPECT_EQ(0U, downloads.size());
233 } 254 }
234 255
235 TEST_F(HistoryBackendDBTest, MigrateDownloadsState) { 256 TEST_F(HistoryBackendDBTest, MigrateDownloadsState) {
236 // Create the db we want. 257 // Create the db we want.
237 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22)); 258 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22));
238 { 259 {
239 // Open the db for manual manipulation. 260 // Open the db for manual manipulation.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 EXPECT_TRUE(statement.Step()); 425 EXPECT_TRUE(statement.Step());
405 EXPECT_EQ(2, statement.ColumnInt64(0)); 426 EXPECT_EQ(2, statement.ColumnInt64(0));
406 EXPECT_EQ(0, statement.ColumnInt(1)); 427 EXPECT_EQ(0, statement.ColumnInt(1));
407 EXPECT_EQ("http://whatever.com/index1.html", statement.ColumnString(2)); 428 EXPECT_EQ("http://whatever.com/index1.html", statement.ColumnString(2));
408 429
409 EXPECT_FALSE(statement.Step()); 430 EXPECT_FALSE(statement.Step());
410 } 431 }
411 } 432 }
412 } 433 }
413 434
435 TEST_F(HistoryBackendDBTest, MigrateReferrer) {
436 Time now(base::Time::Now());
437 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22));
438 {
439 sql::Connection db;
440 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
441 sql::Statement s(db.GetUniqueStatement(
442 "INSERT INTO downloads (id, full_path, url, start_time, "
443 "received_bytes, total_bytes, state, end_time, opened) VALUES "
444 "(?, ?, ?, ?, ?, ?, ?, ?, ?)"));
445 int64 db_handle = 0;
446 s.BindInt64(0, ++db_handle);
447 s.BindString(1, "full_path");
448 s.BindString(2, "http://whatever.com/index.html");
449 s.BindInt64(3, now.ToTimeT());
450 s.BindInt64(4, 100);
451 s.BindInt64(5, 100);
452 s.BindInt(6, 1);
453 s.BindInt64(7, now.ToTimeT());
454 s.BindInt(8, 1);
455 ASSERT_TRUE(s.Run());
456 }
457 // Re-open the db using the HistoryDatabase, which should migrate to version
458 // 26, creating the referrer column.
459 CreateBackendAndDatabase();
460 DeleteBackend();
461 {
462 // Re-open the db for manual manipulation.
463 sql::Connection db;
464 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
465 // The version should have been updated.
466 int cur_version = HistoryDatabase::GetCurrentVersion();
467 ASSERT_LE(26, cur_version);
468 {
469 sql::Statement s(db.GetUniqueStatement(
470 "SELECT value FROM meta WHERE key = 'version'"));
471 EXPECT_TRUE(s.Step());
472 EXPECT_EQ(cur_version, s.ColumnInt(0));
473 }
474 {
475 sql::Statement s(db.GetUniqueStatement(
476 "SELECT referrer from downloads"));
477 EXPECT_TRUE(s.Step());
478 EXPECT_EQ(std::string(), s.ColumnString(0));
479 }
480 }
481 }
482
414 TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) { 483 TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) {
415 // Create the DB. 484 // Create the DB.
416 CreateBackendAndDatabase(); 485 CreateBackendAndDatabase();
417 486
418 base::Time now(base::Time::Now()); 487 base::Time now(base::Time::Now());
419 488
420 // Add some downloads. 489 // Add some downloads.
421 AddDownload(DownloadItem::COMPLETE, now); 490 AddDownload(DownloadItem::COMPLETE, now);
422 int64 did2 = AddDownload(DownloadItem::COMPLETE, now + 491 int64 did2 = AddDownload(DownloadItem::COMPLETE, now +
423 base::TimeDelta::FromDays(2)); 492 base::TimeDelta::FromDays(2));
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 std::vector<PageUsageData*> results; 1727 std::vector<PageUsageData*> results;
1659 db_->QuerySegmentUsage(segment_time, 10, &results); 1728 db_->QuerySegmentUsage(segment_time, 10, &results);
1660 ASSERT_EQ(1u, results.size()); 1729 ASSERT_EQ(1u, results.size());
1661 EXPECT_EQ(url, results[0]->GetURL()); 1730 EXPECT_EQ(url, results[0]->GetURL());
1662 EXPECT_EQ(segment_id, results[0]->GetID()); 1731 EXPECT_EQ(segment_id, results[0]->GetID());
1663 EXPECT_EQ(title, results[0]->GetTitle()); 1732 EXPECT_EQ(title, results[0]->GetTitle());
1664 STLDeleteElements(&results); 1733 STLDeleteElements(&results);
1665 } 1734 }
1666 1735
1667 } // namespace history 1736 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698