OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 EXPECT_TRUE(top_sites().SetPageThumbnail(url2, thumbnail, high_score)); | 408 EXPECT_TRUE(top_sites().SetPageThumbnail(url2, thumbnail, high_score)); |
409 | 409 |
410 // Set on the redirect source should succeed. It should be replacable by | 410 // Set on the redirect source should succeed. It should be replacable by |
411 // the same score on the redirect destination, which in turn should not | 411 // the same score on the redirect destination, which in turn should not |
412 // be replaced by the source again. | 412 // be replaced by the source again. |
413 EXPECT_TRUE(top_sites().SetPageThumbnail(url1a, thumbnail, medium_score)); | 413 EXPECT_TRUE(top_sites().SetPageThumbnail(url1a, thumbnail, medium_score)); |
414 EXPECT_TRUE(top_sites().SetPageThumbnail(url1b, thumbnail, medium_score)); | 414 EXPECT_TRUE(top_sites().SetPageThumbnail(url1b, thumbnail, medium_score)); |
415 EXPECT_FALSE(top_sites().SetPageThumbnail(url1a, thumbnail, medium_score)); | 415 EXPECT_FALSE(top_sites().SetPageThumbnail(url1a, thumbnail, medium_score)); |
416 } | 416 } |
417 | 417 |
| 418 TEST_F(TopSitesTest, GetPageThumbnail) { |
| 419 ChromeThread db_loop(ChromeThread::DB, MessageLoop::current()); |
| 420 MostVisitedURLList url_list; |
| 421 MostVisitedURL url1 = {GURL("http://asdf.com")}; |
| 422 url1.redirects.push_back(url1.url); |
| 423 url_list.push_back(url1); |
| 424 |
| 425 MostVisitedURL url2 = {GURL("http://gmail.com")}; |
| 426 url2.redirects.push_back(url2.url); |
| 427 url2.redirects.push_back(GURL("http://mail.google.com")); |
| 428 url_list.push_back(url2); |
| 429 |
| 430 top_sites().UpdateMostVisited(url_list); |
| 431 MessageLoop::current()->RunAllPending(); |
| 432 |
| 433 // Create a dummy thumbnail. |
| 434 SkBitmap thumbnail; |
| 435 thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 4, 4); |
| 436 thumbnail.allocPixels(); |
| 437 thumbnail.eraseRGB(0x00, 0x00, 0x00); |
| 438 ThumbnailScore score(0.5, true, true, base::Time::Now()); |
| 439 |
| 440 RefCountedBytes* result = NULL; |
| 441 EXPECT_TRUE(top_sites().SetPageThumbnail(url1.url, thumbnail, score)); |
| 442 EXPECT_TRUE(top_sites().GetPageThumbnail(url1.url, &result)); |
| 443 |
| 444 EXPECT_TRUE(top_sites().SetPageThumbnail(GURL("http://gmail.com"), |
| 445 thumbnail, score)); |
| 446 EXPECT_TRUE(top_sites().GetPageThumbnail(GURL("http://gmail.com"), |
| 447 &result)); |
| 448 // Get a thumbnail via a redirect. |
| 449 EXPECT_TRUE(top_sites().GetPageThumbnail(GURL("http://mail.google.com"), |
| 450 &result)); |
| 451 |
| 452 EXPECT_TRUE(top_sites().SetPageThumbnail(GURL("http://mail.google.com"), |
| 453 thumbnail, score)); |
| 454 EXPECT_TRUE(top_sites().GetPageThumbnail(url2.url, &result)); |
| 455 |
| 456 scoped_ptr<SkBitmap> out_bitmap(gfx::JPEGCodec::Decode(result->front(), |
| 457 result->size())); |
| 458 EXPECT_EQ(0, memcmp(thumbnail.getPixels(), out_bitmap->getPixels(), |
| 459 thumbnail.getSize())); |
| 460 } |
| 461 |
418 TEST_F(TopSitesTest, GetMostVisited) { | 462 TEST_F(TopSitesTest, GetMostVisited) { |
419 ChromeThread db_loop(ChromeThread::DB, MessageLoop::current()); | 463 ChromeThread db_loop(ChromeThread::DB, MessageLoop::current()); |
420 GURL news("http://news.google.com/"); | 464 GURL news("http://news.google.com/"); |
421 GURL google("http://google.com/"); | 465 GURL google("http://google.com/"); |
422 | 466 |
423 MockHistoryServiceImpl hs; | 467 MockHistoryServiceImpl hs; |
424 hs.AppendMockPage(news, ASCIIToUTF16("Google News")); | 468 hs.AppendMockPage(news, ASCIIToUTF16("Google News")); |
425 hs.AppendMockPage(google, ASCIIToUTF16("Google")); | 469 hs.AppendMockPage(google, ASCIIToUTF16("Google")); |
426 top_sites().SetMockHistoryService(&hs); | 470 top_sites().SetMockHistoryService(&hs); |
427 | 471 |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 | 1326 |
1283 top_sites().AddPrepopulatedPages(&pages); | 1327 top_sites().AddPrepopulatedPages(&pages); |
1284 | 1328 |
1285 // Themes URL is already in pages; should not be added twice. | 1329 // Themes URL is already in pages; should not be added twice. |
1286 ASSERT_EQ(2u, pages.size()); | 1330 ASSERT_EQ(2u, pages.size()); |
1287 EXPECT_EQ(themes_url(), pages[0].url); | 1331 EXPECT_EQ(themes_url(), pages[0].url); |
1288 EXPECT_EQ(welcome_url(), pages[1].url); | 1332 EXPECT_EQ(welcome_url(), pages[1].url); |
1289 } | 1333 } |
1290 | 1334 |
1291 } // namespace history | 1335 } // namespace history |
OLD | NEW |