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

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

Issue 15275004: bookmarks: Get rid of the dependency on history_notifications.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more android fixes Created 7 years, 7 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 <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"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/string16.h" 18 #include "base/string16.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
21 #include "chrome/browser/bookmarks/bookmark_model.h" 21 #include "chrome/browser/bookmarks/bookmark_model.h"
22 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
22 #include "chrome/browser/bookmarks/bookmark_utils.h" 23 #include "chrome/browser/bookmarks/bookmark_utils.h"
24 #include "chrome/browser/favicon/favicon_changed_details.h"
23 #include "chrome/browser/favicon/imported_favicon_usage.h" 25 #include "chrome/browser/favicon/imported_favicon_usage.h"
24 #include "chrome/browser/history/history_backend.h" 26 #include "chrome/browser/history/history_backend.h"
25 #include "chrome/browser/history/history_notifications.h" 27 #include "chrome/browser/history/history_notifications.h"
28 #include "chrome/browser/history/history_service.h"
29 #include "chrome/browser/history/history_service_factory.h"
26 #include "chrome/browser/history/in_memory_database.h" 30 #include "chrome/browser/history/in_memory_database.h"
27 #include "chrome/browser/history/in_memory_history_backend.h" 31 #include "chrome/browser/history/in_memory_history_backend.h"
28 #include "chrome/browser/history/visit_filter.h" 32 #include "chrome/browser/history/visit_filter.h"
29 #include "chrome/common/chrome_constants.h" 33 #include "chrome/common/chrome_constants.h"
30 #include "chrome/common/chrome_paths.h" 34 #include "chrome/common/chrome_paths.h"
31 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/thumbnail_score.h" 36 #include "chrome/common/thumbnail_score.h"
37 #include "chrome/test/base/testing_profile.h"
38 #include "chrome/test/base/ui_test_utils.h"
33 #include "chrome/tools/profiles/thumbnail-inl.h" 39 #include "chrome/tools/profiles/thumbnail-inl.h"
34 #include "content/public/browser/notification_details.h" 40 #include "content/public/browser/notification_details.h"
35 #include "content/public/browser/notification_source.h" 41 #include "content/public/browser/notification_source.h"
42 #include "content/public/test/test_browser_thread.h"
36 #include "googleurl/src/gurl.h" 43 #include "googleurl/src/gurl.h"
37 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
38 #include "third_party/skia/include/core/SkBitmap.h" 45 #include "third_party/skia/include/core/SkBitmap.h"
39 #include "ui/gfx/codec/jpeg_codec.h" 46 #include "ui/gfx/codec/jpeg_codec.h"
40 #include "ui/gfx/image/image.h" 47 #include "ui/gfx/image/image.h"
41 48
42 using base::Time; 49 using base::Time;
43 using base::TimeDelta; 50 using base::TimeDelta;
44 51
45 // This file only tests functionality where it is most convenient to call the 52 // This file only tests functionality where it is most convenient to call the
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // This must be a separate object since HistoryBackend manages its lifetime. 85 // This must be a separate object since HistoryBackend manages its lifetime.
79 // This just forwards the messages we're interested in to the test object. 86 // This just forwards the messages we're interested in to the test object.
80 class HistoryBackendTestDelegate : public HistoryBackend::Delegate { 87 class HistoryBackendTestDelegate : public HistoryBackend::Delegate {
81 public: 88 public:
82 explicit HistoryBackendTestDelegate(HistoryBackendTest* test) : test_(test) {} 89 explicit HistoryBackendTestDelegate(HistoryBackendTest* test) : test_(test) {}
83 90
84 virtual void NotifyProfileError(int backend_id, 91 virtual void NotifyProfileError(int backend_id,
85 sql::InitStatus init_status) OVERRIDE {} 92 sql::InitStatus init_status) OVERRIDE {}
86 virtual void SetInMemoryBackend(int backend_id, 93 virtual void SetInMemoryBackend(int backend_id,
87 InMemoryHistoryBackend* backend) OVERRIDE; 94 InMemoryHistoryBackend* backend) OVERRIDE;
95 virtual void SendFaviconChangedNotification(
96 chrome::FaviconChangedDetails* details) OVERRIDE;
88 virtual void BroadcastNotifications(int type, 97 virtual void BroadcastNotifications(int type,
89 HistoryDetails* details) OVERRIDE; 98 HistoryDetails* details) OVERRIDE;
90 virtual void DBLoaded(int backend_id) OVERRIDE; 99 virtual void DBLoaded(int backend_id) OVERRIDE;
91 virtual void StartTopSitesMigration(int backend_id) OVERRIDE; 100 virtual void StartTopSitesMigration(int backend_id) OVERRIDE;
92 virtual void NotifyVisitDBObserversOnAddVisit( 101 virtual void NotifyVisitDBObserversOnAddVisit(
93 const BriefVisitInfo& info) OVERRIDE {} 102 const BriefVisitInfo& info) OVERRIDE {}
94 103
95 private: 104 private:
96 // Not owned by us. 105 // Not owned by us.
97 HistoryBackendTest* test_; 106 HistoryBackendTest* test_;
(...skipping 13 matching lines...) Expand all
111 AddRequest(request, this); 120 AddRequest(request, this);
112 return request->handle(); 121 return request->handle();
113 } 122 }
114 }; 123 };
115 124
116 class HistoryBackendTest : public testing::Test { 125 class HistoryBackendTest : public testing::Test {
117 public: 126 public:
118 HistoryBackendTest() 127 HistoryBackendTest()
119 : bookmark_model_(NULL), 128 : bookmark_model_(NULL),
120 loaded_(false), 129 loaded_(false),
121 num_broadcasted_notifications_(0) { 130 num_favicon_notifications_(0),
131 num_broadcasted_notifications_(0),
132 ui_thread_(content::BrowserThread::UI, &message_loop_) {
122 } 133 }
123 134
124 virtual ~HistoryBackendTest() { 135 virtual ~HistoryBackendTest() {
125 } 136 }
126 137
127 // Callback for QueryMostVisited. 138 // Callback for QueryMostVisited.
128 void OnQueryMostVisited(CancelableRequestProvider::Handle handle, 139 void OnQueryMostVisited(CancelableRequestProvider::Handle handle,
129 history::MostVisitedURLList data) { 140 history::MostVisitedURLList data) {
130 most_visited_list_.swap(data); 141 most_visited_list_.swap(data);
131 } 142 }
132 143
133 // Callback for QueryFiltered. 144 // Callback for QueryFiltered.
134 void OnQueryFiltered(CancelableRequestProvider::Handle handle, 145 void OnQueryFiltered(CancelableRequestProvider::Handle handle,
135 const history::FilteredURLList& data) { 146 const history::FilteredURLList& data) {
136 filtered_list_ = data; 147 filtered_list_ = data;
137 } 148 }
138 149
139 const history::MostVisitedURLList& get_most_visited_list() const { 150 const history::MostVisitedURLList& get_most_visited_list() const {
140 return most_visited_list_; 151 return most_visited_list_;
141 } 152 }
142 153
143 const history::FilteredURLList& get_filtered_list() const { 154 const history::FilteredURLList& get_filtered_list() const {
144 return filtered_list_; 155 return filtered_list_;
145 } 156 }
146 157
158 int num_favicon_notifications() const { return num_favicon_notifications_; }
159
147 int num_broadcasted_notifications() const { 160 int num_broadcasted_notifications() const {
148 return num_broadcasted_notifications_; 161 return num_broadcasted_notifications_;
149 } 162 }
150 163
151 protected: 164 protected:
152 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. 165 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure.
153 scoped_ptr<InMemoryHistoryBackend> mem_backend_; 166 scoped_ptr<InMemoryHistoryBackend> mem_backend_;
154 167
155 void AddRedirectChain(const char* sequence[], int page_id) { 168 void AddRedirectChain(const char* sequence[], int page_id) {
156 AddRedirectChainWithTransitionAndTime(sequence, page_id, 169 AddRedirectChainWithTransitionAndTime(sequence, page_id,
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 backend_->Closing(); 397 backend_->Closing();
385 backend_ = NULL; 398 backend_ = NULL;
386 mem_backend_.reset(); 399 mem_backend_.reset();
387 file_util::Delete(test_dir_, true); 400 file_util::Delete(test_dir_, true);
388 } 401 }
389 402
390 void SetInMemoryBackend(int backend_id, InMemoryHistoryBackend* backend) { 403 void SetInMemoryBackend(int backend_id, InMemoryHistoryBackend* backend) {
391 mem_backend_.reset(backend); 404 mem_backend_.reset(backend);
392 } 405 }
393 406
407 void SendFaviconChangedNotification(chrome::FaviconChangedDetails* details) {
408 ++num_favicon_notifications_;
409 // The backend passes ownership of the details pointer to us.
410 delete details;
411 }
412
394 void BroadcastNotifications(int type, 413 void BroadcastNotifications(int type,
395 HistoryDetails* details) { 414 HistoryDetails* details) {
396 ++num_broadcasted_notifications_; 415 ++num_broadcasted_notifications_;
397 416
398 // Send the notifications directly to the in-memory database. 417 // Send the notifications directly to the in-memory database.
399 content::Details<HistoryDetails> det(details); 418 content::Details<HistoryDetails> det(details);
400 mem_backend_->Observe(type, content::Source<HistoryBackendTest>(NULL), det); 419 mem_backend_->Observe(type, content::Source<HistoryBackendTest>(NULL), det);
401 420
402 // The backend passes ownership of the details pointer to us. 421 // The backend passes ownership of the details pointer to us.
403 delete details; 422 delete details;
404 } 423 }
405 424
425 // The number of chrome::NOTIFICATION_FAVICON_CHANGED notifications that were
426 // dispatched.
427 int num_favicon_notifications_;
428
406 // The number of notifications which were broadcasted. 429 // The number of notifications which were broadcasted.
407 int num_broadcasted_notifications_; 430 int num_broadcasted_notifications_;
408 431
409 MessageLoop message_loop_; 432 MessageLoop message_loop_;
433 content::TestBrowserThread ui_thread_;
410 base::FilePath test_dir_; 434 base::FilePath test_dir_;
411 history::MostVisitedURLList most_visited_list_; 435 history::MostVisitedURLList most_visited_list_;
412 history::FilteredURLList filtered_list_; 436 history::FilteredURLList filtered_list_;
413 }; 437 };
414 438
415 void HistoryBackendTestDelegate::SetInMemoryBackend(int backend_id, 439 void HistoryBackendTestDelegate::SetInMemoryBackend(int backend_id,
416 InMemoryHistoryBackend* backend) { 440 InMemoryHistoryBackend* backend) {
417 test_->SetInMemoryBackend(backend_id, backend); 441 test_->SetInMemoryBackend(backend_id, backend);
418 } 442 }
419 443
444 void HistoryBackendTestDelegate::SendFaviconChangedNotification(
445 chrome::FaviconChangedDetails* details) {
446 test_->SendFaviconChangedNotification(details);
447 }
448
420 void HistoryBackendTestDelegate::BroadcastNotifications( 449 void HistoryBackendTestDelegate::BroadcastNotifications(
421 int type, 450 int type,
422 HistoryDetails* details) { 451 HistoryDetails* details) {
423 test_->BroadcastNotifications(type, details); 452 test_->BroadcastNotifications(type, details);
424 } 453 }
425 454
426 void HistoryBackendTestDelegate::DBLoaded(int backend_id) { 455 void HistoryBackendTestDelegate::DBLoaded(int backend_id) {
427 test_->loaded_ = true; 456 test_->loaded_ = true;
428 } 457 }
429 458
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 favicon_bitmap_data.clear(); 1498 favicon_bitmap_data.clear();
1470 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data); 1499 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
1471 1500
1472 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmap(large_bitmap_id, NULL, 1501 EXPECT_FALSE(backend_->thumbnail_db_->GetFaviconBitmap(large_bitmap_id, NULL,
1473 NULL, NULL)); 1502 NULL, NULL));
1474 icon_mappings.clear(); 1503 icon_mappings.clear();
1475 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1504 EXPECT_FALSE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1476 &icon_mappings)); 1505 &icon_mappings));
1477 1506
1478 // Notifications should have been broadcast for each call to SetFavicons(). 1507 // Notifications should have been broadcast for each call to SetFavicons().
1479 EXPECT_EQ(3, num_broadcasted_notifications()); 1508 EXPECT_EQ(3, num_favicon_notifications());
1480 } 1509 }
1481 1510
1482 // Test updating a single favicon bitmap's data via SetFavicons. 1511 // Test updating a single favicon bitmap's data via SetFavicons.
1483 TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) { 1512 TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) {
1484 const GURL page_url("http://www.google.com/"); 1513 const GURL page_url("http://www.google.com/");
1485 const GURL icon_url("http://www.google.com/icon"); 1514 const GURL icon_url("http://www.google.com/icon");
1486 1515
1487 std::vector<unsigned char> data_initial; 1516 std::vector<unsigned char> data_initial;
1488 data_initial.push_back('a'); 1517 data_initial.push_back('a');
1489 1518
(...skipping 10 matching lines...) Expand all
1500 1529
1501 chrome::FaviconID original_favicon_id = 1530 chrome::FaviconID original_favicon_id =
1502 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1531 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1503 icon_url, chrome::FAVICON, NULL); 1532 icon_url, chrome::FAVICON, NULL);
1504 EXPECT_NE(0, original_favicon_id); 1533 EXPECT_NE(0, original_favicon_id);
1505 FaviconBitmap original_favicon_bitmap; 1534 FaviconBitmap original_favicon_bitmap;
1506 EXPECT_TRUE( 1535 EXPECT_TRUE(
1507 GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap)); 1536 GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap));
1508 EXPECT_TRUE(BitmapDataEqual('a', original_favicon_bitmap.bitmap_data)); 1537 EXPECT_TRUE(BitmapDataEqual('a', original_favicon_bitmap.bitmap_data));
1509 1538
1510 EXPECT_EQ(1, num_broadcasted_notifications()); 1539 EXPECT_EQ(1, num_favicon_notifications());
1511 1540
1512 // Call SetFavicons() with completely identical data. 1541 // Call SetFavicons() with completely identical data.
1513 std::vector<unsigned char> updated_data; 1542 std::vector<unsigned char> updated_data;
1514 updated_data.push_back('a'); 1543 updated_data.push_back('a');
1515 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data); 1544 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data);
1516 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data); 1545 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
1517 1546
1518 chrome::FaviconID updated_favicon_id = 1547 chrome::FaviconID updated_favicon_id =
1519 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1548 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1520 icon_url, chrome::FAVICON, NULL); 1549 icon_url, chrome::FAVICON, NULL);
1521 EXPECT_NE(0, updated_favicon_id); 1550 EXPECT_NE(0, updated_favicon_id);
1522 FaviconBitmap updated_favicon_bitmap; 1551 FaviconBitmap updated_favicon_bitmap;
1523 EXPECT_TRUE( 1552 EXPECT_TRUE(
1524 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); 1553 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap));
1525 EXPECT_TRUE(BitmapDataEqual('a', updated_favicon_bitmap.bitmap_data)); 1554 EXPECT_TRUE(BitmapDataEqual('a', updated_favicon_bitmap.bitmap_data));
1526 1555
1527 // Because the bitmap data is byte equivalent, no notifications should have 1556 // Because the bitmap data is byte equivalent, no notifications should have
1528 // been broadcasted. 1557 // been broadcasted.
1529 EXPECT_EQ(1, num_broadcasted_notifications()); 1558 EXPECT_EQ(1, num_favicon_notifications());
1530 1559
1531 // Call SetFavicons() with identical data but a different bitmap. 1560 // Call SetFavicons() with identical data but a different bitmap.
1532 updated_data[0] = 'b'; 1561 updated_data[0] = 'b';
1533 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data); 1562 favicon_bitmap_data[0].bitmap_data = new base::RefCountedBytes(updated_data);
1534 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data); 1563 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
1535 1564
1536 updated_favicon_id = 1565 updated_favicon_id =
1537 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1566 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1538 icon_url, chrome::FAVICON, NULL); 1567 icon_url, chrome::FAVICON, NULL);
1539 EXPECT_NE(0, updated_favicon_id); 1568 EXPECT_NE(0, updated_favicon_id);
1540 EXPECT_TRUE( 1569 EXPECT_TRUE(
1541 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap)); 1570 GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap));
1542 EXPECT_TRUE(BitmapDataEqual('b', updated_favicon_bitmap.bitmap_data)); 1571 EXPECT_TRUE(BitmapDataEqual('b', updated_favicon_bitmap.bitmap_data));
1543 1572
1544 // There should be no churn in FaviconIDs or FaviconBitmapIds even though 1573 // There should be no churn in FaviconIDs or FaviconBitmapIds even though
1545 // the bitmap data changed. 1574 // the bitmap data changed.
1546 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id); 1575 EXPECT_EQ(original_favicon_bitmap.icon_id, updated_favicon_bitmap.icon_id);
1547 EXPECT_EQ(original_favicon_bitmap.bitmap_id, 1576 EXPECT_EQ(original_favicon_bitmap.bitmap_id,
1548 updated_favicon_bitmap.bitmap_id); 1577 updated_favicon_bitmap.bitmap_id);
1549 1578
1550 // A notification should have been broadcasted as the favicon bitmap data has 1579 // A notification should have been broadcasted as the favicon bitmap data has
1551 // changed. 1580 // changed.
1552 EXPECT_EQ(2, num_broadcasted_notifications()); 1581 EXPECT_EQ(2, num_favicon_notifications());
1553 } 1582 }
1554 1583
1555 // Test that if two pages share the same FaviconID, changing the favicon for 1584 // Test that if two pages share the same FaviconID, changing the favicon for
1556 // one page does not affect the other. 1585 // one page does not affect the other.
1557 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) { 1586 TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) {
1558 GURL icon_url("http://www.google.com/favicon.ico"); 1587 GURL icon_url("http://www.google.com/favicon.ico");
1559 GURL icon_url_new("http://www.google.com/favicon2.ico"); 1588 GURL icon_url_new("http://www.google.com/favicon2.ico");
1560 GURL page_url1("http://www.google.com"); 1589 GURL page_url1("http://www.google.com");
1561 GURL page_url2("http://www.google.ca"); 1590 GURL page_url2("http://www.google.ca");
1562 1591
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 EXPECT_EQ(1u, icon_mappings.size()); 1643 EXPECT_EQ(1u, icon_mappings.size());
1615 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 1644 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
1616 1645
1617 favicon_bitmaps.clear(); 1646 favicon_bitmaps.clear();
1618 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id, 1647 EXPECT_TRUE(backend_->thumbnail_db_->GetFaviconBitmaps(favicon_id,
1619 &favicon_bitmaps)); 1648 &favicon_bitmaps));
1620 EXPECT_EQ(2u, favicon_bitmaps.size()); 1649 EXPECT_EQ(2u, favicon_bitmaps.size());
1621 1650
1622 // A notification should have been broadcast for each call to SetFavicons() 1651 // A notification should have been broadcast for each call to SetFavicons()
1623 // and each call to UpdateFaviconMappingsAndFetch(). 1652 // and each call to UpdateFaviconMappingsAndFetch().
1624 EXPECT_EQ(3, num_broadcasted_notifications()); 1653 EXPECT_EQ(3, num_favicon_notifications());
1625 } 1654 }
1626 1655
1627 // Test that no notifications are broadcast as a result of calling 1656 // Test that no notifications are broadcast as a result of calling
1628 // UpdateFaviconMappingsAndFetch() for an icon URL which is already 1657 // UpdateFaviconMappingsAndFetch() for an icon URL which is already
1629 // mapped to the passed in page URL. 1658 // mapped to the passed in page URL.
1630 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) { 1659 TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchNoChange) {
1631 GURL page_url("http://www.google.com"); 1660 GURL page_url("http://www.google.com");
1632 GURL icon_url("http://www.google.com/favicon.ico"); 1661 GURL icon_url("http://www.google.com/favicon.ico");
1633 std::vector<chrome::FaviconBitmapData> favicon_bitmap_data; 1662 std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
1634 GenerateFaviconBitmapData(icon_url, GetSizesSmall(), &favicon_bitmap_data); 1663 GenerateFaviconBitmapData(icon_url, GetSizesSmall(), &favicon_bitmap_data);
1635 1664
1636 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data); 1665 backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
1637 1666
1638 chrome::FaviconID icon_id = 1667 chrome::FaviconID icon_id =
1639 backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1668 backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1640 icon_url, chrome::FAVICON, NULL); 1669 icon_url, chrome::FAVICON, NULL);
1641 EXPECT_NE(0, icon_id); 1670 EXPECT_NE(0, icon_id);
1642 EXPECT_EQ(1, num_broadcasted_notifications()); 1671 EXPECT_EQ(1, num_favicon_notifications());
1643 1672
1644 std::vector<GURL> icon_urls; 1673 std::vector<GURL> icon_urls;
1645 icon_urls.push_back(icon_url); 1674 icon_urls.push_back(icon_url);
1646 1675
1647 std::vector<chrome::FaviconBitmapResult> bitmap_results; 1676 std::vector<chrome::FaviconBitmapResult> bitmap_results;
1648 backend_->UpdateFaviconMappingsAndFetch( 1677 backend_->UpdateFaviconMappingsAndFetch(
1649 page_url, icon_urls, chrome::FAVICON, kSmallSize.width(), 1678 page_url, icon_urls, chrome::FAVICON, kSmallSize.width(),
1650 GetScaleFactors1x2x(), &bitmap_results); 1679 GetScaleFactors1x2x(), &bitmap_results);
1651 1680
1652 EXPECT_EQ(icon_id, backend_->thumbnail_db_->GetFaviconIDForFaviconURL( 1681 EXPECT_EQ(icon_id, backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
1653 icon_url, chrome::FAVICON, NULL)); 1682 icon_url, chrome::FAVICON, NULL));
1654 1683
1655 // No notification should have been broadcast as no icon mapping, favicon, 1684 // No notification should have been broadcast as no icon mapping, favicon,
1656 // or favicon bitmap was updated, added or removed. 1685 // or favicon bitmap was updated, added or removed.
1657 EXPECT_EQ(1, num_broadcasted_notifications()); 1686 EXPECT_EQ(1, num_favicon_notifications());
1658 } 1687 }
1659 1688
1660 // Test repeatedly calling MergeFavicon(). |page_url| is initially not known 1689 // Test repeatedly calling MergeFavicon(). |page_url| is initially not known
1661 // to the database. 1690 // to the database.
1662 TEST_F(HistoryBackendTest, MergeFaviconPageURLNotInDB) { 1691 TEST_F(HistoryBackendTest, MergeFaviconPageURLNotInDB) {
1663 GURL page_url("http://www.google.com"); 1692 GURL page_url("http://www.google.com");
1664 GURL icon_url("http:/www.google.com/favicon.ico"); 1693 GURL icon_url("http:/www.google.com/favicon.ico");
1665 1694
1666 std::vector<unsigned char> data; 1695 std::vector<unsigned char> data;
1667 data.push_back('a'); 1696 data.push_back('a');
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 &icon_mappings)); 1751 &icon_mappings));
1723 EXPECT_EQ(1u, icon_mappings.size()); 1752 EXPECT_EQ(1u, icon_mappings.size());
1724 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 1753 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
1725 1754
1726 FaviconBitmap favicon_bitmap; 1755 FaviconBitmap favicon_bitmap;
1727 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 1756 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1728 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 1757 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
1729 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); 1758 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data));
1730 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 1759 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1731 1760
1732 EXPECT_EQ(1, num_broadcasted_notifications()); 1761 EXPECT_EQ(1, num_favicon_notifications());
1733 1762
1734 // 1) Merge identical favicon bitmap. 1763 // 1) Merge identical favicon bitmap.
1735 std::vector<unsigned char> data; 1764 std::vector<unsigned char> data;
1736 data.push_back('a'); 1765 data.push_back('a');
1737 scoped_refptr<base::RefCountedBytes> bitmap_data( 1766 scoped_refptr<base::RefCountedBytes> bitmap_data(
1738 new base::RefCountedBytes(data)); 1767 new base::RefCountedBytes(data));
1739 backend_->MergeFavicon( 1768 backend_->MergeFavicon(
1740 page_url, icon_url1, chrome::FAVICON, bitmap_data, kSmallSize); 1769 page_url, icon_url1, chrome::FAVICON, bitmap_data, kSmallSize);
1741 1770
1742 // All the data should stay the same and no notifications should have been 1771 // All the data should stay the same and no notifications should have been
1743 // sent. 1772 // sent.
1744 icon_mappings.clear(); 1773 icon_mappings.clear();
1745 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1774 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
1746 &icon_mappings)); 1775 &icon_mappings));
1747 EXPECT_EQ(1u, icon_mappings.size()); 1776 EXPECT_EQ(1u, icon_mappings.size());
1748 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url); 1777 EXPECT_EQ(icon_url1, icon_mappings[0].icon_url);
1749 1778
1750 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap)); 1779 EXPECT_TRUE(GetOnlyFaviconBitmap(icon_mappings[0].icon_id, &favicon_bitmap));
1751 EXPECT_NE(base::Time(), favicon_bitmap.last_updated); 1780 EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
1752 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data)); 1781 EXPECT_TRUE(BitmapDataEqual('a', favicon_bitmap.bitmap_data));
1753 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size); 1782 EXPECT_EQ(kSmallSize, favicon_bitmap.pixel_size);
1754 1783
1755 EXPECT_EQ(1, num_broadcasted_notifications()); 1784 EXPECT_EQ(1, num_favicon_notifications());
1756 1785
1757 // 2) Merge favicon bitmap of the same size. 1786 // 2) Merge favicon bitmap of the same size.
1758 data[0] = 'b'; 1787 data[0] = 'b';
1759 bitmap_data = new base::RefCountedBytes(data); 1788 bitmap_data = new base::RefCountedBytes(data);
1760 backend_->MergeFavicon( 1789 backend_->MergeFavicon(
1761 page_url, icon_url1, chrome::FAVICON, bitmap_data, kSmallSize); 1790 page_url, icon_url1, chrome::FAVICON, bitmap_data, kSmallSize);
1762 1791
1763 // The small favicon bitmap at |icon_url1| should be overwritten. 1792 // The small favicon bitmap at |icon_url1| should be overwritten.
1764 icon_mappings.clear(); 1793 icon_mappings.clear();
1765 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, 1794 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data)); 1848 EXPECT_TRUE(BitmapDataEqual('c', favicon_bitmaps[0].bitmap_data));
1820 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size); 1849 EXPECT_EQ(kTinySize, favicon_bitmaps[0].pixel_size);
1821 // The favicon being merged should take precedence over the preexisting 1850 // The favicon being merged should take precedence over the preexisting
1822 // favicon bitmaps. 1851 // favicon bitmaps.
1823 EXPECT_NE(base::Time(), favicon_bitmaps[1].last_updated); 1852 EXPECT_NE(base::Time(), favicon_bitmaps[1].last_updated);
1824 EXPECT_TRUE(BitmapDataEqual('d', favicon_bitmaps[1].bitmap_data)); 1853 EXPECT_TRUE(BitmapDataEqual('d', favicon_bitmaps[1].bitmap_data));
1825 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size); 1854 EXPECT_EQ(kSmallSize, favicon_bitmaps[1].pixel_size);
1826 1855
1827 // A notification should have been broadcast for each call to SetFavicons() 1856 // A notification should have been broadcast for each call to SetFavicons()
1828 // and MergeFavicon(). 1857 // and MergeFavicon().
1829 EXPECT_EQ(4, num_broadcasted_notifications()); 1858 EXPECT_EQ(4, num_favicon_notifications());
1830 } 1859 }
1831 1860
1832 // Test calling MergeFavicon() when |icon_url| is known to the database but not 1861 // Test calling MergeFavicon() when |icon_url| is known to the database but not
1833 // mapped to |page_url|. 1862 // mapped to |page_url|.
1834 TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) { 1863 TEST_F(HistoryBackendTest, MergeFaviconIconURLMappedToDifferentPageURL) {
1835 GURL page_url1("http://www.google.com"); 1864 GURL page_url1("http://www.google.com");
1836 GURL page_url2("http://news.google.com"); 1865 GURL page_url2("http://news.google.com");
1837 GURL page_url3("http://maps.google.com"); 1866 GURL page_url3("http://maps.google.com");
1838 GURL icon_url("http:/www.google.com/favicon.ico"); 1867 GURL icon_url("http:/www.google.com/favicon.ico");
1839 1868
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 1933 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
1905 1934
1906 icon_mappings.clear(); 1935 icon_mappings.clear();
1907 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url3, 1936 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url3,
1908 &icon_mappings)); 1937 &icon_mappings));
1909 EXPECT_EQ(1u, icon_mappings.size()); 1938 EXPECT_EQ(1u, icon_mappings.size());
1910 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id); 1939 EXPECT_EQ(favicon_id, icon_mappings[0].icon_id);
1911 1940
1912 // A notification should have been broadcast for each call to SetFavicons() 1941 // A notification should have been broadcast for each call to SetFavicons()
1913 // and MergeFavicon(). 1942 // and MergeFavicon().
1914 EXPECT_EQ(3, num_broadcasted_notifications()); 1943 EXPECT_EQ(3, num_favicon_notifications());
1915 } 1944 }
1916 1945
1917 // Test that MergeFavicon() does not add more than 1946 // Test that MergeFavicon() does not add more than
1918 // |kMaxFaviconBitmapsPerIconURL| to a favicon. 1947 // |kMaxFaviconBitmapsPerIconURL| to a favicon.
1919 TEST_F(HistoryBackendTest, MergeFaviconMaxFaviconBitmapsPerIconURL) { 1948 TEST_F(HistoryBackendTest, MergeFaviconMaxFaviconBitmapsPerIconURL) {
1920 GURL page_url("http://www.google.com"); 1949 GURL page_url("http://www.google.com");
1921 std::string icon_url_string("http://www.google.com/favicon.ico"); 1950 std::string icon_url_string("http://www.google.com/favicon.ico");
1922 size_t replace_index = icon_url_string.size() - 1; 1951 size_t replace_index = icon_url_string.size() - 1;
1923 1952
1924 std::vector<unsigned char> data; 1953 std::vector<unsigned char> data;
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
2774 ASSERT_EQ(2u, data.size()); 2803 ASSERT_EQ(2u, data.size());
2775 EXPECT_EQ(url2.spec(), data[0]->GetURL().spec()); 2804 EXPECT_EQ(url2.spec(), data[0]->GetURL().spec());
2776 EXPECT_EQ(url2_id, data[0]->GetID()); 2805 EXPECT_EQ(url2_id, data[0]->GetID());
2777 EXPECT_EQ(segment2_time_delta.InHours(), data[0]->duration().InHours()); 2806 EXPECT_EQ(segment2_time_delta.InHours(), data[0]->duration().InHours());
2778 2807
2779 EXPECT_EQ(url1.spec(), data[1]->GetURL().spec()); 2808 EXPECT_EQ(url1.spec(), data[1]->GetURL().spec());
2780 EXPECT_EQ(url1_id, data[1]->GetID()); 2809 EXPECT_EQ(url1_id, data[1]->GetID());
2781 EXPECT_EQ(segment1_time_delta.InHours(), data[1]->duration().InHours()); 2810 EXPECT_EQ(segment1_time_delta.InHours(), data[1]->duration().InHours());
2782 } 2811 }
2783 2812
2813 // Simple test that removes a bookmark. This test exercises the code paths in
2814 // History that block till bookmark bar model is loaded.
2815 TEST_F(HistoryBackendTest, RemoveNotification) {
2816 scoped_ptr<TestingProfile> profile(new TestingProfile());
2817 profile->CreateHistoryService(false, false);
2818 profile->CreateBookmarkModel(true);
2819
2820 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile.get());
2821 ui_test_utils::WaitForBookmarkModelToLoad(model);
2822
2823 // Add a URL.
2824 GURL url("http://www.google.com");
2825 bookmark_utils::AddIfNotBookmarked(model, url, string16());
2826
2827 HistoryService* service = HistoryServiceFactory::GetForProfile(
2828 profile.get(), Profile::EXPLICIT_ACCESS);
2829 service->AddPage(url,
2830 base::Time::Now(),
2831 NULL,
2832 1,
2833 GURL(),
2834 RedirectList(),
2835 content::PAGE_TRANSITION_TYPED,
2836 SOURCE_BROWSED,
2837 false);
2838
2839 // This won't actually delete the URL, rather it'll empty out the visits.
2840 // This triggers blocking on the BookmarkModel.
2841 service->DeleteURL(url);
2842 }
2843
2784 } // namespace history 2844 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698