| 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 #include "webkit/dom_storage/session_storage_database.h" | 5 #include "webkit/dom_storage/session_storage_database.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 CheckAreaData(1, kOrigin2, data2); | 472 CheckAreaData(1, kOrigin2, data2); |
| 473 CheckAreaData(5, kOrigin1, data1); | 473 CheckAreaData(5, kOrigin1, data1); |
| 474 CheckAreaData(5, kOrigin2, data2); | 474 CheckAreaData(5, kOrigin2, data2); |
| 475 // Both the namespaces refer to the same maps. | 475 // Both the namespaces refer to the same maps. |
| 476 EXPECT_EQ(GetMapForArea(1, kOrigin1), GetMapForArea(5, kOrigin1)); | 476 EXPECT_EQ(GetMapForArea(1, kOrigin1), GetMapForArea(5, kOrigin1)); |
| 477 EXPECT_EQ(GetMapForArea(1, kOrigin2), GetMapForArea(5, kOrigin2)); | 477 EXPECT_EQ(GetMapForArea(1, kOrigin2), GetMapForArea(5, kOrigin2)); |
| 478 EXPECT_EQ(2, GetMapRefCount(GetMapForArea(1, kOrigin1))); | 478 EXPECT_EQ(2, GetMapRefCount(GetMapForArea(1, kOrigin1))); |
| 479 EXPECT_EQ(2, GetMapRefCount(GetMapForArea(1, kOrigin2))); | 479 EXPECT_EQ(2, GetMapRefCount(GetMapForArea(1, kOrigin2))); |
| 480 } | 480 } |
| 481 | 481 |
| 482 TEST_F(SessionStorageDatabaseTest, DeepCopy) { | 482 TEST_F(SessionStorageDatabaseTest, WriteIntoShallowCopy) { |
| 483 ValuesMap data1; | 483 ValuesMap data1; |
| 484 data1[kKey1] = kValue1; | 484 data1[kKey1] = kValue1; |
| 485 data1[kKey2] = kValue2; | 485 data1[kKey2] = kValue2; |
| 486 ASSERT_TRUE(db_->CommitAreaChanges(1, kOrigin1, false, data1)); | 486 ASSERT_TRUE(db_->CommitAreaChanges(1, kOrigin1, false, data1)); |
| 487 EXPECT_TRUE(db_->CloneNamespace(1, 5)); | 487 EXPECT_TRUE(db_->CloneNamespace(1, 5)); |
| 488 | 488 |
| 489 // Make the shallow copy deep. | 489 // Write data into a shallow copy. |
| 490 EXPECT_TRUE(db_->DeepCopyArea(5, kOrigin1)); | |
| 491 | |
| 492 // Write data into the deep copy. | |
| 493 ValuesMap changes; | 490 ValuesMap changes; |
| 494 ValuesMap reference; | 491 ValuesMap reference; |
| 495 changes[kKey1] = kValueNull; | 492 changes[kKey1] = kValueNull; |
| 496 changes[kKey2] = kValue4; | 493 changes[kKey2] = kValue4; |
| 497 changes[kKey3] = kValue4; | 494 changes[kKey3] = kValue4; |
| 498 reference[kKey2] = kValue4; | 495 reference[kKey2] = kValue4; |
| 499 reference[kKey3] = kValue4; | 496 reference[kKey3] = kValue4; |
| 500 EXPECT_TRUE(db_->CommitAreaChanges(5, kOrigin1, false, changes)); | 497 EXPECT_TRUE(db_->CommitAreaChanges(5, kOrigin1, false, changes)); |
| 501 | 498 |
| 502 // Values in the original namespace were not changed. | 499 // Values in the original namespace were not changed. |
| 503 CheckAreaData(1, kOrigin1, data1); | 500 CheckAreaData(1, kOrigin1, data1); |
| 504 // But values in the deep copy were. | 501 // But values in the copy were. |
| 505 CheckAreaData(5, kOrigin1, reference); | 502 CheckAreaData(5, kOrigin1, reference); |
| 506 | 503 |
| 507 // The namespaces no longer refer to the same map. | 504 // The namespaces no longer refer to the same map. |
| 508 EXPECT_NE(GetMapForArea(1, kOrigin1), GetMapForArea(5, kOrigin1)); | 505 EXPECT_NE(GetMapForArea(1, kOrigin1), GetMapForArea(5, kOrigin1)); |
| 509 EXPECT_EQ(1, GetMapRefCount(GetMapForArea(1, kOrigin1))); | 506 EXPECT_EQ(1, GetMapRefCount(GetMapForArea(1, kOrigin1))); |
| 510 EXPECT_EQ(1, GetMapRefCount(GetMapForArea(5, kOrigin1))); | 507 EXPECT_EQ(1, GetMapRefCount(GetMapForArea(5, kOrigin1))); |
| 511 } | 508 } |
| 512 | 509 |
| 513 TEST_F(SessionStorageDatabaseTest, ManyShallowCopies) { | 510 TEST_F(SessionStorageDatabaseTest, ManyShallowCopies) { |
| 514 // Write data for a namespace, for 2 origins. | 511 // Write data for a namespace, for 2 origins. |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 | 755 |
| 759 // Close the database and recreate it. | 756 // Close the database and recreate it. |
| 760 ResetDatabase(); | 757 ResetDatabase(); |
| 761 | 758 |
| 762 // The namespace and the clone are still accessible. | 759 // The namespace and the clone are still accessible. |
| 763 CheckAreaData(-1, kOrigin1, data2); | 760 CheckAreaData(-1, kOrigin1, data2); |
| 764 CheckAreaData(-20, kOrigin1, data2); | 761 CheckAreaData(-20, kOrigin1, data2); |
| 765 CheckAreaData(-22, kOrigin1, data1); | 762 CheckAreaData(-22, kOrigin1, data1); |
| 766 } | 763 } |
| 767 | 764 |
| 768 TEST_F(SessionStorageDatabaseTest, NamespaceOffsetDeepCopyArea) { | 765 TEST_F(SessionStorageDatabaseTest, NamespaceOffsetWriteIntoShallowCopy) { |
| 769 // Create a namespace with id 1. | 766 // Create a namespace with id 1. |
| 770 ValuesMap data1; | 767 ValuesMap data1; |
| 771 data1[kKey1] = kValue1; | 768 data1[kKey1] = kValue1; |
| 772 data1[kKey2] = kValue2; | 769 data1[kKey2] = kValue2; |
| 773 ASSERT_TRUE(db_->CommitAreaChanges(1, kOrigin1, false, data1)); | 770 ASSERT_TRUE(db_->CommitAreaChanges(1, kOrigin1, false, data1)); |
| 774 | 771 |
| 775 // Close the database and recreate it. | 772 // Close the database and recreate it. |
| 776 ResetDatabase(); | 773 ResetDatabase(); |
| 777 | 774 |
| 778 // Create another namespace with id 1. | 775 // Create another namespace with id 1. |
| 779 ValuesMap data2; | 776 ValuesMap data2; |
| 780 data2[kKey1] = kValue3; | 777 data2[kKey1] = kValue3; |
| 781 EXPECT_TRUE(db_->CommitAreaChanges(1, kOrigin1, false, data2)); | 778 EXPECT_TRUE(db_->CommitAreaChanges(1, kOrigin1, false, data2)); |
| 782 | 779 |
| 783 // Make a shallow copy of the newly created namespace. | 780 // Make a shallow copy of the newly created namespace. |
| 784 EXPECT_TRUE(db_->CloneNamespace(1, 20)); | 781 EXPECT_TRUE(db_->CloneNamespace(1, 20)); |
| 785 // And make it deep. | |
| 786 EXPECT_TRUE(db_->DeepCopyArea(20, kOrigin1)); | |
| 787 | 782 |
| 788 // Now the values can be altered in the deep copy. | 783 // Now the values can be altered and a deep copy will be made. |
| 789 ValuesMap data3; | 784 ValuesMap data3; |
| 790 data3[kKey1] = kValue2; | 785 data3[kKey1] = kValue2; |
| 791 EXPECT_TRUE(db_->CommitAreaChanges(20, kOrigin1, false, data3)); | 786 EXPECT_TRUE(db_->CommitAreaChanges(20, kOrigin1, false, data3)); |
| 792 | 787 |
| 793 CheckAreaData(20, kOrigin1, data3); | 788 CheckAreaData(20, kOrigin1, data3); |
| 794 CheckAreaData(1, kOrigin1, data2); | 789 CheckAreaData(1, kOrigin1, data2); |
| 795 | 790 |
| 796 // The values for the old namespace 1 are still accessible via id -1. | 791 // The values for the old namespace 1 are still accessible via id -1. |
| 797 CheckAreaData(-1, kOrigin1, data1); | 792 CheckAreaData(-1, kOrigin1, data1); |
| 798 | 793 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 EXPECT_TRUE(db_->DeleteNamespace(1)); | 844 EXPECT_TRUE(db_->DeleteNamespace(1)); |
| 850 | 845 |
| 851 // Namespace 1 is empty. | 846 // Namespace 1 is empty. |
| 852 CheckAreaData(1, kOrigin1, ValuesMap()); | 847 CheckAreaData(1, kOrigin1, ValuesMap()); |
| 853 | 848 |
| 854 // The values for the old namespace 1 are still accessible via id -1. | 849 // The values for the old namespace 1 are still accessible via id -1. |
| 855 CheckAreaData(-1, kOrigin1, data1); | 850 CheckAreaData(-1, kOrigin1, data1); |
| 856 } | 851 } |
| 857 | 852 |
| 858 } // namespace dom_storage | 853 } // namespace dom_storage |
| OLD | NEW |