| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 EXPECT_EQ(kValue, values[kKey].string()); | 63 EXPECT_EQ(kValue, values[kKey].string()); |
| 64 } | 64 } |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 MessageLoop message_loop_; | 68 MessageLoop message_loop_; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 TEST_F(DomStorageAreaTest, DomStorageAreaBasics) { | 71 TEST_F(DomStorageAreaTest, DomStorageAreaBasics) { |
| 72 scoped_refptr<DomStorageArea> area( | 72 scoped_refptr<DomStorageArea> area( |
| 73 new DomStorageArea(1, kOrigin, FilePath(), NULL)); | 73 new DomStorageArea(1, "", kOrigin, NULL)); |
| 74 string16 old_value; | 74 string16 old_value; |
| 75 NullableString16 old_nullable_value; | 75 NullableString16 old_nullable_value; |
| 76 scoped_refptr<DomStorageArea> copy; | 76 scoped_refptr<DomStorageArea> copy; |
| 77 | 77 |
| 78 // We don't focus on the underlying DomStorageMap functionality | 78 // We don't focus on the underlying DomStorageMap functionality |
| 79 // since that's covered by seperate unit tests. | 79 // since that's covered by seperate unit tests. |
| 80 EXPECT_EQ(kOrigin, area->origin()); | 80 EXPECT_EQ(kOrigin, area->origin()); |
| 81 EXPECT_EQ(1, area->namespace_id()); | 81 EXPECT_EQ(1, area->namespace_id()); |
| 82 EXPECT_EQ(0u, area->Length()); | 82 EXPECT_EQ(0u, area->Length()); |
| 83 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_nullable_value)); | 83 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_nullable_value)); |
| 84 EXPECT_TRUE(area->SetItem(kKey2, kValue2, &old_nullable_value)); | 84 EXPECT_TRUE(area->SetItem(kKey2, kValue2, &old_nullable_value)); |
| 85 EXPECT_FALSE(area->HasUncommittedChanges()); | 85 EXPECT_FALSE(area->HasUncommittedChanges()); |
| 86 | 86 |
| 87 // Verify that a copy shares the same map. | 87 // Verify that a copy shares the same map. |
| 88 copy = area->ShallowCopy(2); | 88 copy = area->ShallowCopy(2, ""); |
| 89 EXPECT_EQ(kOrigin, copy->origin()); | 89 EXPECT_EQ(kOrigin, copy->origin()); |
| 90 EXPECT_EQ(2, copy->namespace_id()); | 90 EXPECT_EQ(2, copy->namespace_id()); |
| 91 EXPECT_EQ(area->Length(), copy->Length()); | 91 EXPECT_EQ(area->Length(), copy->Length()); |
| 92 EXPECT_EQ(area->GetItem(kKey).string(), copy->GetItem(kKey).string()); | 92 EXPECT_EQ(area->GetItem(kKey).string(), copy->GetItem(kKey).string()); |
| 93 EXPECT_EQ(area->Key(0).string(), copy->Key(0).string()); | 93 EXPECT_EQ(area->Key(0).string(), copy->Key(0).string()); |
| 94 EXPECT_EQ(copy->map_.get(), area->map_.get()); | 94 EXPECT_EQ(copy->map_.get(), area->map_.get()); |
| 95 | 95 |
| 96 // But will deep copy-on-write as needed. | 96 // But will deep copy-on-write as needed. |
| 97 EXPECT_TRUE(area->RemoveItem(kKey, &old_value)); | 97 EXPECT_TRUE(area->RemoveItem(kKey, &old_value)); |
| 98 EXPECT_NE(copy->map_.get(), area->map_.get()); | 98 EXPECT_NE(copy->map_.get(), area->map_.get()); |
| 99 copy = area->ShallowCopy(2); | 99 copy = area->ShallowCopy(2, ""); |
| 100 EXPECT_EQ(copy->map_.get(), area->map_.get()); | 100 EXPECT_EQ(copy->map_.get(), area->map_.get()); |
| 101 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_nullable_value)); | 101 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_nullable_value)); |
| 102 EXPECT_NE(copy->map_.get(), area->map_.get()); | 102 EXPECT_NE(copy->map_.get(), area->map_.get()); |
| 103 copy = area->ShallowCopy(2); | 103 copy = area->ShallowCopy(2, ""); |
| 104 EXPECT_EQ(copy->map_.get(), area->map_.get()); | 104 EXPECT_EQ(copy->map_.get(), area->map_.get()); |
| 105 EXPECT_NE(0u, area->Length()); | 105 EXPECT_NE(0u, area->Length()); |
| 106 EXPECT_TRUE(area->Clear()); | 106 EXPECT_TRUE(area->Clear()); |
| 107 EXPECT_EQ(0u, area->Length()); | 107 EXPECT_EQ(0u, area->Length()); |
| 108 EXPECT_NE(copy->map_.get(), area->map_.get()); | 108 EXPECT_NE(copy->map_.get(), area->map_.get()); |
| 109 | 109 |
| 110 // Verify that once Shutdown(), behaves that way. | 110 // Verify that once Shutdown(), behaves that way. |
| 111 area->Shutdown(); | 111 area->Shutdown(); |
| 112 EXPECT_TRUE(area->is_shutdown_); | 112 EXPECT_TRUE(area->is_shutdown_); |
| 113 EXPECT_FALSE(area->map_.get()); | 113 EXPECT_FALSE(area->map_.get()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 133 NULL)); | 133 NULL)); |
| 134 EXPECT_EQ(NULL, area->backing_.get()); | 134 EXPECT_EQ(NULL, area->backing_.get()); |
| 135 EXPECT_TRUE(area->is_initial_import_done_); | 135 EXPECT_TRUE(area->is_initial_import_done_); |
| 136 EXPECT_FALSE(file_util::PathExists(kExpectedOriginFilePath)); | 136 EXPECT_FALSE(file_util::PathExists(kExpectedOriginFilePath)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // Valid directory and origin but non-local namespace id. Backing should | 139 // Valid directory and origin but non-local namespace id. Backing should |
| 140 // be null. | 140 // be null. |
| 141 { | 141 { |
| 142 scoped_refptr<DomStorageArea> area( | 142 scoped_refptr<DomStorageArea> area( |
| 143 new DomStorageArea(kSessionStorageNamespaceId, kOrigin, | 143 new DomStorageArea(kSessionStorageNamespaceId, "", kOrigin, NULL)); |
| 144 temp_dir.path(), NULL)); | |
| 145 EXPECT_EQ(NULL, area->backing_.get()); | 144 EXPECT_EQ(NULL, area->backing_.get()); |
| 146 EXPECT_TRUE(area->is_initial_import_done_); | 145 EXPECT_TRUE(area->is_initial_import_done_); |
| 147 | 146 |
| 148 NullableString16 old_value; | 147 NullableString16 old_value; |
| 149 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value)); | 148 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_value)); |
| 150 ASSERT_TRUE(old_value.is_null()); | 149 ASSERT_TRUE(old_value.is_null()); |
| 151 | 150 |
| 152 // Check that saving a value has still left us without a backing database. | 151 // Check that saving a value has still left us without a backing database. |
| 153 EXPECT_EQ(NULL, area->backing_.get()); | 152 EXPECT_EQ(NULL, area->backing_.get()); |
| 154 EXPECT_FALSE(file_util::PathExists(kExpectedOriginFilePath)); | 153 EXPECT_FALSE(file_util::PathExists(kExpectedOriginFilePath)); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 EXPECT_EQ( | 444 EXPECT_EQ( |
| 446 FilePath().AppendASCII("-journal"), | 445 FilePath().AppendASCII("-journal"), |
| 447 DomStorageDatabase::GetJournalFilePath(FilePath())); | 446 DomStorageDatabase::GetJournalFilePath(FilePath())); |
| 448 EXPECT_EQ( | 447 EXPECT_EQ( |
| 449 FilePath().AppendASCII(".extensiononly-journal"), | 448 FilePath().AppendASCII(".extensiononly-journal"), |
| 450 DomStorageDatabase::GetJournalFilePath( | 449 DomStorageDatabase::GetJournalFilePath( |
| 451 FilePath().AppendASCII(".extensiononly"))); | 450 FilePath().AppendASCII(".extensiononly"))); |
| 452 } | 451 } |
| 453 | 452 |
| 454 } // namespace dom_storage | 453 } // namespace dom_storage |
| OLD | NEW |