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

Side by Side Diff: webkit/dom_storage/session_storage_database_unittest.cc

Issue 9963107: Persist sessionStorage on disk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review (pkasting) Created 8 years, 4 months 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
« no previous file with comments | « webkit/dom_storage/session_storage_database.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 leveldb::ReadOptions(), &exists, &map_id));
350 EXPECT_TRUE(exists); 364 EXPECT_TRUE(exists);
351 return map_id; 365 return map_id;
352 } 366 }
353 367
354 int64 SessionStorageDatabaseTest::GetMapRefCount( 368 int64 SessionStorageDatabaseTest::GetMapRefCount(
355 const std::string& map_id) const { 369 const std::string& map_id) const {
356 int64 ref_count; 370 int64 ref_count;
357 EXPECT_TRUE(db_->GetMapRefCount(map_id, &ref_count)); 371 EXPECT_TRUE(db_->GetMapRefCount(map_id, &ref_count));
358 return ref_count; 372 return ref_count;
359 } 373 }
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, ReadNamespaceIdsInEmptyDatabase) {
742 std::set<std::string> expected_namespace_ids;
743 CheckNamespaceIds(expected_namespace_ids);
744 }
745
746 TEST_F(SessionStorageDatabaseTest, ReadOriginsInNamespace) {
747 ValuesMap data1;
748 data1[kKey1] = kValue1;
749 data1[kKey2] = kValue2;
750 data1[kKey3] = kValue3;
751
752 std::set<GURL> expected_origins1;
753 ASSERT_TRUE(db_->CommitAreaChanges(kNamespace1, kOrigin1, false, data1));
754 ASSERT_TRUE(db_->CommitAreaChanges(kNamespace1, kOrigin2, false, data1));
755 expected_origins1.insert(kOrigin1);
756 expected_origins1.insert(kOrigin2);
757 CheckOrigins(kNamespace1, expected_origins1);
758
759 std::set<GURL> expected_origins2;
760 ASSERT_TRUE(db_->CommitAreaChanges(kNamespace2, kOrigin2, false, data1));
761 expected_origins2.insert(kOrigin2);
762 CheckOrigins(kNamespace2, expected_origins2);
763
764 ASSERT_TRUE(db_->CloneNamespace(kNamespace1, kNamespaceClone));
765 CheckOrigins(kNamespaceClone, expected_origins1);
766
767 ASSERT_TRUE(db_->DeleteArea(kNamespace1, kOrigin2));
768 expected_origins1.erase(kOrigin2);
769 CheckOrigins(kNamespace1, expected_origins1);
770
771 CheckDatabaseConsistency();
772 }
773
727 } // namespace dom_storage 774 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/dom_storage/session_storage_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698