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

Side by Side Diff: chrome/browser/history/android/android_provider_backend_unittest.cc

Issue 10825085: Move RunAllPendingInMessageLoop from ui_test_utils.h to test_utils.h, so that it can be reused by c… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
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 "chrome/browser/history/android/android_provider_backend.h" 5 #include "chrome/browser/history/android/android_provider_backend.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 ASSERT_TRUE(delegate_.modified_details()); 485 ASSERT_TRUE(delegate_.modified_details());
486 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size()); 486 ASSERT_EQ(1u, delegate_.modified_details()->changed_urls.size());
487 EXPECT_EQ(row1.url(), delegate_.modified_details()->changed_urls[0].url()); 487 EXPECT_EQ(row1.url(), delegate_.modified_details()->changed_urls[0].url());
488 EXPECT_EQ(row1.last_visit_time(), 488 EXPECT_EQ(row1.last_visit_time(),
489 delegate_.modified_details()->changed_urls[0].last_visit()); 489 delegate_.modified_details()->changed_urls[0].last_visit());
490 EXPECT_EQ(row1.visit_count(), 490 EXPECT_EQ(row1.visit_count(),
491 delegate_.modified_details()->changed_urls[0].visit_count()); 491 delegate_.modified_details()->changed_urls[0].visit_count());
492 EXPECT_EQ(row1.title(), 492 EXPECT_EQ(row1.title(),
493 delegate_.modified_details()->changed_urls[0].title()); 493 delegate_.modified_details()->changed_urls[0].title());
494 EXPECT_FALSE(delegate_.favicon_details()); 494 EXPECT_FALSE(delegate_.favicon_details());
495 ui_test_utils::RunAllPendingInMessageLoop(); 495 content::RunAllPendingInMessageLoop();
496 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count()); 496 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count());
497 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0); 497 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0);
498 ASSERT_TRUE(child); 498 ASSERT_TRUE(child);
499 EXPECT_EQ(row1.title(), child->GetTitle()); 499 EXPECT_EQ(row1.title(), child->GetTitle());
500 EXPECT_EQ(row1.url(), child->url()); 500 EXPECT_EQ(row1.url(), child->url());
501 501
502 delegate_.ResetDetails(); 502 delegate_.ResetDetails();
503 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row2)); 503 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row2));
504 EXPECT_FALSE(delegate_.deleted_details()); 504 EXPECT_FALSE(delegate_.deleted_details());
505 ASSERT_TRUE(delegate_.modified_details()); 505 ASSERT_TRUE(delegate_.modified_details());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL, 586 ASSERT_EQ(sql::INIT_OK, thumbnail_db_.Init(thumbnail_db_name_, NULL,
587 &history_db_)); 587 &history_db_));
588 588
589 scoped_ptr<AndroidProviderBackend> backend( 589 scoped_ptr<AndroidProviderBackend> backend(
590 new AndroidProviderBackend(android_cache_db_name_, &history_db_, 590 new AndroidProviderBackend(android_cache_db_name_, &history_db_,
591 &thumbnail_db_, bookmark_model_, &delegate_)); 591 &thumbnail_db_, bookmark_model_, &delegate_));
592 592
593 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row1)); 593 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row1));
594 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row2)); 594 ASSERT_TRUE(backend->InsertHistoryAndBookmark(row2));
595 // Verify the row1 has been added in bookmark model. 595 // Verify the row1 has been added in bookmark model.
596 ui_test_utils::RunAllPendingInMessageLoop(); 596 content::RunAllPendingInMessageLoop();
597 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count()); 597 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count());
598 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0); 598 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0);
599 ASSERT_TRUE(child); 599 ASSERT_TRUE(child);
600 EXPECT_EQ(row1.title(), child->GetTitle()); 600 EXPECT_EQ(row1.title(), child->GetTitle());
601 EXPECT_EQ(row1.url(), child->url()); 601 EXPECT_EQ(row1.url(), child->url());
602 602
603 // Delete the row1. 603 // Delete the row1.
604 std::vector<string16> args; 604 std::vector<string16> args;
605 int deleted_count = 0; 605 int deleted_count = 0;
606 delegate_.ResetDetails(); 606 delegate_.ResetDetails();
607 ASSERT_TRUE(backend->DeleteHistoryAndBookmarks("Favicon IS NULL", args, 607 ASSERT_TRUE(backend->DeleteHistoryAndBookmarks("Favicon IS NULL", args,
608 &deleted_count)); 608 &deleted_count));
609 EXPECT_EQ(1, deleted_count); 609 EXPECT_EQ(1, deleted_count);
610 // Verify the row1 was removed from bookmark model. 610 // Verify the row1 was removed from bookmark model.
611 ui_test_utils::RunAllPendingInMessageLoop(); 611 content::RunAllPendingInMessageLoop();
612 ASSERT_EQ(0, bookmark_model_->mobile_node()->child_count()); 612 ASSERT_EQ(0, bookmark_model_->mobile_node()->child_count());
613 613
614 // Verify notifications 614 // Verify notifications
615 ASSERT_TRUE(delegate_.deleted_details()); 615 ASSERT_TRUE(delegate_.deleted_details());
616 EXPECT_FALSE(delegate_.modified_details()); 616 EXPECT_FALSE(delegate_.modified_details());
617 EXPECT_EQ(1u, delegate_.deleted_details()->rows.size()); 617 EXPECT_EQ(1u, delegate_.deleted_details()->rows.size());
618 EXPECT_EQ(row1.url(), delegate_.deleted_details()->rows[0].url()); 618 EXPECT_EQ(row1.url(), delegate_.deleted_details()->rows[0].url());
619 EXPECT_EQ(row1.last_visit_time(), 619 EXPECT_EQ(row1.last_visit_time(),
620 delegate_.deleted_details()->rows[0].last_visit()); 620 delegate_.deleted_details()->rows[0].last_visit());
621 EXPECT_EQ(row1.title(), 621 EXPECT_EQ(row1.title(),
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 scoped_ptr<AndroidProviderBackend> backend( 777 scoped_ptr<AndroidProviderBackend> backend(
778 new AndroidProviderBackend(android_cache_db_name_, &history_db_, 778 new AndroidProviderBackend(android_cache_db_name_, &history_db_,
779 &thumbnail_db_, bookmark_model_, &delegate_)); 779 &thumbnail_db_, bookmark_model_, &delegate_));
780 780
781 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1); 781 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1);
782 ASSERT_TRUE(id1); 782 ASSERT_TRUE(id1);
783 AndroidURLID id2 = backend->InsertHistoryAndBookmark(row2); 783 AndroidURLID id2 = backend->InsertHistoryAndBookmark(row2);
784 ASSERT_TRUE(id2); 784 ASSERT_TRUE(id2);
785 785
786 // Verify the row1 has been added in bookmark model. 786 // Verify the row1 has been added in bookmark model.
787 ui_test_utils::RunAllPendingInMessageLoop(); 787 content::RunAllPendingInMessageLoop();
788 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count()); 788 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count());
789 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0); 789 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0);
790 ASSERT_TRUE(child); 790 ASSERT_TRUE(child);
791 EXPECT_EQ(row1.title(), child->GetTitle()); 791 EXPECT_EQ(row1.title(), child->GetTitle());
792 EXPECT_EQ(row1.url(), child->url()); 792 EXPECT_EQ(row1.url(), child->url());
793 793
794 // Make sure the url has correctly insertted. 794 // Make sure the url has correctly insertted.
795 URLID url_id1 = history_db_.GetRowForURL(row1.url(), NULL); 795 URLID url_id1 = history_db_.GetRowForURL(row1.url(), NULL);
796 ASSERT_TRUE(url_id1); 796 ASSERT_TRUE(url_id1);
797 URLID url_id2 = history_db_.GetRowForURL(row2.url(), NULL); 797 URLID url_id2 = history_db_.GetRowForURL(row2.url(), NULL);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 ToDatabaseTime(new_row.last_visit())); 854 ToDatabaseTime(new_row.last_visit()));
855 visits.clear(); 855 visits.clear();
856 EXPECT_TRUE(history_db_.GetVisitsForURL(new_row.id(), &visits)); 856 EXPECT_TRUE(history_db_.GetVisitsForURL(new_row.id(), &visits));
857 EXPECT_EQ(10u, visits.size()); 857 EXPECT_EQ(10u, visits.size());
858 AndroidURLRow android_url_row1; 858 AndroidURLRow android_url_row1;
859 ASSERT_TRUE(history_db_.GetAndroidURLRow(new_row.id(), &android_url_row1)); 859 ASSERT_TRUE(history_db_.GetAndroidURLRow(new_row.id(), &android_url_row1));
860 // Android URL ID shouldn't change. 860 // Android URL ID shouldn't change.
861 EXPECT_EQ(id1, android_url_row1.id); 861 EXPECT_EQ(id1, android_url_row1.id);
862 862
863 // Verify the bookmark model was updated. 863 // Verify the bookmark model was updated.
864 ui_test_utils::RunAllPendingInMessageLoop(); 864 content::RunAllPendingInMessageLoop();
865 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count()); 865 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count());
866 const BookmarkNode* child1 = bookmark_model_->mobile_node()->GetChild(0); 866 const BookmarkNode* child1 = bookmark_model_->mobile_node()->GetChild(0);
867 ASSERT_TRUE(child1); 867 ASSERT_TRUE(child1);
868 EXPECT_EQ(row1.title(), child1->GetTitle()); 868 EXPECT_EQ(row1.title(), child1->GetTitle());
869 EXPECT_EQ(update_row1.url(), child1->url()); 869 EXPECT_EQ(update_row1.url(), child1->url());
870 870
871 // Update the URL with visit count, created time, and last visit time. 871 // Update the URL with visit count, created time, and last visit time.
872 HistoryAndBookmarkRow update_row2; 872 HistoryAndBookmarkRow update_row2;
873 update_row2.set_raw_url("somethingelse.com"); 873 update_row2.set_raw_url("somethingelse.com");
874 update_row2.set_url(GURL("http://somethingelse.com")); 874 update_row2.set_url(GURL("http://somethingelse.com"));
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 scoped_ptr<AndroidProviderBackend> backend( 1543 scoped_ptr<AndroidProviderBackend> backend(
1544 new AndroidProviderBackend(android_cache_db_name_, &history_db_, 1544 new AndroidProviderBackend(android_cache_db_name_, &history_db_,
1545 &thumbnail_db_, bookmark_model_, &delegate_)); 1545 &thumbnail_db_, bookmark_model_, &delegate_));
1546 1546
1547 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1); 1547 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1);
1548 ASSERT_TRUE(id1); 1548 ASSERT_TRUE(id1);
1549 AndroidURLID id2 = backend->InsertHistoryAndBookmark(row2); 1549 AndroidURLID id2 = backend->InsertHistoryAndBookmark(row2);
1550 ASSERT_TRUE(id2); 1550 ASSERT_TRUE(id2);
1551 1551
1552 // Verify the row1 has been added in bookmark model. 1552 // Verify the row1 has been added in bookmark model.
1553 ui_test_utils::RunAllPendingInMessageLoop(); 1553 content::RunAllPendingInMessageLoop();
1554 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count()); 1554 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count());
1555 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0); 1555 const BookmarkNode* child = bookmark_model_->mobile_node()->GetChild(0);
1556 ASSERT_TRUE(child); 1556 ASSERT_TRUE(child);
1557 EXPECT_EQ(row1.title(), child->GetTitle()); 1557 EXPECT_EQ(row1.title(), child->GetTitle());
1558 EXPECT_EQ(row1.url(), child->url()); 1558 EXPECT_EQ(row1.url(), child->url());
1559 1559
1560 // Delete history 1560 // Delete history
1561 int deleted_count = 0; 1561 int deleted_count = 0;
1562 ASSERT_TRUE(backend->DeleteHistory(std::string(), std::vector<string16>(), 1562 ASSERT_TRUE(backend->DeleteHistory(std::string(), std::vector<string16>(),
1563 &deleted_count)); 1563 &deleted_count));
1564 EXPECT_EQ(2, deleted_count); 1564 EXPECT_EQ(2, deleted_count);
1565 // The row2 was deleted. 1565 // The row2 was deleted.
1566 EXPECT_FALSE(history_db_.GetRowForURL(row2.url(), NULL)); 1566 EXPECT_FALSE(history_db_.GetRowForURL(row2.url(), NULL));
1567 // Still find the row1. 1567 // Still find the row1.
1568 URLRow url_row; 1568 URLRow url_row;
1569 ASSERT_TRUE(history_db_.GetRowForURL(row1.url(), &url_row)); 1569 ASSERT_TRUE(history_db_.GetRowForURL(row1.url(), &url_row));
1570 // The visit_count was reset. 1570 // The visit_count was reset.
1571 EXPECT_EQ(0, url_row.visit_count()); 1571 EXPECT_EQ(0, url_row.visit_count());
1572 EXPECT_EQ(Time::UnixEpoch(), url_row.last_visit()); 1572 EXPECT_EQ(Time::UnixEpoch(), url_row.last_visit());
1573 1573
1574 // Verify the row1 is still in bookmark model. 1574 // Verify the row1 is still in bookmark model.
1575 ui_test_utils::RunAllPendingInMessageLoop(); 1575 content::RunAllPendingInMessageLoop();
1576 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count()); 1576 ASSERT_EQ(1, bookmark_model_->mobile_node()->child_count());
1577 const BookmarkNode* child1 = bookmark_model_->mobile_node()->GetChild(0); 1577 const BookmarkNode* child1 = bookmark_model_->mobile_node()->GetChild(0);
1578 ASSERT_TRUE(child1); 1578 ASSERT_TRUE(child1);
1579 EXPECT_EQ(row1.title(), child1->GetTitle()); 1579 EXPECT_EQ(row1.title(), child1->GetTitle());
1580 EXPECT_EQ(row1.url(), child1->url()); 1580 EXPECT_EQ(row1.url(), child1->url());
1581 1581
1582 // Verify notification 1582 // Verify notification
1583 ASSERT_TRUE(delegate_.deleted_details()); 1583 ASSERT_TRUE(delegate_.deleted_details());
1584 ASSERT_EQ(2u, delegate_.deleted_details()->rows.size()); 1584 ASSERT_EQ(2u, delegate_.deleted_details()->rows.size());
1585 EXPECT_EQ(row1.url(), 1585 EXPECT_EQ(row1.url(),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 row2.set_is_bookmark(false); 1701 row2.set_is_bookmark(false);
1702 row2.set_title(UTF8ToUTF16("example")); 1702 row2.set_title(UTF8ToUTF16("example"));
1703 std::vector<unsigned char> data; 1703 std::vector<unsigned char> data;
1704 data.push_back('1'); 1704 data.push_back('1');
1705 row2.set_favicon(data); 1705 row2.set_favicon(data);
1706 1706
1707 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1); 1707 AndroidURLID id1 = backend->InsertHistoryAndBookmark(row1);
1708 ASSERT_TRUE(id1); 1708 ASSERT_TRUE(id1);
1709 AndroidURLID id2 = backend->InsertHistoryAndBookmark(row2); 1709 AndroidURLID id2 = backend->InsertHistoryAndBookmark(row2);
1710 ASSERT_TRUE(id2); 1710 ASSERT_TRUE(id2);
1711 ui_test_utils::RunAllPendingInMessageLoop(); 1711 content::RunAllPendingInMessageLoop();
1712 1712
1713 // Query by folder=0, the row1 should returned. 1713 // Query by folder=0, the row1 should returned.
1714 std::vector<HistoryAndBookmarkRow::ColumnID> projections; 1714 std::vector<HistoryAndBookmarkRow::ColumnID> projections;
1715 1715
1716 projections.push_back(HistoryAndBookmarkRow::URL); 1716 projections.push_back(HistoryAndBookmarkRow::URL);
1717 1717
1718 scoped_ptr<AndroidStatement> statement(backend->QueryHistoryAndBookmarks( 1718 scoped_ptr<AndroidStatement> statement(backend->QueryHistoryAndBookmarks(
1719 projections, std::string("folder=0"), std::vector<string16>(), 1719 projections, std::string("folder=0"), std::vector<string16>(),
1720 std::string("url ASC"))); 1720 std::string("url ASC")));
1721 ASSERT_TRUE(statement->statement()->Step()); 1721 ASSERT_TRUE(statement->statement()->Step());
1722 EXPECT_EQ(row1.raw_url(), statement->statement()->ColumnString(0)); 1722 EXPECT_EQ(row1.raw_url(), statement->statement()->ColumnString(0));
1723 EXPECT_FALSE(statement->statement()->Step()); 1723 EXPECT_FALSE(statement->statement()->Step());
1724 1724
1725 // Query by folder=1, the row2 should returned. 1725 // Query by folder=1, the row2 should returned.
1726 statement.reset(backend->QueryHistoryAndBookmarks( 1726 statement.reset(backend->QueryHistoryAndBookmarks(
1727 projections, std::string("folder=1"), std::vector<string16>(), 1727 projections, std::string("folder=1"), std::vector<string16>(),
1728 std::string("url ASC"))); 1728 std::string("url ASC")));
1729 ASSERT_TRUE(statement->statement()->Step()); 1729 ASSERT_TRUE(statement->statement()->Step());
1730 EXPECT_EQ(row2.url(), GURL(statement->statement()->ColumnString(0))); 1730 EXPECT_EQ(row2.url(), GURL(statement->statement()->ColumnString(0)));
1731 EXPECT_FALSE(statement->statement()->Step()); 1731 EXPECT_FALSE(statement->statement()->Step());
1732 } 1732 }
1733 1733
1734 } // namespace history 1734 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698