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 "chrome/browser/history/history_backend.h" | 5 #include "chrome/browser/history/history_backend.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 const gfx::Size kTinySize = gfx::Size(kTinyEdgeSize, kTinyEdgeSize); | 59 const gfx::Size kTinySize = gfx::Size(kTinyEdgeSize, kTinyEdgeSize); |
60 const gfx::Size kSmallSize = gfx::Size(kSmallEdgeSize, kSmallEdgeSize); | 60 const gfx::Size kSmallSize = gfx::Size(kSmallEdgeSize, kSmallEdgeSize); |
61 const gfx::Size kLargeSize = gfx::Size(kLargeEdgeSize, kLargeEdgeSize); | 61 const gfx::Size kLargeSize = gfx::Size(kLargeEdgeSize, kLargeEdgeSize); |
62 | 62 |
63 typedef base::Callback<void(const history::URLRow*, | 63 typedef base::Callback<void(const history::URLRow*, |
64 const history::URLRow*, | 64 const history::URLRow*, |
65 const history::URLRow*)> | 65 const history::URLRow*)> |
66 SimulateNotificationCallback; | 66 SimulateNotificationCallback; |
67 | 67 |
68 // Comparison functions as to make it easier to check results of | |
69 // GetFaviconBitmaps() and GetIconMappingsForPageURL(). | |
70 bool IconMappingLessThan(const history::IconMapping& a, | |
71 const history::IconMapping& b) { | |
72 return a.icon_url < b.icon_url; | |
73 } | |
74 | |
75 bool FaviconBitmapLessThan(const history::FaviconBitmap& a, | |
76 const history::FaviconBitmap& b) { | |
77 return a.pixel_size.GetArea() < b.pixel_size.GetArea(); | |
78 } | |
79 | |
80 class HistoryClientMock : public history::HistoryClientFakeBookmarks { | 68 class HistoryClientMock : public history::HistoryClientFakeBookmarks { |
81 public: | 69 public: |
82 MOCK_METHOD0(BlockUntilBookmarksLoaded, void()); | 70 MOCK_METHOD0(BlockUntilBookmarksLoaded, void()); |
83 }; | 71 }; |
84 | 72 |
85 void SimulateNotificationURLVisited(history::HistoryServiceObserver* observer, | 73 void SimulateNotificationURLVisited(history::HistoryServiceObserver* observer, |
86 const history::URLRow* row1, | 74 const history::URLRow* row1, |
87 const history::URLRow* row2, | 75 const history::URLRow* row2, |
88 const history::URLRow* row3) { | 76 const history::URLRow* row3) { |
89 history::URLRows rows; | 77 history::URLRows rows; |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 // URL in ascending order. Returns true if there is at least one icon | 349 // URL in ascending order. Returns true if there is at least one icon |
362 // mapping. | 350 // mapping. |
363 bool GetSortedIconMappingsForPageURL( | 351 bool GetSortedIconMappingsForPageURL( |
364 const GURL& page_url, | 352 const GURL& page_url, |
365 std::vector<IconMapping>* icon_mappings) { | 353 std::vector<IconMapping>* icon_mappings) { |
366 if (!backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, | 354 if (!backend_->thumbnail_db_->GetIconMappingsForPageURL(page_url, |
367 icon_mappings)) { | 355 icon_mappings)) { |
368 return false; | 356 return false; |
369 } | 357 } |
370 std::sort(icon_mappings->begin(), icon_mappings->end(), | 358 std::sort(icon_mappings->begin(), icon_mappings->end(), |
371 IconMappingLessThan); | 359 [](const history::IconMapping& a, const history::IconMapping& b) { |
| 360 return a.icon_url < b.icon_url; |
| 361 }); |
372 return true; | 362 return true; |
373 } | 363 } |
374 | 364 |
375 // Returns the favicon bitmaps for |icon_id| sorted by pixel size in | 365 // Returns the favicon bitmaps for |icon_id| sorted by pixel size in |
376 // ascending order. Returns true if there is at least one favicon bitmap. | 366 // ascending order. Returns true if there is at least one favicon bitmap. |
377 bool GetSortedFaviconBitmaps(favicon_base::FaviconID icon_id, | 367 bool GetSortedFaviconBitmaps(favicon_base::FaviconID icon_id, |
378 std::vector<FaviconBitmap>* favicon_bitmaps) { | 368 std::vector<FaviconBitmap>* favicon_bitmaps) { |
379 if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, favicon_bitmaps)) | 369 if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, favicon_bitmaps)) |
380 return false; | 370 return false; |
381 std::sort(favicon_bitmaps->begin(), favicon_bitmaps->end(), | 371 std::sort( |
382 FaviconBitmapLessThan); | 372 favicon_bitmaps->begin(), favicon_bitmaps->end(), |
| 373 [](const history::FaviconBitmap& a, const history::FaviconBitmap& b) { |
| 374 return a.pixel_size.GetArea() < b.pixel_size.GetArea(); |
| 375 }); |
383 return true; | 376 return true; |
384 } | 377 } |
385 | 378 |
386 // Returns true if there is exactly one favicon bitmap associated to | 379 // Returns true if there is exactly one favicon bitmap associated to |
387 // |favicon_id|. If true, returns favicon bitmap in output parameter. | 380 // |favicon_id|. If true, returns favicon bitmap in output parameter. |
388 bool GetOnlyFaviconBitmap(const favicon_base::FaviconID icon_id, | 381 bool GetOnlyFaviconBitmap(const favicon_base::FaviconID icon_id, |
389 FaviconBitmap* favicon_bitmap) { | 382 FaviconBitmap* favicon_bitmap) { |
390 std::vector<FaviconBitmap> favicon_bitmaps; | 383 std::vector<FaviconBitmap> favicon_bitmaps; |
391 if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, &favicon_bitmaps)) | 384 if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, &favicon_bitmaps)) |
392 return false; | 385 return false; |
(...skipping 2867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3260 // Verify that the second term is no longer returned as result, and also check | 3253 // Verify that the second term is no longer returned as result, and also check |
3261 // at the low level that it is gone for good. The term corresponding to the | 3254 // at the low level that it is gone for good. The term corresponding to the |
3262 // first URLRow should not be affected. | 3255 // first URLRow should not be affected. |
3263 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); | 3256 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); |
3264 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); | 3257 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); |
3265 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); | 3258 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); |
3266 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); | 3259 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); |
3267 } | 3260 } |
3268 | 3261 |
3269 } // namespace history | 3262 } // namespace history |
OLD | NEW |