| 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 | 5 |
| 6 #include "webkit/dom_storage/session_storage_database.h" | 6 #include "webkit/dom_storage/session_storage_database.h" |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 void ReadData(DataMap* data) const; | 45 void ReadData(DataMap* data) const; |
| 46 void CheckDatabaseConsistency() const; | 46 void CheckDatabaseConsistency() const; |
| 47 void CheckEmptyDatabase() const; | 47 void CheckEmptyDatabase() const; |
| 48 void DumpData() const; | 48 void DumpData() const; |
| 49 void CheckAreaData(const std::string& namespace_id, | 49 void CheckAreaData(const std::string& namespace_id, |
| 50 const GURL& origin, | 50 const GURL& origin, |
| 51 const ValuesMap& reference) const; | 51 const ValuesMap& reference) const; |
| 52 void CompareValuesMaps(const ValuesMap& map1, const ValuesMap& map2) const; | 52 void CompareValuesMaps(const ValuesMap& map1, const ValuesMap& map2) const; |
| 53 void CheckNamespaceIds( | 53 void CheckNamespaceIds( |
| 54 const std::set<std::string>& expected_namespace_ids) const; | 54 const std::set<std::string>& expected_namespace_ids) const; |
| 55 void CheckOrigins( |
| 56 const std::string& namespace_id, |
| 57 const std::set<GURL>& expected_origins) const; |
| 55 std::string GetMapForArea(const std::string& namespace_id, | 58 std::string GetMapForArea(const std::string& namespace_id, |
| 56 const GURL& origin) const; | 59 const GURL& origin) const; |
| 57 int64 GetMapRefCount(const std::string& map_id) const; | 60 int64 GetMapRefCount(const std::string& map_id) const; |
| 58 | 61 |
| 59 ScopedTempDir temp_dir_; | 62 ScopedTempDir temp_dir_; |
| 60 scoped_refptr<SessionStorageDatabase> db_; | 63 scoped_refptr<SessionStorageDatabase> db_; |
| 61 | 64 |
| 62 // Test data. | 65 // Test data. |
| 63 const GURL kOrigin1; | 66 const GURL kOrigin1; |
| 64 const GURL kOrigin2; | 67 const GURL kOrigin2; |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 } | 331 } |
| 329 } | 332 } |
| 330 | 333 |
| 331 void SessionStorageDatabaseTest::CheckNamespaceIds( | 334 void SessionStorageDatabaseTest::CheckNamespaceIds( |
| 332 const std::set<std::string>& expected_namespace_ids) const { | 335 const std::set<std::string>& expected_namespace_ids) const { |
| 333 std::vector<std::string> namespace_ids; | 336 std::vector<std::string> namespace_ids; |
| 334 EXPECT_TRUE(db_->ReadNamespaceIds(&namespace_ids)); | 337 EXPECT_TRUE(db_->ReadNamespaceIds(&namespace_ids)); |
| 335 EXPECT_EQ(expected_namespace_ids.size(), namespace_ids.size()); | 338 EXPECT_EQ(expected_namespace_ids.size(), namespace_ids.size()); |
| 336 for (std::vector<std::string>::const_iterator it = namespace_ids.begin(); | 339 for (std::vector<std::string>::const_iterator it = namespace_ids.begin(); |
| 337 it != namespace_ids.end(); ++it) { | 340 it != namespace_ids.end(); ++it) { |
| 338 LOG(WARNING) << *it; | |
| 339 EXPECT_TRUE(expected_namespace_ids.find(*it) != | 341 EXPECT_TRUE(expected_namespace_ids.find(*it) != |
| 340 expected_namespace_ids.end()); | 342 expected_namespace_ids.end()); |
| 341 } | 343 } |
| 342 } | 344 } |
| 343 | 345 |
| 346 void SessionStorageDatabaseTest::CheckOrigins( |
| 347 const std::string& namespace_id, |
| 348 const std::set<GURL>& expected_origins) const { |
| 349 std::vector<GURL> origins; |
| 350 EXPECT_TRUE(db_->ReadOriginsInNamespace(namespace_id, &origins)); |
| 351 EXPECT_EQ(expected_origins.size(), origins.size()); |
| 352 for (std::vector<GURL>::const_iterator it = origins.begin(); |
| 353 it != origins.end(); ++it) { |
| 354 EXPECT_TRUE(expected_origins.find(*it) != expected_origins.end()); |
| 355 } |
| 356 } |
| 357 |
| 344 std::string SessionStorageDatabaseTest::GetMapForArea( | 358 std::string SessionStorageDatabaseTest::GetMapForArea( |
| 345 const std::string& namespace_id, const GURL& origin) const { | 359 const std::string& namespace_id, const GURL& origin) const { |
| 346 bool exists; | 360 bool exists; |
| 347 std::string map_id; | 361 std::string map_id; |
| 348 EXPECT_TRUE(db_->GetMapForArea(namespace_id, origin.spec(), | 362 EXPECT_TRUE(db_->GetMapForArea(namespace_id, origin.spec(), |
| 349 &exists, &map_id)); | 363 &exists, &map_id)); |
| 350 EXPECT_TRUE(exists); | 364 EXPECT_TRUE(exists); |
| 351 return map_id; | 365 return map_id; |
| 352 } | 366 } |
| 353 | 367 |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 expected_namespace_ids.insert(kNamespaceClone); | 731 expected_namespace_ids.insert(kNamespaceClone); |
| 718 CheckNamespaceIds(expected_namespace_ids); | 732 CheckNamespaceIds(expected_namespace_ids); |
| 719 | 733 |
| 720 ASSERT_TRUE(db_->DeleteNamespace(kNamespace1)); | 734 ASSERT_TRUE(db_->DeleteNamespace(kNamespace1)); |
| 721 expected_namespace_ids.erase(kNamespace1); | 735 expected_namespace_ids.erase(kNamespace1); |
| 722 CheckNamespaceIds(expected_namespace_ids); | 736 CheckNamespaceIds(expected_namespace_ids); |
| 723 | 737 |
| 724 CheckDatabaseConsistency(); | 738 CheckDatabaseConsistency(); |
| 725 } | 739 } |
| 726 | 740 |
| 741 TEST_F(SessionStorageDatabaseTest, ReadOriginsInNamespace) { |
| 742 ValuesMap data1; |
| 743 data1[kKey1] = kValue1; |
| 744 data1[kKey2] = kValue2; |
| 745 data1[kKey3] = kValue3; |
| 746 |
| 747 std::set<GURL> expected_origins1; |
| 748 ASSERT_TRUE(db_->CommitAreaChanges(kNamespace1, kOrigin1, false, data1)); |
| 749 ASSERT_TRUE(db_->CommitAreaChanges(kNamespace1, kOrigin2, false, data1)); |
| 750 expected_origins1.insert(kOrigin1); |
| 751 expected_origins1.insert(kOrigin2); |
| 752 CheckOrigins(kNamespace1, expected_origins1); |
| 753 |
| 754 std::set<GURL> expected_origins2; |
| 755 ASSERT_TRUE(db_->CommitAreaChanges(kNamespace2, kOrigin2, false, data1)); |
| 756 expected_origins2.insert(kOrigin2); |
| 757 CheckOrigins(kNamespace2, expected_origins2); |
| 758 |
| 759 ASSERT_TRUE(db_->CloneNamespace(kNamespace1, kNamespaceClone)); |
| 760 CheckOrigins(kNamespaceClone, expected_origins1); |
| 761 |
| 762 ASSERT_TRUE(db_->DeleteArea(kNamespace1, kOrigin2)); |
| 763 expected_origins1.erase(kOrigin2); |
| 764 CheckOrigins(kNamespace1, expected_origins1); |
| 765 |
| 766 CheckDatabaseConsistency(); |
| 767 } |
| 768 |
| 727 } // namespace dom_storage | 769 } // namespace dom_storage |
| OLD | NEW |