| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 content::TestBrowserThread ui_thread_; | 73 content::TestBrowserThread ui_thread_; |
| 74 content::TestBrowserThread file_thread_; | 74 content::TestBrowserThread file_thread_; |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 // Get a semblance of coverage for both extension and app settings by | 77 // Get a semblance of coverage for both extension and app settings by |
| 78 // alternating in each test. | 78 // alternating in each test. |
| 79 // TODO(kalman): explicitly test the two interact correctly. | 79 // TODO(kalman): explicitly test the two interact correctly. |
| 80 | 80 |
| 81 TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) { | 81 TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) { |
| 82 const std::string id = "ext"; | 82 const std::string id = "ext"; |
| 83 profile_->GetMockExtensionService()->AddExtension( | 83 profile_->GetMockExtensionService()->AddExtensionWithId( |
| 84 id, Extension::TYPE_EXTENSION); | 84 id, Extension::TYPE_EXTENSION); |
| 85 | 85 |
| 86 SettingsStorage* storage = GetStorage(id, frontend_.get()); | 86 SettingsStorage* storage = GetStorage(id, frontend_.get()); |
| 87 | 87 |
| 88 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to | 88 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to |
| 89 // be too rigorous. | 89 // be too rigorous. |
| 90 { | 90 { |
| 91 StringValue bar("bar"); | 91 StringValue bar("bar"); |
| 92 SettingsStorage::WriteResult result = storage->Set("foo", bar); | 92 SettingsStorage::WriteResult result = storage->Set("foo", bar); |
| 93 ASSERT_FALSE(result.HasError()); | 93 ASSERT_FALSE(result.HasError()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 104 | 104 |
| 105 { | 105 { |
| 106 SettingsStorage::ReadResult result = storage->Get(); | 106 SettingsStorage::ReadResult result = storage->Get(); |
| 107 ASSERT_FALSE(result.HasError()); | 107 ASSERT_FALSE(result.HasError()); |
| 108 EXPECT_FALSE(result.settings().empty()); | 108 EXPECT_FALSE(result.settings().empty()); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) { | 112 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) { |
| 113 const std::string id = "ext"; | 113 const std::string id = "ext"; |
| 114 profile_->GetMockExtensionService()->AddExtension( | 114 profile_->GetMockExtensionService()->AddExtensionWithId( |
| 115 id, Extension::TYPE_PACKAGED_APP); | 115 id, Extension::TYPE_PACKAGED_APP); |
| 116 | 116 |
| 117 SettingsStorage* storage = GetStorage(id, frontend_.get()); | 117 SettingsStorage* storage = GetStorage(id, frontend_.get()); |
| 118 | 118 |
| 119 { | 119 { |
| 120 StringValue bar("bar"); | 120 StringValue bar("bar"); |
| 121 SettingsStorage::WriteResult result = storage->Set("foo", bar); | 121 SettingsStorage::WriteResult result = storage->Set("foo", bar); |
| 122 ASSERT_FALSE(result.HasError()); | 122 ASSERT_FALSE(result.HasError()); |
| 123 } | 123 } |
| 124 | 124 |
| 125 // This would be triggered by extension uninstall via an ExtensionDataDeleter. | 125 // This would be triggered by extension uninstall via an ExtensionDataDeleter. |
| 126 frontend_->DeleteStorageSoon(id); | 126 frontend_->DeleteStorageSoon(id); |
| 127 MessageLoop::current()->RunAllPending(); | 127 MessageLoop::current()->RunAllPending(); |
| 128 | 128 |
| 129 // The storage area may no longer be valid post-uninstall, so re-request. | 129 // The storage area may no longer be valid post-uninstall, so re-request. |
| 130 storage = GetStorage(id, frontend_.get()); | 130 storage = GetStorage(id, frontend_.get()); |
| 131 { | 131 { |
| 132 SettingsStorage::ReadResult result = storage->Get(); | 132 SettingsStorage::ReadResult result = storage->Get(); |
| 133 ASSERT_FALSE(result.HasError()); | 133 ASSERT_FALSE(result.HasError()); |
| 134 EXPECT_TRUE(result.settings().empty()); | 134 EXPECT_TRUE(result.settings().empty()); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) { | 138 TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) { |
| 139 const std::string id = "ext"; | 139 const std::string id = "ext"; |
| 140 profile_->GetMockExtensionService()->AddExtension( | 140 profile_->GetMockExtensionService()->AddExtensionWithId( |
| 141 id, Extension::TYPE_EXTENSION); | 141 id, Extension::TYPE_EXTENSION); |
| 142 | 142 |
| 143 SettingsStorage* storage = GetStorage(id, frontend_.get()); | 143 SettingsStorage* storage = GetStorage(id, frontend_.get()); |
| 144 | 144 |
| 145 { | 145 { |
| 146 StringValue bar("bar"); | 146 StringValue bar("bar"); |
| 147 SettingsStorage::WriteResult result = storage->Set("foo", bar); | 147 SettingsStorage::WriteResult result = storage->Set("foo", bar); |
| 148 ASSERT_FALSE(result.HasError()); | 148 ASSERT_FALSE(result.HasError()); |
| 149 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); | 149 EXPECT_TRUE(file_util::PathExists(temp_dir_.path())); |
| 150 } | 150 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 162 // TODO(kalman): Figure out why this fails, despite appearing to work. | 162 // TODO(kalman): Figure out why this fails, despite appearing to work. |
| 163 // Leaving this commented out rather than disabling the whole test so that the | 163 // Leaving this commented out rather than disabling the whole test so that the |
| 164 // deletion code paths are at least exercised. | 164 // deletion code paths are at least exercised. |
| 165 //EXPECT_FALSE(file_util::PathExists(temp_dir_.path())); | 165 //EXPECT_FALSE(file_util::PathExists(temp_dir_.path())); |
| 166 } | 166 } |
| 167 | 167 |
| 168 TEST_F(ExtensionSettingsFrontendTest, | 168 TEST_F(ExtensionSettingsFrontendTest, |
| 169 LeveldbCreationFailureFailsAllOperations) { | 169 LeveldbCreationFailureFailsAllOperations) { |
| 170 const StringValue bar("bar"); | 170 const StringValue bar("bar"); |
| 171 const std::string id = "ext"; | 171 const std::string id = "ext"; |
| 172 profile_->GetMockExtensionService()->AddExtension( | 172 profile_->GetMockExtensionService()->AddExtensionWithId( |
| 173 id, Extension::TYPE_EXTENSION); | 173 id, Extension::TYPE_EXTENSION); |
| 174 | 174 |
| 175 storage_factory_->Reset(new NullSettingsStorageFactory()); | 175 storage_factory_->Reset(new NullSettingsStorageFactory()); |
| 176 | 176 |
| 177 SettingsStorage* storage = GetStorage(id, frontend_.get()); | 177 SettingsStorage* storage = GetStorage(id, frontend_.get()); |
| 178 ASSERT_TRUE(storage != NULL); | 178 ASSERT_TRUE(storage != NULL); |
| 179 | 179 |
| 180 EXPECT_TRUE(storage->Get().HasError()); | 180 EXPECT_TRUE(storage->Get().HasError()); |
| 181 EXPECT_TRUE(storage->Clear().HasError()); | 181 EXPECT_TRUE(storage->Clear().HasError()); |
| 182 EXPECT_TRUE(storage->Set("foo", bar).HasError()); | 182 EXPECT_TRUE(storage->Set("foo", bar).HasError()); |
| 183 EXPECT_TRUE(storage->Remove("foo").HasError()); | 183 EXPECT_TRUE(storage->Remove("foo").HasError()); |
| 184 | 184 |
| 185 // For simplicity: just always fail those requests, even if the leveldb | 185 // For simplicity: just always fail those requests, even if the leveldb |
| 186 // storage areas start working. | 186 // storage areas start working. |
| 187 storage_factory_->Reset(new SettingsLeveldbStorage::Factory()); | 187 storage_factory_->Reset(new SettingsLeveldbStorage::Factory()); |
| 188 | 188 |
| 189 storage = GetStorage(id, frontend_.get()); | 189 storage = GetStorage(id, frontend_.get()); |
| 190 ASSERT_TRUE(storage != NULL); | 190 ASSERT_TRUE(storage != NULL); |
| 191 | 191 |
| 192 EXPECT_TRUE(storage->Get().HasError()); | 192 EXPECT_TRUE(storage->Get().HasError()); |
| 193 EXPECT_TRUE(storage->Clear().HasError()); | 193 EXPECT_TRUE(storage->Clear().HasError()); |
| 194 EXPECT_TRUE(storage->Set("foo", bar).HasError()); | 194 EXPECT_TRUE(storage->Set("foo", bar).HasError()); |
| 195 EXPECT_TRUE(storage->Remove("foo").HasError()); | 195 EXPECT_TRUE(storage->Remove("foo").HasError()); |
| 196 } | 196 } |
| 197 | 197 |
| 198 } // namespace extensions | 198 } // namespace extensions |
| OLD | NEW |