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

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

Issue 8469018: Provide assumed favicon for intents if service provider page was never visited. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed review issues. Fixed merge issues due to MaybeShowIntentInfoBar Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <vector> 6 #include <vector>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 EXPECT_TRUE(db.HasMappingFor(id2)); 426 EXPECT_TRUE(db.HasMappingFor(id2));
427 EXPECT_FALSE(db.HasMappingFor(id3)); 427 EXPECT_FALSE(db.HasMappingFor(id3));
428 428
429 // Remove all mappings 429 // Remove all mappings
430 db.DeleteIconMappings(page_url); 430 db.DeleteIconMappings(page_url);
431 EXPECT_FALSE(db.HasMappingFor(id1)); 431 EXPECT_FALSE(db.HasMappingFor(id1));
432 EXPECT_FALSE(db.HasMappingFor(id2)); 432 EXPECT_FALSE(db.HasMappingFor(id2));
433 EXPECT_FALSE(db.HasMappingFor(id3)); 433 EXPECT_FALSE(db.HasMappingFor(id3));
434 } 434 }
435 435
436 TEST_F(ThumbnailDatabaseTest, CloneIconMapping) {
437 ThumbnailDatabase db;
438 ASSERT_EQ(sql::INIT_OK, db.Init(file_name_, NULL, NULL));
439 db.BeginTransaction();
440
441 std::vector<unsigned char> data(blob1, blob1 + sizeof(blob1));
442 scoped_refptr<RefCountedBytes> favicon(new RefCountedBytes(data));
443
444 // Add a favicon which will have icon_mappings
445 FaviconID id1 = db.AddFavicon(GURL("http://google.com"), FAVICON);
446 EXPECT_NE(id1, 0);
447 base::Time time = base::Time::Now();
448 db.SetFavicon(id1, favicon, time);
449
450 // Add another type of favicon
451 FaviconID id2 = db.AddFavicon(GURL("http://www.google.com/icon"), TOUCH_ICON);
452 EXPECT_NE(id2, 0);
453 time = base::Time::Now();
454 db.SetFavicon(id2, favicon, time);
455
456 // Add 3rd favicon
457 FaviconID id3 = db.AddFavicon(GURL("http://www.google.com/icon"), TOUCH_ICON);
458 EXPECT_NE(id3, 0);
459 time = base::Time::Now();
460 db.SetFavicon(id3, favicon, time);
461
462 GURL page1_url("http://page1.com");
463 EXPECT_TRUE(db.AddIconMapping(page1_url, id1));
464 EXPECT_TRUE(db.AddIconMapping(page1_url, id2));
465
466 GURL page2_url("http://page2.com");
467 EXPECT_TRUE(db.AddIconMapping(page2_url, id3));
468
469 // Test we do nothing with existing mappings.
470 std::vector<IconMapping> icon_mapping;
471 EXPECT_TRUE(db.GetIconMappingsForPageURL(page2_url, &icon_mapping));
472 ASSERT_EQ(1U, icon_mapping.size());
473
474 EXPECT_TRUE(db.CloneIconMapping(page1_url, page2_url));
475
476 icon_mapping.clear();
477 EXPECT_TRUE(db.GetIconMappingsForPageURL(page2_url, &icon_mapping));
478 ASSERT_EQ(1U, icon_mapping.size());
479 EXPECT_EQ(page2_url, icon_mapping[0].page_url);
480 EXPECT_EQ(id3, icon_mapping[0].icon_id);
481
482 // Test we clone if the new page has no mappings.
483 GURL page3_url("http://page3.com");
484 EXPECT_TRUE(db.CloneIconMapping(page1_url, page3_url));
485
486 icon_mapping.clear();
487 EXPECT_TRUE(db.GetIconMappingsForPageURL(page3_url, &icon_mapping));
488
489 ASSERT_EQ(2U, icon_mapping.size());
490 if (icon_mapping[0].icon_id == id2)
491 std::swap(icon_mapping[0], icon_mapping[1]);
492 EXPECT_EQ(page3_url, icon_mapping[0].page_url);
493 EXPECT_EQ(id1, icon_mapping[0].icon_id);
494 EXPECT_EQ(page3_url, icon_mapping[1].page_url);
495 EXPECT_EQ(id2, icon_mapping[1].icon_id);
496 }
497
436 TEST_F(IconMappingMigrationTest, TestIconMappingMigration) { 498 TEST_F(IconMappingMigrationTest, TestIconMappingMigration) {
437 HistoryDatabase history_db; 499 HistoryDatabase history_db;
438 ASSERT_TRUE(history_db.db_.Open(history_db_name_)); 500 ASSERT_TRUE(history_db.db_.Open(history_db_name_));
439 history_db.BeginTransaction(); 501 history_db.BeginTransaction();
440 502
441 const GURL icon1 = GURL("http://www.google.com/favicon.ico"); 503 const GURL icon1 = GURL("http://www.google.com/favicon.ico");
442 const GURL icon2 = GURL("http://www.yahoo.com/favicon.ico"); 504 const GURL icon2 = GURL("http://www.yahoo.com/favicon.ico");
443 505
444 ThumbnailDatabase db; 506 ThumbnailDatabase db;
445 ASSERT_EQ(sql::INIT_OK, db.Init(thumbnail_db_name_, NULL, &history_db)); 507 ASSERT_EQ(sql::INIT_OK, db.Init(thumbnail_db_name_, NULL, &history_db));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 ASSERT_TRUE(db.GetFavicon( 543 ASSERT_TRUE(db.GetFavicon(
482 icon_mappings[0].icon_id, &time, &out_data, &out_icon_url)); 544 icon_mappings[0].icon_id, &time, &out_data, &out_icon_url));
483 EXPECT_EQ(icon2, out_icon_url); 545 EXPECT_EQ(icon2, out_icon_url);
484 546
485 // Test a page without icon 547 // Test a page without icon
486 GURL page_url4 = GURL("http://www.google.com/blank.html"); 548 GURL page_url4 = GURL("http://www.google.com/blank.html");
487 EXPECT_FALSE(db.GetIconMappingsForPageURL(page_url4, NULL)); 549 EXPECT_FALSE(db.GetIconMappingsForPageURL(page_url4, NULL));
488 } 550 }
489 551
490 } // namespace history 552 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698