| 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 #include <set> | 5 #include <set> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // backend directly. Most of the history backend functions are tested by the | 38 // backend directly. Most of the history backend functions are tested by the |
| 39 // history unit test. Because of the elaborate callbacks involved, this is no | 39 // history unit test. Because of the elaborate callbacks involved, this is no |
| 40 // harder than calling it directly for many things. | 40 // harder than calling it directly for many things. |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 // data we'll put into the thumbnail database | 44 // data we'll put into the thumbnail database |
| 45 static const unsigned char blob1[] = | 45 static const unsigned char blob1[] = |
| 46 "12346102356120394751634516591348710478123649165419234519234512349134"; | 46 "12346102356120394751634516591348710478123649165419234519234512349134"; |
| 47 | 47 |
| 48 static const gfx::Size kSmallSize = gfx::Size(16, 16); |
| 49 static const gfx::Size kLargeSize = gfx::Size(48, 48); |
| 50 |
| 48 } // namepace | 51 } // namepace |
| 49 | 52 |
| 50 namespace history { | 53 namespace history { |
| 51 | 54 |
| 52 class HistoryBackendTest; | 55 class HistoryBackendTest; |
| 53 | 56 |
| 54 // This must be a separate object since HistoryBackend manages its lifetime. | 57 // This must be a separate object since HistoryBackend manages its lifetime. |
| 55 // This just forwards the messages we're interested in to the test object. | 58 // This just forwards the messages we're interested in to the test object. |
| 56 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { | 59 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { |
| 57 public: | 60 public: |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 #define MAYBE_Loaded Loaded | 283 #define MAYBE_Loaded Loaded |
| 281 #endif // defined(OS_WIN) | 284 #endif // defined(OS_WIN) |
| 282 TEST_F(HistoryBackendTest, MAYBE_Loaded) { | 285 TEST_F(HistoryBackendTest, MAYBE_Loaded) { |
| 283 ASSERT_TRUE(backend_.get()); | 286 ASSERT_TRUE(backend_.get()); |
| 284 ASSERT_TRUE(loaded_); | 287 ASSERT_TRUE(loaded_); |
| 285 } | 288 } |
| 286 | 289 |
| 287 TEST_F(HistoryBackendTest, DeleteAll) { | 290 TEST_F(HistoryBackendTest, DeleteAll) { |
| 288 ASSERT_TRUE(backend_.get()); | 291 ASSERT_TRUE(backend_.get()); |
| 289 | 292 |
| 290 // Add two favicons, use the characters '1' and '2' for the image data. Note | 293 // Add two favicons, each with two bitmaps. Note that we add favicon2 before |
| 291 // that we do these in the opposite order. This is so the first one gets ID | 294 // adding favicon1. This is so that favicon1 one gets ID 2 autoassigned to |
| 292 // 2 autoassigned to the database, which will change when the other one is | 295 // the database, which will change when the other one is deleted. This way |
| 293 // deleted. This way we can test that updating works properly. | 296 // we can test that updating works properly. |
| 294 GURL favicon_url1("http://www.google.com/favicon.ico"); | 297 GURL favicon_url1("http://www.google.com/favicon.ico"); |
| 295 GURL favicon_url2("http://news.google.com/favicon.ico"); | 298 GURL favicon_url2("http://news.google.com/favicon.ico"); |
| 296 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2, | 299 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2, |
| 297 FAVICON); | 300 FAVICON); |
| 298 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1, | 301 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1, |
| 299 FAVICON); | 302 FAVICON); |
| 300 | 303 |
| 301 std::vector<unsigned char> data; | 304 std::vector<unsigned char> data; |
| 302 data.push_back('1'); | 305 data.push_back('a'); |
| 303 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon(favicon1, | 306 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon1, |
| 304 new base::RefCountedBytes(data), Time::Now())); | 307 new base::RefCountedBytes(data), Time::Now(), kSmallSize)); |
| 308 data[0] = 'b'; |
| 309 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon1, |
| 310 new base::RefCountedBytes(data), Time::Now(), kLargeSize)); |
| 305 | 311 |
| 306 data[0] = '2'; | 312 data[0] = 'c'; |
| 307 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( | 313 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon2, |
| 308 favicon2, new base::RefCountedBytes(data), Time::Now())); | 314 new base::RefCountedBytes(data), Time::Now(), kSmallSize)); |
| 315 data[0] = 'd'; |
| 316 EXPECT_TRUE(backend_->thumbnail_db_->AddFaviconBitmap(favicon2, |
| 317 new base::RefCountedBytes(data), Time::Now(), kLargeSize)); |
| 309 | 318 |
| 310 // First visit two URLs. | 319 // First visit two URLs. |
| 311 URLRow row1(GURL("http://www.google.com/")); | 320 URLRow row1(GURL("http://www.google.com/")); |
| 312 row1.set_visit_count(2); | 321 row1.set_visit_count(2); |
| 313 row1.set_typed_count(1); | 322 row1.set_typed_count(1); |
| 314 row1.set_last_visit(Time::Now()); | 323 row1.set_last_visit(Time::Now()); |
| 315 backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1); | 324 backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1); |
| 316 | 325 |
| 317 URLRow row2(GURL("http://news.google.com/")); | 326 URLRow row2(GURL("http://news.google.com/")); |
| 318 row2.set_visit_count(1); | 327 row2.set_visit_count(1); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 VisitVector all_visits; | 403 VisitVector all_visits; |
| 395 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits); | 404 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits); |
| 396 ASSERT_EQ(0U, all_visits.size()); | 405 ASSERT_EQ(0U, all_visits.size()); |
| 397 | 406 |
| 398 // All thumbnails should be deleted. | 407 // All thumbnails should be deleted. |
| 399 std::vector<unsigned char> out_data; | 408 std::vector<unsigned char> out_data; |
| 400 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(outrow1.id(), | 409 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(outrow1.id(), |
| 401 &out_data)); | 410 &out_data)); |
| 402 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(row2_id, &out_data)); | 411 EXPECT_FALSE(backend_->thumbnail_db_->GetPageThumbnail(row2_id, &out_data)); |
| 403 | 412 |
| 404 // We should have a favicon for the first URL only. We look them up by favicon | 413 // We should have a favicon and favicon bitmaps for the first URL only. We |
| 405 // URL since the IDs may hav changed. | 414 // look them up by favicon URL since the IDs may have changed. |
| 406 FaviconID out_favicon1 = backend_->thumbnail_db_-> | 415 FaviconID out_favicon1 = backend_->thumbnail_db_-> |
| 407 GetFaviconIDForFaviconURL(favicon_url1, FAVICON, NULL); | 416 GetFaviconIDForFaviconURL(favicon_url1, FAVICON, NULL); |
| 408 EXPECT_TRUE(out_favicon1); | 417 EXPECT_TRUE(out_favicon1); |
| 418 |
| 419 std::vector<FaviconBitmap> favicon_bitmaps; |
| 420 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps( |
| 421 out_favicon1, &favicon_bitmaps)); |
| 422 ASSERT_EQ(2u, favicon_bitmaps.size()); |
| 423 |
| 424 FaviconBitmap favicon_bitmap1 = favicon_bitmaps[0]; |
| 425 FaviconBitmap favicon_bitmap2 = favicon_bitmaps[1]; |
| 426 |
| 427 // Bitmaps do not need to be in particular order. |
| 428 if (favicon_bitmap1.pixel_size == kLargeSize) { |
| 429 FaviconBitmap tmp_favicon_bitmap = favicon_bitmap1; |
| 430 favicon_bitmap1 = favicon_bitmap2; |
| 431 favicon_bitmap2 = tmp_favicon_bitmap; |
| 432 } |
| 433 |
| 434 EXPECT_EQ('a', *favicon_bitmap1.bitmap_data->front()); |
| 435 EXPECT_EQ(kSmallSize, favicon_bitmap1.pixel_size); |
| 436 |
| 437 EXPECT_EQ('b', *favicon_bitmap2.bitmap_data->front()); |
| 438 EXPECT_EQ(kLargeSize, favicon_bitmap2.pixel_size); |
| 439 |
| 409 FaviconID out_favicon2 = backend_->thumbnail_db_-> | 440 FaviconID out_favicon2 = backend_->thumbnail_db_-> |
| 410 GetFaviconIDForFaviconURL(favicon_url2, FAVICON, NULL); | 441 GetFaviconIDForFaviconURL(favicon_url2, FAVICON, NULL); |
| 411 EXPECT_FALSE(out_favicon2) << "Favicon not deleted"; | 442 EXPECT_FALSE(out_favicon2) << "Favicon not deleted"; |
| 412 | 443 |
| 413 // The remaining URL should still reference the same favicon, even if its | 444 // The remaining URL should still reference the same favicon, even if its |
| 414 // ID has changed. | 445 // ID has changed. |
| 415 EXPECT_EQ(out_favicon1, GetFavicon(outrow1.url(), FAVICON)); | 446 EXPECT_EQ(out_favicon1, GetFavicon(outrow1.url(), FAVICON)); |
| 416 | 447 |
| 417 // The first URL should still be bookmarked. | 448 // The first URL should still be bookmarked. |
| 418 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url())); | 449 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url())); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"), | 509 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"), |
| 479 QueryOptions(), | 510 QueryOptions(), |
| 480 &text_matches, | 511 &text_matches, |
| 481 &first_time_searched); | 512 &first_time_searched); |
| 482 EXPECT_EQ(0U, text_matches.size()); | 513 EXPECT_EQ(0U, text_matches.size()); |
| 483 } | 514 } |
| 484 | 515 |
| 485 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { | 516 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { |
| 486 GURL favicon_url1("http://www.google.com/favicon.ico"); | 517 GURL favicon_url1("http://www.google.com/favicon.ico"); |
| 487 GURL favicon_url2("http://news.google.com/favicon.ico"); | 518 GURL favicon_url2("http://news.google.com/favicon.ico"); |
| 488 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon(favicon_url2, | |
| 489 FAVICON); | |
| 490 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1, | |
| 491 FAVICON); | |
| 492 | 519 |
| 493 std::vector<unsigned char> data; | 520 std::vector<unsigned char> data; |
| 494 data.push_back('1'); | 521 data.push_back('1'); |
| 495 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( | 522 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon( |
| 496 favicon1, new base::RefCountedBytes(data), Time::Now())); | 523 favicon_url1, |
| 524 FAVICON, |
| 525 "0 0", |
| 526 new base::RefCountedBytes(data), |
| 527 Time::Now(), |
| 528 gfx::Size()); |
| 497 | 529 |
| 498 data[0] = '2'; | 530 data[0] = '2'; |
| 499 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon( | 531 FaviconID favicon2 = backend_->thumbnail_db_->AddFavicon( |
| 500 favicon2, new base::RefCountedBytes(data), Time::Now())); | 532 favicon_url2, |
| 533 FAVICON, |
| 534 "0 0", |
| 535 new base::RefCountedBytes(data), |
| 536 Time::Now(), |
| 537 gfx::Size()); |
| 501 | 538 |
| 502 // First visit two URLs. | 539 // First visit two URLs. |
| 503 URLRow row1(GURL("http://www.google.com/")); | 540 URLRow row1(GURL("http://www.google.com/")); |
| 504 row1.set_visit_count(2); | 541 row1.set_visit_count(2); |
| 505 row1.set_typed_count(1); | 542 row1.set_typed_count(1); |
| 506 row1.set_last_visit(Time::Now()); | 543 row1.set_last_visit(Time::Now()); |
| 507 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); | 544 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); |
| 508 | 545 |
| 509 URLRow row2(GURL("http://news.google.com/")); | 546 URLRow row2(GURL("http://news.google.com/")); |
| 510 row2.set_visit_count(1); | 547 row2.set_visit_count(1); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 AddClientRedirect(url_b, url_c, true, base::Time(), | 692 AddClientRedirect(url_b, url_c, true, base::Time(), |
| 656 &transition1, &transition2); | 693 &transition1, &transition2); |
| 657 EXPECT_FALSE(transition1 & content::PAGE_TRANSITION_CHAIN_END); | 694 EXPECT_FALSE(transition1 & content::PAGE_TRANSITION_CHAIN_END); |
| 658 EXPECT_TRUE(transition2 & content::PAGE_TRANSITION_CHAIN_END); | 695 EXPECT_TRUE(transition2 & content::PAGE_TRANSITION_CHAIN_END); |
| 659 } | 696 } |
| 660 | 697 |
| 661 TEST_F(HistoryBackendTest, ImportedFaviconsTest) { | 698 TEST_F(HistoryBackendTest, ImportedFaviconsTest) { |
| 662 // Setup test data - two Urls in the history, one with favicon assigned and | 699 // Setup test data - two Urls in the history, one with favicon assigned and |
| 663 // one without. | 700 // one without. |
| 664 GURL favicon_url1("http://www.google.com/favicon.ico"); | 701 GURL favicon_url1("http://www.google.com/favicon.ico"); |
| 665 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(favicon_url1, | |
| 666 FAVICON); | |
| 667 std::vector<unsigned char> data; | 702 std::vector<unsigned char> data; |
| 668 data.push_back('1'); | 703 data.push_back('1'); |
| 669 EXPECT_TRUE(backend_->thumbnail_db_->SetFavicon(favicon1, | 704 FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon( |
| 670 base::RefCountedBytes::TakeVector(&data), Time::Now())); | 705 favicon_url1, |
| 706 FAVICON, |
| 707 "0 0", |
| 708 base::RefCountedBytes::TakeVector(&data), |
| 709 Time::Now(), |
| 710 gfx::Size()); |
| 671 URLRow row1(GURL("http://www.google.com/")); | 711 URLRow row1(GURL("http://www.google.com/")); |
| 672 row1.set_visit_count(1); | 712 row1.set_visit_count(1); |
| 673 row1.set_last_visit(Time::Now()); | 713 row1.set_last_visit(Time::Now()); |
| 674 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); | 714 EXPECT_TRUE(backend_->thumbnail_db_->AddIconMapping(row1.url(), favicon1)); |
| 675 | 715 |
| 676 URLRow row2(GURL("http://news.google.com/")); | 716 URLRow row2(GURL("http://news.google.com/")); |
| 677 row2.set_visit_count(1); | 717 row2.set_visit_count(1); |
| 678 row2.set_last_visit(Time::Now()); | 718 row2.set_last_visit(Time::Now()); |
| 679 URLRows rows; | 719 URLRows rows; |
| 680 rows.push_back(row1); | 720 rows.push_back(row1); |
| (...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 | 1607 |
| 1568 backend_->DeleteURL(url); | 1608 backend_->DeleteURL(url); |
| 1569 backend_->AddPageNoVisitForBookmark(url, string16()); | 1609 backend_->AddPageNoVisitForBookmark(url, string16()); |
| 1570 backend_->GetURL(url, &row); | 1610 backend_->GetURL(url, &row); |
| 1571 EXPECT_EQ(url, row.url()); | 1611 EXPECT_EQ(url, row.url()); |
| 1572 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); | 1612 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); |
| 1573 EXPECT_EQ(0, row.visit_count()); | 1613 EXPECT_EQ(0, row.visit_count()); |
| 1574 } | 1614 } |
| 1575 | 1615 |
| 1576 } // namespace history | 1616 } // namespace history |
| OLD | NEW |