diff options
Diffstat (limited to 'chrome')
6 files changed, 102 insertions, 3 deletions
diff --git a/chrome/browser/browsing_data_appcache_helper.cc b/chrome/browser/browsing_data_appcache_helper.cc index 54b08ac..3ce7106 100644 --- a/chrome/browser/browsing_data_appcache_helper.cc +++ b/chrome/browser/browsing_data_appcache_helper.cc @@ -108,7 +108,17 @@ CannedBrowsingDataAppCacheHelper::CannedBrowsingDataAppCacheHelper( void CannedBrowsingDataAppCacheHelper::AddAppCache(const GURL& manifest_url) { typedef std::map<GURL, appcache::AppCacheInfoVector> InfoByOrigin; InfoByOrigin& origin_map = info_collection_->infos_by_origin; - origin_map[manifest_url.GetOrigin()].push_back( + appcache::AppCacheInfoVector& appcache_infos_ = + origin_map[manifest_url.GetOrigin()]; + + for (appcache::AppCacheInfoVector::iterator + appcache = appcache_infos_.begin(); appcache != appcache_infos_.end(); + ++appcache) { + if (appcache->manifest_url == manifest_url) + return; + } + + appcache_infos_.push_back( appcache::AppCacheInfo(manifest_url, 0, base::Time(), diff --git a/chrome/browser/browsing_data_appcache_helper_unittest.cc b/chrome/browser/browsing_data_appcache_helper_unittest.cc index fe30c7c..e5631b1 100644 --- a/chrome/browser/browsing_data_appcache_helper_unittest.cc +++ b/chrome/browser/browsing_data_appcache_helper_unittest.cc @@ -59,3 +59,26 @@ TEST(CannedBrowsingDataAppCacheHelperTest, SetInfo) { EXPECT_TRUE(ContainsKey(manifest_results, manifest2)); EXPECT_TRUE(ContainsKey(manifest_results, manifest3)); } + +TEST(CannedBrowsingDataAppCacheHelperTest, Unique) { + TestingProfile profile; + + GURL manifest("http://example.com/manifest.xml"); + + scoped_refptr<CannedBrowsingDataAppCacheHelper> helper = + new CannedBrowsingDataAppCacheHelper(&profile); + helper->AddAppCache(manifest); + helper->AddAppCache(manifest); + + TestCompletionCallback callback; + helper->StartFetching(&callback); + ASSERT_TRUE(callback.have_result()); + + std::map<GURL, appcache::AppCacheInfoVector>& collection = + helper->info_collection()->infos_by_origin; + + ASSERT_EQ(1u, collection.size()); + EXPECT_TRUE(ContainsKey(collection, manifest.GetOrigin())); + ASSERT_EQ(1u, collection[manifest.GetOrigin()].size()); + EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url); +} diff --git a/chrome/browser/browsing_data_database_helper.cc b/chrome/browser/browsing_data_database_helper.cc index 0530225..09db4c8 100644 --- a/chrome/browser/browsing_data_database_helper.cc +++ b/chrome/browser/browsing_data_database_helper.cc @@ -122,10 +122,20 @@ void CannedBrowsingDataDatabaseHelper::AddDatabase( WebKit::WebSecurityOrigin web_security_origin = WebKit::WebSecurityOrigin::createFromString( UTF8ToUTF16(origin.spec())); + std::string origin_identifier = + web_security_origin.databaseIdentifier().utf8(); + + for (std::vector<DatabaseInfo>::iterator database = database_info_.begin(); + database != database_info_.end(); ++database) { + if (database->origin_identifier == origin_identifier && + database->database_name == name) + return; + } + database_info_.push_back(DatabaseInfo( web_security_origin.host().utf8(), name, - web_security_origin.databaseIdentifier().utf8(), + origin_identifier, description, 0, base::Time())); diff --git a/chrome/browser/browsing_data_database_helper_unittest.cc b/chrome/browser/browsing_data_database_helper_unittest.cc index 5b6a8d5..b5368c4 100644 --- a/chrome/browser/browsing_data_database_helper_unittest.cc +++ b/chrome/browser/browsing_data_database_helper_unittest.cc @@ -69,3 +69,27 @@ TEST(CannedBrowsingDataDatabaseTest, AddDatabase) { EXPECT_STREQ(origin_str2, result[2].origin_identifier.c_str()); EXPECT_STREQ(db3, result[2].database_name.c_str()); } + +TEST(CannedBrowsingDataDatabaseTest, Unique) { + TestingProfile profile; + + const GURL origin("http://host1:1/"); + const char origin_str[] = "http_host1_1"; + const char db[] = "db1"; + + scoped_refptr<CannedBrowsingDataDatabaseHelper> helper = + new CannedBrowsingDataDatabaseHelper(&profile); + helper->AddDatabase(origin, db, ""); + helper->AddDatabase(origin, db, ""); + + TestCompletionCallback callback; + helper->StartFetching(&callback); + ASSERT_TRUE(callback.have_result()); + + std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result = + callback.result(); + + ASSERT_EQ(1u, result.size()); + EXPECT_STREQ(origin_str, result[0].origin_identifier.c_str()); + EXPECT_STREQ(db, result[0].database_name.c_str()); +} diff --git a/chrome/browser/browsing_data_local_storage_helper.cc b/chrome/browser/browsing_data_local_storage_helper.cc index 47a4b61..2193305 100644 --- a/chrome/browser/browsing_data_local_storage_helper.cc +++ b/chrome/browser/browsing_data_local_storage_helper.cc @@ -127,12 +127,21 @@ void CannedBrowsingDataLocalStorageHelper::AddLocalStorage( WebKit::WebSecurityOrigin web_security_origin = WebKit::WebSecurityOrigin::createFromString( UTF8ToUTF16(origin.spec())); + std::string security_origin(web_security_origin.toString().utf8()); + + for (std::vector<LocalStorageInfo>::iterator + local_storage = local_storage_info_.begin(); + local_storage != local_storage_info_.end(); ++local_storage) { + if (local_storage->origin == security_origin) + return; + } + local_storage_info_.push_back(LocalStorageInfo( web_security_origin.protocol().utf8(), web_security_origin.host().utf8(), web_security_origin.port(), web_security_origin.databaseIdentifier().utf8(), - web_security_origin.toString().utf8(), + security_origin, profile_->GetWebKitContext()->dom_storage_context()-> GetLocalStorageFilePath(web_security_origin.databaseIdentifier()), 0, diff --git a/chrome/browser/browsing_data_local_storage_helper_unittest.cc b/chrome/browser/browsing_data_local_storage_helper_unittest.cc index 959cf5a..37c3555 100644 --- a/chrome/browser/browsing_data_local_storage_helper_unittest.cc +++ b/chrome/browser/browsing_data_local_storage_helper_unittest.cc @@ -64,3 +64,26 @@ TEST(CannedBrowsingDataLocalStorageTest, AddLocalStorage) { EXPECT_EQ(FilePath(file1).value(), result[0].file_path.BaseName().value()); EXPECT_EQ(FilePath(file2).value(), result[1].file_path.BaseName().value()); } + +TEST(CannedBrowsingDataLocalStorageTest, Unique) { + TestingProfile profile; + + const GURL origin("http://host1:1/"); + const FilePath::CharType file[] = + FILE_PATH_LITERAL("http_host1_1.localstorage"); + + scoped_refptr<CannedBrowsingDataLocalStorageHelper> helper = + new CannedBrowsingDataLocalStorageHelper(&profile); + helper->AddLocalStorage(origin); + helper->AddLocalStorage(origin); + + TestCompletionCallback callback; + helper->StartFetching(&callback); + ASSERT_TRUE(callback.have_result()); + + std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> result = + callback.result(); + + ASSERT_EQ(1u, result.size()); + EXPECT_EQ(FilePath(file).value(), result[0].file_path.BaseName().value()); +} |