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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/task/cancelable_task_tracker.h" | 9 #include "base/task/cancelable_task_tracker.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/history/history_db_task.h" | 11 #include "chrome/browser/history/history_db_task.h" |
12 #include "chrome/browser/history/history_notifications.h" | 12 #include "chrome/browser/history/history_notifications.h" |
13 #include "chrome/browser/history/history_service_factory.h" | 13 #include "chrome/browser/history/history_service_factory.h" |
14 #include "chrome/browser/history/history_unittest_base.h" | 14 #include "chrome/browser/history/history_unittest_base.h" |
15 #include "chrome/browser/history/top_sites.h" | |
16 #include "chrome/browser/history/top_sites_cache.h" | 15 #include "chrome/browser/history/top_sites_cache.h" |
17 #include "chrome/browser/history/top_sites_impl.h" | 16 #include "chrome/browser/history/top_sites_provider.h" |
| 17 #include "chrome/browser/history/top_sites_service.h" |
18 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
21 #include "components/history/core/browser/history_types.h" | 21 #include "components/history/core/browser/history_types.h" |
22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
23 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
26 #include "ui/gfx/codec/jpeg_codec.h" | 26 #include "ui/gfx/codec/jpeg_codec.h" |
27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
28 | 28 |
29 using content::BrowserThread; | 29 using content::BrowserThread; |
30 | 30 |
31 class TestTopSitesObserver : public history::TopSitesObserver { | 31 class TestTopSitesObserver : public history::TopSitesObserver { |
32 public: | 32 public: |
33 explicit TestTopSitesObserver(Profile* profile, history::TopSites* top_sites); | 33 explicit TestTopSitesObserver(Profile* profile, |
| 34 history::TopSitesProvider* top_sites); |
34 virtual ~TestTopSitesObserver(); | 35 virtual ~TestTopSitesObserver(); |
35 // TopSitesObserver: | 36 // TopSitesObserver: |
36 void TopSitesLoaded(history::TopSites* top_sites) override; | 37 void TopSitesLoaded(history::TopSitesProvider* top_sites) override; |
37 void TopSitesChanged(history::TopSites* top_sites) override; | 38 void TopSitesChanged(history::TopSitesProvider* top_sites) override; |
38 | 39 |
39 private: | 40 private: |
40 Profile* profile_; | 41 Profile* profile_; |
41 history::TopSites* top_sites_; | 42 history::TopSitesProvider* top_sites_; |
42 }; | 43 }; |
43 | 44 |
44 TestTopSitesObserver::~TestTopSitesObserver() { | 45 TestTopSitesObserver::~TestTopSitesObserver() { |
45 top_sites_->RemoveObserver(this); | 46 top_sites_->RemoveObserver(this); |
46 } | 47 } |
47 | 48 |
48 TestTopSitesObserver::TestTopSitesObserver(Profile* profile, | 49 TestTopSitesObserver::TestTopSitesObserver(Profile* profile, |
49 history::TopSites* top_sites) | 50 history::TopSitesProvider* top_sites) |
50 : profile_(profile), top_sites_(top_sites) { | 51 : profile_(profile), top_sites_(top_sites) { |
51 DCHECK(top_sites_); | 52 DCHECK(top_sites_); |
52 top_sites_->AddObserver(this); | 53 top_sites_->AddObserver(this); |
53 } | 54 } |
54 | 55 |
55 void TestTopSitesObserver::TopSitesLoaded(history::TopSites* top_sites) { | 56 void TestTopSitesObserver::TopSitesLoaded( |
| 57 history::TopSitesProvider* top_sites) { |
56 content::NotificationService::current()->Notify( | 58 content::NotificationService::current()->Notify( |
57 chrome::NOTIFICATION_TOP_SITES_LOADED, | 59 chrome::NOTIFICATION_TOP_SITES_LOADED, content::Source<Profile>(profile_), |
58 content::Source<Profile>(profile_), | 60 content::Details<history::TopSitesProvider>(top_sites)); |
59 content::Details<history::TopSites>(top_sites)); | |
60 } | 61 } |
61 | 62 |
62 void TestTopSitesObserver::TopSitesChanged(history::TopSites* top_sites) { | 63 void TestTopSitesObserver::TopSitesChanged( |
| 64 history::TopSitesProvider* top_sites) { |
63 content::NotificationService::current()->Notify( | 65 content::NotificationService::current()->Notify( |
64 chrome::NOTIFICATION_TOP_SITES_CHANGED, | 66 chrome::NOTIFICATION_TOP_SITES_CHANGED, |
65 content::Source<Profile>(profile_), | 67 content::Source<Profile>(profile_), |
66 content::NotificationService::NoDetails()); | 68 content::NotificationService::NoDetails()); |
67 } | 69 } |
68 | 70 |
69 namespace history { | 71 namespace history { |
70 | 72 |
71 namespace { | 73 namespace { |
72 | 74 |
(...skipping 19 matching lines...) Expand all Loading... |
92 // TopSites is queried before it finishes loading. | 94 // TopSites is queried before it finishes loading. |
93 class TopSitesQuerier { | 95 class TopSitesQuerier { |
94 public: | 96 public: |
95 TopSitesQuerier() | 97 TopSitesQuerier() |
96 : number_of_callbacks_(0), | 98 : number_of_callbacks_(0), |
97 waiting_(false), | 99 waiting_(false), |
98 weak_ptr_factory_(this) {} | 100 weak_ptr_factory_(this) {} |
99 | 101 |
100 // Queries top sites. If |wait| is true a nested message loop is run until the | 102 // Queries top sites. If |wait| is true a nested message loop is run until the |
101 // callback is notified. | 103 // callback is notified. |
102 void QueryTopSites(TopSitesImpl* top_sites, bool wait) { | 104 void QueryTopSites(TopSitesService* top_sites, bool wait) { |
103 QueryAllTopSites(top_sites, wait, false); | 105 QueryAllTopSites(top_sites, wait, false); |
104 } | 106 } |
105 | 107 |
106 // Queries top sites, including potentially forced URLs if | 108 // Queries top sites, including potentially forced URLs if |
107 // |include_forced_urls| is true. | 109 // |include_forced_urls| is true. |
108 void QueryAllTopSites(TopSitesImpl* top_sites, | 110 void QueryAllTopSites(TopSitesService* top_sites, |
109 bool wait, | 111 bool wait, |
110 bool include_forced_urls) { | 112 bool include_forced_urls) { |
111 int start_number_of_callbacks = number_of_callbacks_; | 113 int start_number_of_callbacks = number_of_callbacks_; |
112 top_sites->GetMostVisitedURLs( | 114 top_sites->GetMostVisitedURLs( |
113 base::Bind(&TopSitesQuerier::OnTopSitesAvailable, | 115 base::Bind(&TopSitesQuerier::OnTopSitesAvailable, |
114 weak_ptr_factory_.GetWeakPtr()), | 116 weak_ptr_factory_.GetWeakPtr()), |
115 include_forced_urls); | 117 include_forced_urls); |
116 if (wait && start_number_of_callbacks == number_of_callbacks_) { | 118 if (wait && start_number_of_callbacks == number_of_callbacks_) { |
117 waiting_ = true; | 119 waiting_ = true; |
118 base::MessageLoop::current()->Run(); | 120 base::MessageLoop::current()->Run(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 230 |
229 // Waits for top sites to finish processing a task. This is useful if you need | 231 // Waits for top sites to finish processing a task. This is useful if you need |
230 // to wait until top sites finishes processing a task. | 232 // to wait until top sites finishes processing a task. |
231 void WaitForTopSites() { | 233 void WaitForTopSites() { |
232 top_sites()->backend_->DoEmptyRequest( | 234 top_sites()->backend_->DoEmptyRequest( |
233 base::Bind(&TopSitesImplTest::QuitCallback, base::Unretained(this)), | 235 base::Bind(&TopSitesImplTest::QuitCallback, base::Unretained(this)), |
234 &top_sites_tracker_); | 236 &top_sites_tracker_); |
235 base::MessageLoop::current()->Run(); | 237 base::MessageLoop::current()->Run(); |
236 } | 238 } |
237 | 239 |
238 TopSitesImpl* top_sites() { | 240 TopSitesService* top_sites() { |
239 return static_cast<TopSitesImpl*>(profile_->GetTopSites()); | 241 return static_cast<TopSitesService*>(profile_->GetTopSites()); |
240 } | 242 } |
241 TestingProfile* profile() {return profile_.get();} | 243 TestingProfile* profile() {return profile_.get();} |
242 HistoryService* history_service() { | 244 HistoryService* history_service() { |
243 return HistoryServiceFactory::GetForProfile(profile_.get(), | 245 return HistoryServiceFactory::GetForProfile(profile_.get(), |
244 Profile::EXPLICIT_ACCESS); | 246 Profile::EXPLICIT_ACCESS); |
245 } | 247 } |
246 | 248 |
247 MostVisitedURLList GetPrepopulatePages() { | 249 MostVisitedURLList GetPrepopulatePages() { |
248 return top_sites()->GetPrepopulatePages(); | 250 return top_sites()->GetPrepopulatePages(); |
249 } | 251 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 308 |
307 // Delets a url. | 309 // Delets a url. |
308 void DeleteURL(const GURL& url) { | 310 void DeleteURL(const GURL& url) { |
309 history_service()->DeleteURL(url); | 311 history_service()->DeleteURL(url); |
310 } | 312 } |
311 | 313 |
312 // Returns true if the thumbnail equals the specified bytes. | 314 // Returns true if the thumbnail equals the specified bytes. |
313 bool ThumbnailEqualsBytes(const gfx::Image& image, | 315 bool ThumbnailEqualsBytes(const gfx::Image& image, |
314 base::RefCountedMemory* bytes) { | 316 base::RefCountedMemory* bytes) { |
315 scoped_refptr<base::RefCountedBytes> encoded_image; | 317 scoped_refptr<base::RefCountedBytes> encoded_image; |
316 TopSitesImpl::EncodeBitmap(image, &encoded_image); | 318 TopSitesService::EncodeBitmap(image, &encoded_image); |
317 return ThumbnailsAreEqual(encoded_image.get(), bytes); | 319 return ThumbnailsAreEqual(encoded_image.get(), bytes); |
318 } | 320 } |
319 | 321 |
320 // Recreates top sites. This forces top sites to reread from the db. | 322 // Recreates top sites. This forces top sites to reread from the db. |
321 void RecreateTopSitesAndBlock() { | 323 void RecreateTopSitesAndBlock() { |
322 // Recreate TopSites and wait for it to load. | 324 // Recreate TopSites and wait for it to load. |
323 CreateTopSitesAndObserver(); | 325 CreateTopSitesAndObserver(); |
324 // As history already loaded we have to fake this call. | 326 // As history already loaded we have to fake this call. |
325 profile()->BlockUntilTopSitesLoaded(); | 327 profile()->BlockUntilTopSitesLoaded(); |
326 } | 328 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 AppendMostVisitedURL(&old_list, gets_deleted_1); // 1 (deleted) | 469 AppendMostVisitedURL(&old_list, gets_deleted_1); // 1 (deleted) |
468 AppendMostVisitedURL(&old_list, gets_moved_1); // 2 (moved to 3) | 470 AppendMostVisitedURL(&old_list, gets_moved_1); // 2 (moved to 3) |
469 | 471 |
470 std::vector<MostVisitedURL> new_list; | 472 std::vector<MostVisitedURL> new_list; |
471 AppendMostVisitedURL(&new_list, stays_the_same); // 0 (unchanged) | 473 AppendMostVisitedURL(&new_list, stays_the_same); // 0 (unchanged) |
472 AppendMostVisitedURL(&new_list, gets_added_1); // 1 (added) | 474 AppendMostVisitedURL(&new_list, gets_added_1); // 1 (added) |
473 AppendMostVisitedURL(&new_list, gets_added_2); // 2 (added) | 475 AppendMostVisitedURL(&new_list, gets_added_2); // 2 (added) |
474 AppendMostVisitedURL(&new_list, gets_moved_1); // 3 (moved from 2) | 476 AppendMostVisitedURL(&new_list, gets_moved_1); // 3 (moved from 2) |
475 | 477 |
476 history::TopSitesDelta delta; | 478 history::TopSitesDelta delta; |
477 history::TopSitesImpl::DiffMostVisited(old_list, new_list, &delta); | 479 history::TopSitesService::DiffMostVisited(old_list, new_list, &delta); |
478 | 480 |
479 ASSERT_EQ(2u, delta.added.size()); | 481 ASSERT_EQ(2u, delta.added.size()); |
480 EXPECT_TRUE(gets_added_1 == delta.added[0].url.url); | 482 EXPECT_TRUE(gets_added_1 == delta.added[0].url.url); |
481 EXPECT_EQ(1, delta.added[0].rank); | 483 EXPECT_EQ(1, delta.added[0].rank); |
482 EXPECT_TRUE(gets_added_2 == delta.added[1].url.url); | 484 EXPECT_TRUE(gets_added_2 == delta.added[1].url.url); |
483 EXPECT_EQ(2, delta.added[1].rank); | 485 EXPECT_EQ(2, delta.added[1].rank); |
484 | 486 |
485 ASSERT_EQ(1u, delta.deleted.size()); | 487 ASSERT_EQ(1u, delta.deleted.size()); |
486 EXPECT_TRUE(gets_deleted_1 == delta.deleted[0].url); | 488 EXPECT_TRUE(gets_deleted_1 == delta.deleted[0].url); |
487 | 489 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 AppendForcedMostVisitedURL(&new_list, stays_the_same_2, 3000); | 524 AppendForcedMostVisitedURL(&new_list, stays_the_same_2, 3000); |
523 AppendForcedMostVisitedURL(&new_list, new_last_forced_time, 4000); | 525 AppendForcedMostVisitedURL(&new_list, new_last_forced_time, 4000); |
524 AppendForcedMostVisitedURL(&new_list, gets_added_1, 5000); | 526 AppendForcedMostVisitedURL(&new_list, gets_added_1, 5000); |
525 AppendForcedMostVisitedURL(&new_list, move_to_forced, 6000); | 527 AppendForcedMostVisitedURL(&new_list, move_to_forced, 6000); |
526 AppendMostVisitedURL(&new_list, move_to_nonforced); | 528 AppendMostVisitedURL(&new_list, move_to_nonforced); |
527 AppendMostVisitedURL(&new_list, stays_the_same_3); | 529 AppendMostVisitedURL(&new_list, stays_the_same_3); |
528 AppendMostVisitedURL(&new_list, gets_added_2); | 530 AppendMostVisitedURL(&new_list, gets_added_2); |
529 AppendMostVisitedURL(&new_list, gets_moved_1); | 531 AppendMostVisitedURL(&new_list, gets_moved_1); |
530 | 532 |
531 history::TopSitesDelta delta; | 533 history::TopSitesDelta delta; |
532 history::TopSitesImpl::DiffMostVisited(old_list, new_list, &delta); | 534 history::TopSitesService::DiffMostVisited(old_list, new_list, &delta); |
533 | 535 |
534 ASSERT_EQ(2u, delta.added.size()); | 536 ASSERT_EQ(2u, delta.added.size()); |
535 EXPECT_TRUE(gets_added_1 == delta.added[0].url.url); | 537 EXPECT_TRUE(gets_added_1 == delta.added[0].url.url); |
536 EXPECT_EQ(-1, delta.added[0].rank); | 538 EXPECT_EQ(-1, delta.added[0].rank); |
537 EXPECT_TRUE(gets_added_2 == delta.added[1].url.url); | 539 EXPECT_TRUE(gets_added_2 == delta.added[1].url.url); |
538 EXPECT_EQ(2, delta.added[1].rank); | 540 EXPECT_EQ(2, delta.added[1].rank); |
539 | 541 |
540 ASSERT_EQ(2u, delta.deleted.size()); | 542 ASSERT_EQ(2u, delta.deleted.size()); |
541 EXPECT_TRUE(gets_deleted_1 == delta.deleted[0].url); | 543 EXPECT_TRUE(gets_deleted_1 == delta.deleted[0].url); |
542 EXPECT_TRUE(gets_deleted_2 == delta.deleted[1].url); | 544 EXPECT_TRUE(gets_deleted_2 == delta.deleted[1].url); |
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 ASSERT_EQ(orig_thumbnail.getSize(), thumbnail.getSize()); | 1684 ASSERT_EQ(orig_thumbnail.getSize(), thumbnail.getSize()); |
1683 orig_thumbnail.lockPixels(); | 1685 orig_thumbnail.lockPixels(); |
1684 thumbnail.lockPixels(); | 1686 thumbnail.lockPixels(); |
1685 EXPECT_EQ(0, memcmp(orig_thumbnail.getPixels(), thumbnail.getPixels(), | 1687 EXPECT_EQ(0, memcmp(orig_thumbnail.getPixels(), thumbnail.getPixels(), |
1686 orig_thumbnail.getSize())); | 1688 orig_thumbnail.getSize())); |
1687 thumbnail.unlockPixels(); | 1689 thumbnail.unlockPixels(); |
1688 orig_thumbnail.unlockPixels(); | 1690 orig_thumbnail.unlockPixels(); |
1689 } | 1691 } |
1690 | 1692 |
1691 } // namespace history | 1693 } // namespace history |
OLD | NEW |