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

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

Issue 16951015: Remove TextDatabase from the history service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@replace_fts
Patch Set: Remove QueryOptions.body_only 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
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_database.cc » ('j') | 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 #include <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 rows.push_back(row1); 496 rows.push_back(row1);
497 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); 497 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED);
498 498
499 URLID row1_id = backend_->db_->GetRowForURL(row1.url(), NULL); 499 URLID row1_id = backend_->db_->GetRowForURL(row1.url(), NULL);
500 URLID row2_id = backend_->db_->GetRowForURL(row2.url(), NULL); 500 URLID row2_id = backend_->db_->GetRowForURL(row2.url(), NULL);
501 501
502 // Get the two visits for the URLs we just added. 502 // Get the two visits for the URLs we just added.
503 VisitVector visits; 503 VisitVector visits;
504 backend_->db_->GetVisitsForURL(row1_id, &visits); 504 backend_->db_->GetVisitsForURL(row1_id, &visits);
505 ASSERT_EQ(1U, visits.size()); 505 ASSERT_EQ(1U, visits.size());
506 VisitID visit1_id = visits[0].visit_id;
507 506
508 visits.clear(); 507 visits.clear();
509 backend_->db_->GetVisitsForURL(row2_id, &visits); 508 backend_->db_->GetVisitsForURL(row2_id, &visits);
510 ASSERT_EQ(1U, visits.size()); 509 ASSERT_EQ(1U, visits.size());
511 VisitID visit2_id = visits[0].visit_id;
512 510
513 // The in-memory backend should have been set and it should have gotten the 511 // The in-memory backend should have been set and it should have gotten the
514 // typed URL. 512 // typed URL.
515 ASSERT_TRUE(mem_backend_.get()); 513 ASSERT_TRUE(mem_backend_.get());
516 URLRow outrow1; 514 URLRow outrow1;
517 EXPECT_TRUE(mem_backend_->db_->GetRowForURL(row1.url(), NULL)); 515 EXPECT_TRUE(mem_backend_->db_->GetRowForURL(row1.url(), NULL));
518 516
519 // Add thumbnails for each page. The |Images| take ownership of SkBitmap 517 // Add thumbnails for each page. The |Images| take ownership of SkBitmap
520 // created from decoding the images. 518 // created from decoding the images.
521 ThumbnailScore score(0.25, true, true); 519 ThumbnailScore score(0.25, true, true);
522 scoped_ptr<SkBitmap> google_bitmap( 520 scoped_ptr<SkBitmap> google_bitmap(
523 gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); 521 gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail)));
524 522
525 gfx::Image google_image = gfx::Image::CreateFrom1xBitmap(*google_bitmap); 523 gfx::Image google_image = gfx::Image::CreateFrom1xBitmap(*google_bitmap);
526 524
527 Time time; 525 Time time;
528 GURL gurl; 526 GURL gurl;
529 backend_->thumbnail_db_->SetPageThumbnail(gurl, row1_id, &google_image, 527 backend_->thumbnail_db_->SetPageThumbnail(gurl, row1_id, &google_image,
530 score, time); 528 score, time);
531 scoped_ptr<SkBitmap> weewar_bitmap( 529 scoped_ptr<SkBitmap> weewar_bitmap(
532 gfx::JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail))); 530 gfx::JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail)));
533 gfx::Image weewar_image = gfx::Image::CreateFrom1xBitmap(*weewar_bitmap); 531 gfx::Image weewar_image = gfx::Image::CreateFrom1xBitmap(*weewar_bitmap);
534 backend_->thumbnail_db_->SetPageThumbnail(gurl, row2_id, &weewar_image, 532 backend_->thumbnail_db_->SetPageThumbnail(gurl, row2_id, &weewar_image,
535 score, time); 533 score, time);
536 534
537 // Star row1. 535 // Star row1.
538 bookmark_model_.AddURL( 536 bookmark_model_.AddURL(
539 bookmark_model_.bookmark_bar_node(), 0, string16(), row1.url()); 537 bookmark_model_.bookmark_bar_node(), 0, string16(), row1.url());
540 538
541 // Set full text index for each one.
542 backend_->text_database_->AddPageData(row1.url(), row1_id, visit1_id,
543 row1.last_visit(),
544 UTF8ToUTF16("Title 1"),
545 UTF8ToUTF16("Body 1"));
546 backend_->text_database_->AddPageData(row2.url(), row2_id, visit2_id,
547 row2.last_visit(),
548 UTF8ToUTF16("Title 2"),
549 UTF8ToUTF16("Body 2"));
550
551 // Now finally clear all history. 539 // Now finally clear all history.
552 backend_->DeleteAllHistory(); 540 backend_->DeleteAllHistory();
553 541
554 // The first URL should be preserved but the time should be cleared. 542 // The first URL should be preserved but the time should be cleared.
555 EXPECT_TRUE(backend_->db_->GetRowForURL(row1.url(), &outrow1)); 543 EXPECT_TRUE(backend_->db_->GetRowForURL(row1.url(), &outrow1));
556 EXPECT_EQ(row1.url(), outrow1.url()); 544 EXPECT_EQ(row1.url(), outrow1.url());
557 EXPECT_EQ(0, outrow1.visit_count()); 545 EXPECT_EQ(0, outrow1.visit_count());
558 EXPECT_EQ(0, outrow1.typed_count()); 546 EXPECT_EQ(0, outrow1.typed_count());
559 EXPECT_TRUE(Time() == outrow1.last_visit()); 547 EXPECT_TRUE(Time() == outrow1.last_visit());
560 548
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 594
607 // The remaining URL should still reference the same favicon, even if its 595 // The remaining URL should still reference the same favicon, even if its
608 // ID has changed. 596 // ID has changed.
609 std::vector<IconMapping> mappings; 597 std::vector<IconMapping> mappings;
610 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 598 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
611 outrow1.url(), chrome::FAVICON, &mappings)); 599 outrow1.url(), chrome::FAVICON, &mappings));
612 EXPECT_EQ(1u, mappings.size()); 600 EXPECT_EQ(1u, mappings.size());
613 EXPECT_EQ(out_favicon1, mappings[0].icon_id); 601 EXPECT_EQ(out_favicon1, mappings[0].icon_id);
614 602
615 // The first URL should still be bookmarked. 603 // The first URL should still be bookmarked.
616 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url())); 604 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url()));
palmer 2013/07/12 18:21:02 It'd be good to add some unit tests for the new |H
rmcilroy 2013/07/15 12:47:19 Done.
617
618 // The full text database should have no data.
619 std::vector<TextDatabase::Match> text_matches;
620 Time first_time_searched;
621 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"),
622 QueryOptions(),
623 &text_matches,
624 &first_time_searched);
625 EXPECT_EQ(0U, text_matches.size());
626 } 605 }
627 606
628 // Checks that adding a visit, then calling DeleteAll, and then trying to add 607 // Checks that adding a visit, then calling DeleteAll, and then trying to add
629 // data for the visited page works. This can happen when clearing the history 608 // data for the visited page works. This can happen when clearing the history
630 // immediately after visiting a page. 609 // immediately after visiting a page.
631 TEST_F(HistoryBackendTest, DeleteAllThenAddData) { 610 TEST_F(HistoryBackendTest, DeleteAllThenAddData) {
632 ASSERT_TRUE(backend_.get()); 611 ASSERT_TRUE(backend_.get());
633 612
634 Time visit_time = Time::Now(); 613 Time visit_time = Time::Now();
635 GURL url("http://www.google.com/"); 614 GURL url("http://www.google.com/");
(...skipping 15 matching lines...) Expand all
651 // Clear all history. 630 // Clear all history.
652 backend_->DeleteAllHistory(); 631 backend_->DeleteAllHistory();
653 632
654 // The row should be deleted. 633 // The row should be deleted.
655 EXPECT_FALSE(backend_->db_->GetRowForURL(url, &outrow)); 634 EXPECT_FALSE(backend_->db_->GetRowForURL(url, &outrow));
656 635
657 // The visit should be deleted. 636 // The visit should be deleted.
658 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits); 637 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits);
659 ASSERT_EQ(0U, all_visits.size()); 638 ASSERT_EQ(0U, all_visits.size());
660 639
661 // Try and set the full text index. 640 // Try and set the title.
662 backend_->SetPageTitle(url, UTF8ToUTF16("Title")); 641 backend_->SetPageTitle(url, UTF8ToUTF16("Title"));
663 backend_->SetPageContents(url, UTF8ToUTF16("Body"));
664 642
665 // The row should still be deleted. 643 // The row should still be deleted.
666 EXPECT_FALSE(backend_->db_->GetRowForURL(url, &outrow)); 644 EXPECT_FALSE(backend_->db_->GetRowForURL(url, &outrow));
667 645
668 // The visit should still be deleted. 646 // The visit should still be deleted.
669 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits); 647 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits);
670 ASSERT_EQ(0U, all_visits.size()); 648 ASSERT_EQ(0U, all_visits.size());
671
672 // The full text database should have no data.
673 std::vector<TextDatabase::Match> text_matches;
674 Time first_time_searched;
675 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"),
676 QueryOptions(),
677 &text_matches,
678 &first_time_searched);
679 EXPECT_EQ(0U, text_matches.size());
680 } 649 }
681 650
682 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { 651 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) {
683 GURL favicon_url1("http://www.google.com/favicon.ico"); 652 GURL favicon_url1("http://www.google.com/favicon.ico");
684 GURL favicon_url2("http://news.google.com/favicon.ico"); 653 GURL favicon_url2("http://news.google.com/favicon.ico");
685 654
686 std::vector<unsigned char> data; 655 std::vector<unsigned char> data;
687 data.push_back('1'); 656 data.push_back('1');
688 chrome::FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon( 657 chrome::FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(
689 favicon_url1, 658 favicon_url1,
(...skipping 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after
2809 service->AddPage( 2778 service->AddPage(
2810 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(), 2779 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(),
2811 content::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false); 2780 content::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false);
2812 2781
2813 // This won't actually delete the URL, rather it'll empty out the visits. 2782 // This won't actually delete the URL, rather it'll empty out the visits.
2814 // This triggers blocking on the BookmarkModel. 2783 // This triggers blocking on the BookmarkModel.
2815 service->DeleteURL(url); 2784 service->DeleteURL(url);
2816 } 2785 }
2817 2786
2818 } // namespace history 2787 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698